Connaitre les données meta d’un média via ffprobe

How to Hide the ffprobe Banner

ffprobe -hide_banner <options>

-v error or -v panic and this will further reduce the information printed on the screen.

ffprobe film.mp4 -hide_banner -v panic

-print_format default=nokey=1:noprint_wrappers=1

Stream Specifiers in ffprobe

video files that contain multiple video and audio streams in them (for e.g., multiple languages). Now, let’s suppose that you want to inspect *only* the audio track, how would you do that using ffprobe? Let’s learn!

ffprobe -hide_banner -i film.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'simpsons_1080p2398_clip.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : The Simpsons Movie - Trailer
    artist          : 20th Century Fox
    date            : 2007
    encoder         : Lavf58.56.100
    genre           : Trailer
  Duration: 00:00:19.99, start: 0.007007, bitrate: 4898 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x800, 5277 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
    Metadata:
      handler_name    : GPAC ISO Video Handler
      vendor_id       : [0][0][0][0]

    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 126 kb/s (default)
    Metadata:
      handler_name    : GPAC ISO Audio Handler
      vendor_id       : [0][0][0][0]

If you look at the output of the Simpsons Trailer that I am using for this article, you’ll see that it has two streams – a video stream (stream #0:0) and an a audio stream (stream #0:1).

If we want to inspect only the audio stream, you’ll need to provide a stream specifier to ffprobe and tell it to provide data about only the audio stream. You can do this using the -select_streams specifier as follows. By mentioning a:0, we tell ffprobe to inspect the audio stream with index = 1.

ffprobe -hide_banner -v panic -select_streams v:0 -show_entries stream=bit_rate
[STREAM]
bit_rate=5277205
[/STREAM]

Hide the wrappers [STREAM] and [/STREAM]?

ffprobe -v error -hide_banner -select_streams v:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1 film.mp4

bit_rate=5277205

 

To get access to this information, you have to specify the following in your commandline

-show_streams get information on every stream

-show_format get information on the container format

-show_packets to get information on every packet

-show_frames to get information on every frame

Per-Stream information using ffprobe

Let’s get information on all the streams using the -show_streams specifier.

ffprobe -v error -hide_banner -select_streams v:0 -show_streams film.mp4
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_time_base=1001/48000
codec_tag_string=avc1
codec_tag=0x31637661
width=1920
height=800
coded_width=1920
coded_height=800
closed_captions=0
has_b_frames=1
sample_aspect_ratio=N/A
display_aspect_ratio=N/A
pix_fmt=yuv420p
level=41
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown
chroma_location=left
field_order=unknown
timecode=N/A
refs=1
is_avc=true
nal_length_size=4
id=N/A
r_frame_rate=24000/1001
avg_frame_rate=24000/1001
time_base=1/24000
start_pts=48000
start_time=2.000000
duration_ts=433433
duration=18.059708
bit_rate=5277205
max_bit_rate=N/A
bits_per_raw_sample=8
nb_frames=433
nb_read_frames=N/A
nb_read_packets=N/A
DISPOSITION:default=1
DISPOSITION:dub=0
DISPOSITION:original=0
DISPOSITION:comment=0
DISPOSITION:lyrics=0
DISPOSITION:karaoke=0
DISPOSITION:forced=0
DISPOSITION:hearing_impaired=0
DISPOSITION:visual_impaired=0
DISPOSITION:clean_effects=0
DISPOSITION:attached_pic=0
DISPOSITION:timed_thumbnails=0
TAG:language=und
TAG:handler_name=GPAC ISO Video Handler
TAG:vendor_id=[0][0][0][0]
[/STREAM]

The output contains a lot of vital information at a stream-level. You can inspect the height, width, frame-rate, bitrate, size, codec, codec level & profile, pixel format, presence of B-frames, etc.

Related:  How to Remove Audio from Video using FFmpeg. Bonus: Add, Extract, Replace

How about we go one level deeper and get information on a per-packet basis?

Per-Packet information using ffprobe

Using the following command, you can get information about every packet in your video i.e., using -show_packets. For demo purposes, I’ve only shown one of the packets. As you can see, it contains detailed information about the pts, dts, duration, size, etc.

ffprobe -v error -hide_banner -select_streams v:0 -show_packets film.mp4
[PACKET]
codec_type=video
stream_index=0
pts=72024
pts_time=3.001000
dts=72024
dts_time=3.001000
duration=1001
duration_time=0.041708
convergence_duration=N/A
convergence_duration_time=N/A
size=1094
pos=738626
flags=__
[/PACKET]

Super! Let’s now go one level deeper – down to the frame-level, shall we?

Per-Frame information using ffprobe

Now, let’s get information about every frame of video using the -show_frames command. The output contains a whole lot of information – the timestamps, width, height, pixel format, picture type (I, P, B), picture number in display-order and decode-order, color space, is the picture interlaced or not, and if it is – is it top-field-first or bottom-field-first? Is the frame a Keyframe? Tons of information on a frame-level, right?

ffprobe -v error -hide_banner -select_streams v:0 -show_frames film.mp4
[FRAME]
media_type=video
stream_index=0
key_frame=0
pkt_pts=53005
pkt_pts_time=2.208542
pkt_dts=53005
pkt_dts_time=2.208542
best_effort_timestamp=53005
best_effort_timestamp_time=2.208542
pkt_duration=1001
pkt_duration_time=0.041708
pkt_pos=283117
pkt_size=33853
width=1920
height=800
pix_fmt=yuv420p
sample_aspect_ratio=N/A
pict_type=P
coded_picture_number=2
display_picture_number=0
interlaced_frame=0
top_field_first=0
repeat_pict=0
color_range=unknown
color_space=unknown
color_primaries=unknown
color_transfer=unknown
chroma_location=left
[/FRAME]

Container-Format information using ffprobe

You can also get information about the container format using ffprobe using the -show_format option in the commandline. As you can see, it contains all the information about the container, the duration, size, bitrate, and any tags that accompany the container.

ffprobe -v error -hide_banner -select_streams v:0 -show_format film.mp4
[FORMAT]
filename=simpsons_1080p2398_clip.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.007007
duration=19.993000
size=12242914
bit_rate=4898880
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:title=The Simpsons Movie - Trailer
TAG:artist=20th Century Fox
TAG:date=2007
TAG:encoder=Lavf58.56.100
TAG:genre=Trailer
[/FORMAT]

Now that we’ve understood the depth of information available to us using ffprobe, let’s take a look at how to pretty-print the output so that it is easy to pass it on downstream (for post-processing, or use in compression, etc.)


Output formats – JSON, CSV, XML

ffprobe has a wide option of writers and you can choose from default format (as we’ve seen in previous examples), JSON, CSV, XML, flat, and ini output formats.

Choosing the output format is very simple and requires the use of the print_format <option> in the commandline. Here are a few examples of how the output looks for the show_format specifier.

JSON output from ffprobe

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format json -select_streams v:0 -show_format film.mp4
{
    "format": {
        "filename": "simpsons_1080p2398_clip.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.007007",
        "duration": "19.993000",
        "size": "12242914",
        "bit_rate": "4898880",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "title": "The Simpsons Movie - Trailer",
            "artist": "20th Century Fox",
            "date": "2007",
            "encoder": "Lavf58.56.100",
            "genre": "Trailer"
        }
    }
}

