gpt4 book ai didi

bash - 使用 ffmpeg 的 bash 查找循环中的尴尬行为

转载 作者:行者123 更新时间:2023-12-02 18:53:45 26 4
gpt4 key购买 nike

使用 Docker 运行以下脚本时发生了一些奇怪的事情。

用于此的 dockerfile 是:

FROM debian:9
WORKDIR /app
RUN apt-get -y update && \
apt-get -y install ffmpeg curl
COPY . /app

脚本 run.sh :
#!/bin/bash
find /pfs/in -maxdepth 1 -name "*.flac" -print0 | while IFS= read -r -d $'\0' inFile; do
echo "\n##### Process '${inFile}' #####"
ffmpeg -y -i ${inFile} -ar 16000 tmp.wav # use 16kHz - default for EML
done

从这里开始,将 3 个文件挂载到容器中时:
$ ls pfs/in/
Testaudio16k_2.flac Testaudio16k.flac Testaudio16k.wav TestSprache_Saetze.flac
$ docker run --rm -t -v $(pwd)/pfs/in:/pfs/in test-img:latest /bin/bash run.sh

处理第二个文件时出现错误: pfs/in/Testaudio16k_2.flac: No such file or directory .领先 /不见了。前面的 echo 中也缺少它。确实,这发生在每个 第二文件(如果我在该文件夹中放置了 3 个以上的文件)。

现在来看反例:
如果我注释掉 ffmpeg脚本中的行,重建并运行, echo 为每个文件打印正确的路径。

有人对此有任何想法吗?
是关于 find或者是 ffmpeg做一些奇怪的事情?完全不同的东西?

最佳答案

使用-nostdin :

ffmpeg -nostdin -i input output

来自 ffmpeg documentation :

-stdin
Enable interaction on standard input. On by default unless standard input is used as an input. To explicitly disable interaction you need to specify -nostdin.

Disabling interaction on standard input is useful, for example, if ffmpeg is in the background process group. Roughly the same result can be achieved with ffmpeg ... < /dev/null but it requires a shell.

关于bash - 使用 ffmpeg 的 bash 查找循环中的尴尬行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49997153/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com