Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
FORUMS:listlist (w/ descriptions)archivetagssearchhall of famerecent posts

HANDY TIP: Using FFprobe for stream analysis

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Michael RampeHANDY TIP: Using FFprobe for stream analysis
by on Jun 12, 2010 at 5:21:19 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"


Return to posts index
Reply   Like  

Rodney BakerRe: HANDY TIP: Using FFprobe for stream analysis
by on Jun 12, 2010 at 9:03:08 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?


Return to posts index
Reply   Like  

Michael RampeRe: HANDY TIP: Using FFprobe for stream analysis
by on Jun 13, 2010 at 12:50:47 am

Thanks Rodney.

I will investigate.

Michael

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


Return to posts index
Reply   Like  


Michael RampeRe: HANDY TIP: Using FFprobe for stream analysis
by on Jun 13, 2010 at 2:41:08 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"


Return to posts index
Reply   Like  

Rodney BakerRe: HANDY TIP: Using FFprobe for stream analysis
by on Jun 13, 2010 at 3:34:18 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.


Return to posts index
Reply   Like  


Michael RampeRe: HANDY TIP: Using FFprobe for stream analysis
by on Jun 13, 2010 at 4:02:58 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"


Return to posts index
Reply   Like  


Michael RampeMission complete
by on Jun 14, 2010 at 7:56:41 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"


Return to posts index
Reply   Like  

Michael RampeRe: Mission complete
by on Jun 15, 2010 at 8:35:45 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"


Return to posts index
Reply   Like  

John van KemenadeRe: Mission complete
by on Jun 30, 2010 at 5:41:54 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


Return to posts index
Reply   Like  


Michael RampeRe: Mission complete
by on Jul 1, 2010 at 4:33:53 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"


Return to posts index
Reply   Like  

kathija naseemRe: Mission complete
by on Feb 6, 2012 at 5:37:01 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


Return to posts index
Reply   Like  

Oussama StitiRe: HANDY TIP: Using FFprobe for stream analysis
by on Mar 22, 2012 at 2:12:44 am

Hello,

I want to detect the distorded frames ( corrupted or loss) and, i want to edit a log file, wich exctract such informations, like slice #, frame ID, related frames, type of frame.
Is it possible with ffprobe, to display such informations ( damaged frame) ?

I'm running on ubuntu, and i'm broadcasting a video in the loopback IP, using a VLC player client, and a VLC player server.


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>


FORUMSTUTORIALSMAGAZINESTOCKYARDVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2012 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]