CSV output from ffprobe (also known as “compact”)

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format csv -select_streams v:0 -show_format film.mp4
format,simpsons_1080p2398_clip.mp4,2,0,"mov,mp4,m4a,3gp,3g2,mj2",QuickTime / MOV,0.007007,19.993000,12242914,4898880,100,isom,512,isomiso2avc1mp41,The Simpsons Movie - Trailer,20th Century Fox,2007,Lavf58.56.100,Trailer

ini output frm ffprobe

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format ini -select_streams v:0 -show_format film.mp4
[format]
filename=simpsons_1080p2398_clip.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.007007
duration=19.993000
size=12242914
bit_rate=4898880
probe_score=100

[format.tags]
major_brand=isom
minor_version=512
compatible_brands=isomiso2avc1mp41
title=The Simpsons Movie - Trailer
artist=20th Century Fox
date=2007
encoder=Lavf58.56.100
genre=Trailer

flat output from ffprobe

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat -select_streams v:0 -show_format film.mp4
format.filename="simpsons_1080p2398_clip.mp4"
format.nb_streams=2
format.nb_programs=0
format.format_name="mov,mp4,m4a,3gp,3g2,mj2"
format.format_long_name="QuickTime / MOV"
format.start_time="0.007007"
format.duration="19.993000"
format.size="12242914"
format.bit_rate="4898880"
format.probe_score=100
format.tags.major_brand="isom"
format.tags.minor_version="512"
format.tags.compatible_brands="isomiso2avc1mp41"
format.tags.title="The Simpsons Movie - Trailer"
format.tags.artist="20th Century Fox"
format.tags.date="2007"
format.tags.encoder="Lavf58.56.100"
format.tags.genre="Trailer"

select_streams

To extract only the codec details, or frame size, or picture_type, streams specifiers allow you to specify and extract only what information you need, and not print everything! To use these specifiers, you need first use the format, stream, packet, frame option, and then use -show_entries option along with the key that you are looking to extract.

