Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US :: FAQ
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 >>
Share on Facebook
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  

Quang Nguyễn VănRe: HANDY TIP: Using FFprobe for stream analysis
by on Jan 6, 2014 at 9:01:45 am

I use latest version ffprobe. when I using command line of you (I was replayed size=pkt_size) but I get raw.dat file contains:
...
coded_picture_number=70
pkt_size=10498
coded_picture_number=71
pkt_size=498
pkt_size=497
pkt_size=464
pkt_size=453
pkt_size=452
pkt_size=464
pkt_size=462
pkt_size=454
pkt_size=449
pkt_size=459
pkt_size=469
pkt_size=468
pkt_size=475
pkt_size=462
pkt_size=503
pkt_size=526
pkt_size=490
pkt_size=494
pkt_size=501
pkt_size=457
pkt_size=435
pkt_size=10908
coded_picture_number=72
pkt_size=11168
...
and column.dat file contains:
...
pkt_215 0
pkt_37 1
pkt_37 2
pkt_27182 3
pkt_6601 4
pkt_3540 5
pkt_5845 6
pkt_6190 7
pkt_5860 8
pkt_6284 9
pkt_6295 10
pkt_6816 11
pkt_7073 12
pkt_9 pkt_9
pkt_34 pkt_464
pkt_407 pkt_441
pkt_430 pkt_428
pkt_380 pkt_346
pkt_334 pkt_320
pkt_316 pkt_339
pkt_351 pkt_348
pkt_364 pkt_347
pkt_359 pkt_376
pkt_474 pkt_438
pkt_7133 13
pkt_7535 14
....

and, I use gnuplot to raw but that is incoret.
I get error:
warning: Skipping data file with no valid points
can you help me?


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  

Oche EjembiRe: HANDY TIP: Using FFprobe for stream analysis
by on Aug 15, 2013 at 12:08:21 pm

Hey!

I am sorry to be the guy to comment on a 3 year old thread, but I have to ask.

My version of ffprobe (ffprobe version 0.11.1) -show-frames doesn't show the size of frames (it does for packets though). Any ideas on what I can do? What's the relationship between packets and frames?

This is a sample from my output

##################FRAME#####################
[FRAME]
media_type=video
key_frame=0
pkt_pts=784784
pkt_pts_time=0:00:26.159467
pkt_dts=784784
pkt_dts_time=0:00:26.159467
pkt_pos=20156243
width=1920
height=1080
pix_fmt=yuv420p
sample_aspect_ratio=N/A
pict_type=P
coded_picture_number=784
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
reference=0
[/FRAME]

##################PACKET#####################
[PACKET]
codec_type=video
stream_index=0
pts=789789
pts_time=0:00:26.326300
dts=789789
dts_time=0:00:26.326300
duration=1001
duration_time=0:00:00.033367
size=24.804688 Kibyte
pos=20354166
flags=_
[/PACKET


Return to posts index
Reply   Like  

Michael RampeRe: HANDY TIP: Using FFprobe for stream analysis
by on Aug 16, 2013 at 8:20:06 am

wow. I have not looked at my code on this in a long time....

I am using a very recent compile (V2.x) and I am not getting size anymore either.

I am, however getting pkt_size for H.264 streams. It looks like it is in Bytes to me... maybe try to upgrade?

[FRAME]
media_type=video
key_frame=1
pkt_pts=1539
pkt_pts_time=61.560000
pkt_dts=1539
pkt_dts_time=61.560000
pkt_duration=1
pkt_duration_time=0.040000
pkt_pos=10862541
pkt_size=56311
width=854
height=480
pix_fmt=yuv420p
sample_aspect_ratio=1:1
pict_type=I
coded_picture_number=1539
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
[/FRAME]


FYI, my line was: ffprobe -show_frames -i tests_cut1_x264.mov

and my version is:
ffprobe version N-54992-g63c0113 Copyright (c) 2007-2013 the FFmpeg developers
built on Jul 28 2013 19:42:17 with Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
configuration: --enable-gpl --enable-postproc --enable-swscale --enable-libmp3lame --enable-libfaac --enable-libx264 --enable-nonfree --enable-shared --arch=x86_64 --extra-cflags=/usr/local/lib --enable-avfilter --enable-libfreetype --enable-frei0r --cc=clang
libavutil 52. 40.100 / 52. 40.100
libavcodec 55. 19.100 / 55. 19.100
libavformat 55. 12.102 / 55. 12.102
libavdevice 55. 3.100 / 55. 3.100
libavfilter 3. 81.103 / 3. 81.103
libswscale 2. 4.100 / 2. 4.100
libswresample 0. 17.103 / 0. 17.103
libpostproc 52. 3.100 / 52. 3.100

Michael

p.s. Glad this is still useful after all this time. I was very much a newbie when I did this;-) If you get a new version of this graphing stuff going, please post!


Return to posts index
Reply   Like  


Oche EjembiRe: HANDY TIP: Using FFprobe for stream analysis
by on Aug 16, 2013 at 3:23:39 pm

Thanks a lot for this. I wish I'd seen this a few hours earlier. would have save me some time. I upgraded and it worked.

WIll definitely post if I can script the graphing although I think you've done a great job already.


Return to posts index
Reply   Like  

Oche EjembiRe: HANDY TIP: Using FFprobe for stream analysis
by on Aug 19, 2013 at 11:32:04 pm

Turns out the good people developing ffmpeg recently added a graphing tool written in Perl and using Gnuplot and ffprobe.

In the latest repo, you can find it in tools/plotframes. Its simple enough to use and gives quite impressive graphs on X11. Currently looking for how to maintain that same quality

.ffmpeg/tools/plotframes -i video.mp4 [-t svg -o video.svg]

The -t and -o flags are optional and sets the terminal and the output file respectively. A lot of options are available to set the terminal from the gnuplot manual or typing set terminal within the gnuplot environment


Return to posts index
Reply   Like  

Eric WorkRe: HANDY TIP: Using FFprobe for stream analysis
by on Dec 9, 2013 at 5:02:50 am

The plotframes tool, which is part of the FFMPEG repository, was written in Perl and is very slow for large files. I wrote my own version of this tool using Python 3 which is much faster. Instead of reading the entire JSON output from FFProbe before processing begins my script pipes XML data from FFProbe and uses a stream XML processor to parse the frame data. Matplotlib is then used to plot the data which requires no temporary files. The result is about 5-10% overhead over FFProbe. The major bottleneck when processing an HD video that's 3+ hours long is FFProbe. I got tired of waiting after 2 hours for plotframes to even start generating the temp files for a 3 hour movie, while my script was done in 40 min. You can find my script in my github repo below.

https://github.com/zeroepoch/plotbitrate


Return to posts index
Reply   Like  


Oche EjembiRe: HANDY TIP: Using FFprobe for stream analysis
by on Aug 16, 2013 at 3:19:46 pm

Just in case this helps anyone. I upgraded to the latest version of ffmpeg and I get the pkt_size information with the show-frames tag.


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSFEATURESVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

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

[Top]