Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Compression Techniques HANDY TIP: Using FFprobe for stream analysis

  • HANDY TIP: Using FFprobe for stream analysis

    Posted by Michael Rampe on June 12, 2010 at 5:21 am

    HANDY TIP:

    You can easily extract bitrate data and frame types (I,P,B) using FFprobe.

    At the time of writing, FFprobe version SVN-r92, Copyright (c) 2007-2009 Stefano Sabatini works for frame analysis amongst many other things. The FFprobe attachment to the trunk of FFmpeg version SVN-r23145, Copyright (c) 2000-2010 the FFmpeg developers is not fully complete. Never fear, it works great anyway. Just install the SVN-r92 FFprobe version and run it manually.

    ./ffprobe -show_frames -pretty two_pass.mp4

    …produces this output:

    [FRAME]
    codec_type=video
    pict_type=I
    width=1024
    height=576
    quality=0
    coded_picture_number=0
    display_picture_number=0
    interlaced_frame=0
    repeat_pict=0
    reference=3
    stream_index=0
    size=822.000 byte
    pkt_pts=0:00:00.000000
    pkt_dts=0:00:00.960000
    pkt_duration=0:00:00.040000
    file_pkt_nb=1
    stream_pkt_nb=1
    pkt_flag_key=K
    [/FRAME]
    …etc.

    This is repeated for every frame of video which can be a VERY long list. You can filter the list by piping the output to the grep command.

    ./ffprobe -show_frames -pretty two_pass.mp4 | grep ‘size\|pict_type\|coded_picture_number’

    pict_type=I
    coded_picture_number=0
    size=822.000 byte
    pict_type=P
    coded_picture_number=1
    size=219.000 byte
    pict_type=P
    coded_picture_number=2
    size=515.000 byte
    pict_type=P
    coded_picture_number=3
    size=942.000 byte
    pict_type=B
    coded_picture_number=5
    size=2.292 Kibyte
    pict_type=P
    coded_picture_number=4
    size=3.896 Kibyte
    pict_type=B
    coded_picture_number=7
    size=5.546 Kibyte
    …etc.

    (Note the frame reordering in the structure of the file.)

    Now the challenge is to create an open source graphing program for this data.

    Any thoughts?

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

    Milivoj Ivkovic replied 8 years, 6 months ago 11 Members · 21 Replies
  • 21 Replies
  • Rodney Baker

    June 12, 2010 at 9:03 am

    Use sed/awk to massage the data into a suitable format for graphing, then use gnuplot to produce the output. Once that it settled, tie it all together using a shell script/python/perl or your language of choice. All the tools to do it exist already – why reinvent the wheel?

  • Michael Rampe

    June 13, 2010 at 12:50 am

    Thanks Rodney.

    I will investigate.

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

  • Michael Rampe

    June 13, 2010 at 2:41 am

    Hi Rodney,

    I managed to get gnuplot to show the data after creating the following datafile manually from the data in my previous post.

    0 822.000
    1 219.000
    2 515.000
    3 942.000
    5 2292.000
    4 3896.000
    7 5546.000

    I have had a quick look into sed and awk. Looks tricky. I will keep investigating.

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

  • Rodney Baker

    June 13, 2010 at 3:34 am

    Hi Michael. The syntax for sed and awk can be tricky, and they can both do pretty advanced stuff. I think awk may be the more appropriate tool for this, although it could be done directly using either Python or Perl too (but I’m not a programmer so I’m not the right person to ask about that).

    Mind you, I’m no expert on awk or sed either, but I know that you can use either one to achieve what you want. Sed (Stream EDitor) is designed for line-by-line string editing/replacement, whereas awk is more powerful and probably more suited to parsing the data output from ffprobe and rewriting it into the format that you need for gnuplot. That is my understanding, anyway.

  • Michael Rampe

    June 13, 2010 at 4:02 am

    [Rodney Baker] “(but I’m not a programmer so I’m not the right person to ask about that).”

    Me either;-)

    I did get some good results just then with:
    ./ffprobe -show_frames two_pass.mp4 | grep ‘size\|coded_picture_number’ > raw.dat && paste -s -d ‘\t\n’ raw.dat > fixed.dat && sed -e ‘s/coded_picture_number=//g’ -e ‘s/size=//g’ fixed.dat > column.dat && gnuplot plot1

    1. FFprobe lists all frame details
    2. grep strips all lines except size and picture number and writes to a file
    3. paste combines lines two by two from previous file to new file
    4. sed takes the new file and strips the unnecessary text and creates a data file
    5. gnuplot plots the datafile to image output

    (the gnuplot “plot1” file contains:
    set yrange [0:15000]
    set ytics (15000, 10000, 5000)
    set xrange [0:200]
    set lmargin 9
    set rmargin 2
    plot ‘column.dat’ using 1:2 notitle with lines)

    Not very elegant but it works as a proof of concept.

    Thanks for your nudges in the right directions.

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

  • Michael Rampe

    June 14, 2010 at 7:56 am

    After a bit of tinkering, I think I have got the result I was looking for. Open source bitrate graphing with frame type identification. The following two images are the results of one pass and two pass x264 encoding with FFmpeg. IPB frames are identified by colour. NOTE: As labelled, the y dimension is measured in Bytes per frame.

    For context or interest, this is the test video that I have used for this experiment. (I created it with Blender, another great open source program;-)

    I chose/created this video specifically for its inherently variable bitrate structure.

    For the unix minded, how I did it?

    Let me know if you get stuck;-)

    # SOFTWARE NEEDED (all open source)
    FFmpeg (>SVN-r23145), FFprobe FFprobe (>SVN-r92, currently being merged into FFmpeg as of time of posting) gnuplot (>4.2), grep, sed.

    # COMMAND LINE
    ./ffprobe -show_frames funnyhq.mp4 | grep ‘size\|coded_picture_number\|pict_type’ > raw.dat && paste -s -d ‘\t\t\n’ raw.dat > fixed.dat && sed -e ‘s/coded_picture_number=//g’ -e ‘s/size=//g’ -e ‘s/pict_type=//g’ -e ‘s/I/167116800/g’ -e ‘s/P/65280/g’ -e ‘s/B/255/g’ fixed.dat > column.dat && gnuplot plot.txt

    # GNUPLOT “plot.txt”
    set title “1pass”
    set xlabel “frame number\n\n./ffmpeg -i funny_bubbles.mov -vcodec libx264 -vpre hq -b 1500k funnyhq.mp4”
    set ylabel “Bytes per frame”
    set yrange [0:35000]
    set ytics (35000, 30000, 25000, 20000, 15000, 10000, 5000)
    set xrange [-10:850]
    set lmargin 12
    set rmargin 2
    set grid
    set pointsize 2
    set label 1 “I frames”
    set label 1 at graph .85, .96 tc lt 1
    set label 2 “P frames”
    set label 2 at graph .85, .92 tc lt 2
    set label 3 “B frames”
    set label 3 at graph .85, .88 tc lt 3
    plot ‘column.dat’ using 2:3:1 notitle with i lc rgb variable

    Now, to work out how to write a sh script to make it easier.

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

  • Michael Rampe

    June 15, 2010 at 8:35 am

    …and here are the two other rate control methods: -crf and -cqp


    seems that constant bitrate might not be possible. makes sense in a way.

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

  • John Van kemenade

    June 30, 2010 at 5:41 pm

    pretty impressive huh!
    Can you point me to a win32 binary of this version of FFprobe.
    FFprobe that is packed with the daily builds of FFmpeg does not contain the -show_frames option.

    John

  • Michael Rampe

    July 1, 2010 at 4:33 am

    Hi John,

    I used svn to get the latest version.

    $ svn co https://ffprobe.svn.sourceforge.net/svnroot/ffprobe/trunk ffprobe

    This pulled down SVN-R92 of FFprobe.

    Not sure about any issues specific to windows but this version definitely does support the -show_frames option.

    I am also currently working on a real-time encoding analyser with live graph using the -vstats option in FFmpeg. Worth looking into.

    Michael

    “half-way to world domination A.K.A. the belligerent blue bike shed”

  • Kathija Naseem

    February 6, 2012 at 5:37 am

    Hi,
    Is it possible to use the same tool for files with asf formats. Because i tried with asf on Windows. I was able to parse it but I am not getting the size of each frame.

    Kindly help

Page 1 of 3

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy