0

After this question whose the answer had partially resolved my problem. I would like to have a selected result of ffmpeg. So, with this command:

ffmpeg -y -i "${M3U2}" -vcodec copy -acodec copy "${Directory}/${PROG}_${ID}.mkv" 2>&1 | egrep -e '^[[:blank:]]*(Duration|Output|frame)'

The result is:

Duration: 00:12:28.52, start: 0.100667, bitrate: 0 kb/s
Output #0, matroska, to '/home/path/file.mkv':

But in the result I am missing this dynamic line:

frame= 1834 fps=166 q=-1.0 Lsize=    7120kB time=00:01:13.36 bitrate= 795.0kbits/s

This line changes every second. How can I modify the command line to display this line? My program should read this line and display the "time" updating in-place. Thanks

solution:

ffmpeg -y -i "${M3U2}" -vcodec copy -acodec copy "${Directory}/${PROG}_${ID}.mkv" 2>&1 |
      { while read line
        do
          if $(echo "$line" | grep -q "Duration"); then
            echo "$line"
          fi
          if $(echo "$line" | grep -q "Output"); then
            echo "$line"
          fi
          if $(echo "$line" | grep -q "Stream #0:1 -> #0:1"); then
            break
          fi
        done;
        while read -d $'\x0D' line
       do
          if $(echo "$line" | grep -q "time="); then
            echo -en "\r$line"
          fi
       done; }

Thanks to ofrommel

Community
  • 1
  • 1
Guillaume
  • 2,752
  • 5
  • 27
  • 42

1 Answers1

1

You need to parse the output with CR (carriage return) as a delimiter, because this is what ffmpeg uses for printing on the same line. First use another loop with the regular separator to iterate over the first lines to get "Duration" and "Output":

ffmpeg -y -i inputfile -vcodec copy -acodec copy outputfile 2>&1 |
{ while read line
  do
     if $(echo "$line" | grep -q "Duration"); then
        echo "$line"
     fi
     if $(echo "$line" | grep -q "Output"); then
        echo "$line"
     fi
     if $(echo "$line" | grep -q "Stream mapping"); then
        break
     fi
  done;
  while read -d $'\x0D' line
  do
     if $(echo "$line" | grep -q "time="); then
        echo "$line" | awk '{ printf "%s\r", $8 }'
     fi
  done; }
ofrommel
  • 2,129
  • 14
  • 19
  • Thank you, this is almost what I want. I need too to have "Duration" and "Output", so can I add this in awk command? – Guillaume Jul 03 '14 at 09:22
  • It now prints the time info in place. Please consider specifying your question in more detail next time, as it might save time for people answering it. Thanks. – ofrommel Jul 03 '14 at 11:14
  • With your help my new code is updated in my question. Thank you again. – Guillaume Jul 03 '14 at 21:04