Example : print the height and width of a video : height and width are present in the stream-level information. So, we need to first specify the option -show_entries in the command line. Then, we use stream=width, height to tell ffprobe to give us only the width and height details from the “stream” information.

Similarly, we can use “packet”, “format”, “frame”, “stream”, and then specify the keys (comma-separated) to print only that information.

Examples to extract information from streams

1. Height and Width

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat -select_streams v:0 -show_entries stream=width,height film.mp4
streams.stream.0.width=1920
streams.stream.0.height=800

2. Display PTS of all the packets (Picture TimeStamp)

ffprobe -v error -hide_banner -of default=noprint_wrappers=1 -select_streams v:0 -show_entries packet=pts_time film.mp4
pts_time=2.000000
pts_time=2.041708
pts_time=2.208542
pts_time=2.083417
pts_time=2.125125
pts_time=2.166833
pts_time=2.375375
pts_time=2.250250

3. Durée de la vidéo

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -select_streams v:0 -show_entries stream=duration film.mp4

4. Picture Types

picture types of every frame of a video using ffprobe, then you need to go down to the frame level. If you inspect the frame-level information we printed earlier, then you can see that the picture type information is contained in the pict_type key. So, let’s use that along with the frame modifier.

# Print the picture types of every frame in the flat format

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat  -select_streams v:0 -show_entries frame=pict_type film.mp4

frames.frame.0.pict_type="I"
frames.frame.1.pict_type="P"
frames.frame.2.pict_type="B"
frames.frame.3.pict_type="B"
frames.frame.4.pict_type="B"
frames.frame.5.pict_type="P"
frames.frame.6.pict_type="B"
frames.frame.7.pict_type="B"
frames.frame.8.pict_type="B"
frames.frame.9.pict_type="P"
frames.frame.10.pict_type="B"
frames.frame.11.pict_type="B"
frames.frame.12.pict_type="P"
frames.frame.13.pict_type="P"
frames.frame.14.pict_type="P"
frames.frame.15.pict_type="P"
frames.frame.16.pict_type="P"
frames.frame.17.pict_type="P"
frames.frame.18.pict_type="P"
frames.frame.19.pict_type="B"
frames.frame.20.pict_type="B"

5. Le bitrate d'une vidéo

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat -select_streams v:0 -show_entries stream=bit_rate film.mp4
streams.stream.0.bit_rate="5277205"

6. codec details

Where do you get the codec details? At the stream level, right? So, let’s use the stream specifier and get all this information out.

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat -select_streams v:0 -show_entries stream=codec_name,codec_long_name,profile,codec_tag_string film.mp4
streams.stream.0.codec_name="h264"
streams.stream.0.codec_long_name="H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"
streams.stream.0.profile="High"
streams.stream.0.codec_tag_string="avc1"

7. Pixel format

ffprobe -v error -hide_banner -of default=noprint_wrappers=0 -print_format flat  -select_streams v:0 -show_entries stream=pix_fmt film.mp4
streams.stream.0.pix_fmt="yuv420p"

---

FFprobe output is designed to be easily parsable by a textual filter, and consists of one or more sections of the form:

[SECTION]
key1=val1
...
keyN=valN
[/SECTION]

Metadata tags stored in the container or in the streams are recognized and printed in the corresponding '' FORMAT '' or '' STREAM '' section, and are prefixed by the string '' TAG: ''.

-formats Show available formats.The fields preceding the format names have the following meanings: Decoding available - Encoding available

-codecs Show available codecs.The fields preceding the codec names have the following meanings: (Decoding available - Encoding available)

V/A/S Video/audio/subtitle codec

Codec supports slices - Codec supports direct rendering - Codec can handle input truncated at random locations instead of only at frame boundaries

-bsfs Show available bitstream filters.

-protocols Show available protocols.

-filters Show available libavfilter filters.

-pix_fmts Show available pixel formats.

-loglevel loglevel Set the logging level used by the library. loglevel is a number or a string containing one of the following values: quiet, panic, fatal, error, warning, info, verbose, debug

-convert_tags Convert the tag names in the format container to the generic FFmpeg tag names.

-f format

-unit Show the unit of the displayed values.

-prefix Show a SI prefixes of the displayed values. Unless ''-byte_binary_prefix'' option is used all the prefix are decimal.

-byte_binary_prefix Force the use of binary prefixes for byte values.

-sexagesimal Use sexagesimal format HH:MM:SS .MICROSECONDS for time values.

-pretty Prettify the format of the displayed values, it corresponds to the options ''-unit -prefix -byte_binary_prefix -sexagesimal''.

-show_format Show information about the container format of the input multimedia stream.All the container format information is printed within a section with name '' FORMAT ''.

-show_streams Show information about each media stream contained in the input multimedia stream.Each media stream information is printed within a dedicated section with name '' STREAM ''.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *