ffmpeg失败,有一个红色十六进制输出的墙,但只有在bash循环中

joz*_*yqk 3 bash loops ffmpeg

类似的问题在这里,但没有解决方案:https://www.reddit.com/r/linuxquestions/comments/m00f0/hex_output_from_ffmpeg_when_run_in_a_loop/

我正在尝试批量编码一些视频.我在文本文件中有一个文件名列表,并在bash循环中读取每个文件名.就是这个:

OUT=./out
mkdir -p $OUT

while read inputfile; do
b=$(basename "$inputfile")
outputfile="$OUT/$b"
echo
echo
echo "$inputfile"
echo "$outputfile"
echo
ffmpeg -i "$inputfile" "$outputfile" || exit
done < files.txt
Run Code Online (Sandbox Code Playgroud)

当我运行它时,ffmpeg命令似乎开始正常,然后吐出一个巨大的红色十六进制转储墙,如文本(如下所示).它完成没有错误,但文件只有几百帧长.

[libx264 @ 0x1b68d60] frame= 537 QP=31.44 NAL=0 Slice:B Poc:70  I:2    P:239  SKIP:987  size=516 bytes
stream #1:                                                                                                                                                
  keyframe=1                                                                                                                                              
  duration=0.024                                                                                                                                          
  dts=25.992  pts=25.992                                                                                                                                  
  size=336                                                                                                                                                
00000000  ff fb 84 64 1a 0e d3 21 3f d4 93 18 6a e6 33 a4 ...d...!?...j.3.
00000010  6a 63 25 22 4a 0c d1 1d 52 6c bd ab c0 bf 23 69 jc%"J...Rl....#i
... LOTS MORE
Run Code Online (Sandbox Code Playgroud)

另一个非常奇怪的事情是inputfilebash循环中的下一个被破坏并且只有最后几个字符,如果我只是注释掉这一ffmpeg行就不会发生这种情况.

ffmpeg可以做什么干扰这样的bash循环?

(ffmpeg 2.8.6,bash 4.3.42(1),fedora 23)

joz*_*yqk 5

在这里找到答案:https://unix.stackexchange.com/questions/241535/problem-with-ffmpeg-in-bash-loop

不知何故,read命令stdin最终被共享ffmpeg.不过不知道为什么,但得到的答复是重新路由ffmpeg stdin/dev/null.例如:

ffmpeg -i "$inputfile" "$outputfile" < /dev/null || exit
Run Code Online (Sandbox Code Playgroud)

  • 或者在`ffmpeg`中使用`-nostdin`选项. (5认同)