为什么 FFmpeg 在 while 循环中需要 nostdin?

Raj*_*jib 2 bash ffmpeg

如果我有:

for i in *.mov;
do
ffmpeg -y -i $i -c:v copy -c:a copy ${i%%.mov}.mp4
done
Run Code Online (Sandbox Code Playgroud)

这运行良好。但如果我跑:

find . -name "*.ts" -print0 | while read -d $'\0' file;
do
  ffmpeg -i "$file" -c copy -map 0 "${file%%.ts}_rec.mp4";
done
Run Code Online (Sandbox Code Playgroud)

这失败了。我需要输入-nostdin。

find . -name "*.ts" -print0 | while read -d $'\0' file;
do
  ffmpeg -nostdin -i "$file" -c copy -map 0 "${file%%.ts}_rec.mp4";
done
Run Code Online (Sandbox Code Playgroud)

文档解释说,这会禁用标准输入上的交互,并且对后台进程很有帮助。

为什么在第二种情况下 FFmpeg 是后台进程?或者还有其他问题吗?

Kam*_*ski 6

FFmpeg 在这里不是后台进程。它只是读取它的stdin. 可能不会,但确实如此。这会消耗应该转到 的字符read。实际上,您可能会遇到这样的问题:

\n\n

“while read”循环遍历文本文件中的行,丢失 Bash 脚本中的字符。是FFmpeg线路的错吗?

\n\n
\n\n

该文档提到了后台进程,因为通常您不希望它们特别读取stdin. 在您的情况下,您不希望前台 FFmpeg 读取其stdin.

\n

  • *这种不合理的“胃口”* --> ffmpeg 在运行时接受交互式 kbd 输入,例如过滤器命令或切换日志详细程度。按 ?查看命令列表。 (2认同)