vendredi 17 avril 2015

Bash script: extract info from ffmpeg output.

Hi,
I already script that a several time and I think it's will be a good time to take a note and save a bit my mind for the next time !

When we use ffmpeg in some complex script in which we pipe decoded frame into another process i.e an encoder, it's really useful to get all input video and audio info. But from the ffmpeg -i output there is several regular expression that you can use:

  • Extract widthxheigth:
RESINFO=`$FFMPEGCMD -i $INPUTFILE 2>&1 | grep Stream | grep -oP ', \K[0-9]+x[0-9]+'`






  •  Extract frame-rate:
FPS=`$FFMPEGCMD -i $INPUTFILE 2>&1 | grep Stream | sed -n "s/.*, \(.*\) tb.*/\1/p"`





  • Split RESINFO into Width and Heigth
WIDTH=`echo $RESINFO | grep -oP '^\K[0-9]+'`
HEIGHT=`echo $RESINFO | grep -oP '\K[0-9]+$'`

Feel free to comment and add request/proposal if you think that there is a better/other way to do it !

Aucun commentaire :

Enregistrer un commentaire