Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ffmpeg fails with a wall of red hex output but only when in a bash loop

Tags:

bash

loops

ffmpeg

Similar question here, but no solution: https://www.reddit.com/r/linuxquestions/comments/m00f0/hex_output_from_ffmpeg_when_run_in_a_loop/

I'm trying to batch encode some video. I have a list of filenames in a text file and read each one in a bash loop. This is it:

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

When I run it, the ffmpeg command seems to start OK, then spits out a massive wall of red hex dump like text (as below). It does finish without error, but the file is only a few hundred frames long.

[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

The other really weird thing is that the next inputfile in the bash loop is broken and has only the last few characters, which does not happen if I simply comment out the ffmpeg line.

What could ffmpeg be doing to interfere with the bash loop like this?

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

like image 958
jozxyqk Avatar asked Apr 02 '16 03:04

jozxyqk


2 Answers

The ffmpeg verbosity is quite tricky. Some ideas can be found in their online manual page. A good option is to use the warning level options ‘warning, 24’ like this:

ffmpeg -v 24 -nostdin ...
like image 24
not2qubit Avatar answered Oct 10 '22 04:10

not2qubit


Found the answer here: https://unix.stackexchange.com/questions/241535/problem-with-ffmpeg-in-bash-loop

Somehow the read command's stdin ends up shared by ffmpeg. Still not sure why, but the answer is to re-route the ffmpeg stdin from /dev/null. E.g.:

ffmpeg -i "$inputfile" "$outputfile" < /dev/null || exit
like image 170
jozxyqk Avatar answered Oct 10 '22 04:10

jozxyqk