C.W.K.
Stream
Lesson 06 of 10 · published

ffprobe in Depth — Inspecting Anything

~12 min · ffprobe, inspection, json, metadata

Level 0Viewer
0 XP0/73 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

ffprobe is your X-ray

You'll run ffprobe 10x more than ffmpeg in real workflows. Every encoder bug, every 'why is this audio silent' moment, every 'wait, what frame rate is this' question — ffprobe answers it in two seconds. The five flag combos below cover ~90% of what you'll need.

Output formats

-print_format takes json, xml, csv, flat, ini, or the default human-readable. For scripting, always use json — it's the only format with stable, parseable structure.

Common patterns

Reach for ffprobe when you want to know: duration in seconds, total frame count, exact frame rate (rational, like 30000/1001 = 29.97), bitrate, dimensions, color space, audio channel layout, metadata tags, chapters, stream count, or whether a file even decodes (errors will appear in stderr).

Code

ffprobe — recipes you'll reuse·bash
# Duration in seconds (no banner, just the number)
ffprobe -v error -show_entries format=duration \
  -of default=noprint_wrappers=1:nokey=1 input.mp4

# Frame rate (rational form: 30000/1001 = 29.97)
ffprobe -v error -select_streams v:0 \
  -show_entries stream=r_frame_rate \
  -of default=noprint_wrappers=1:nokey=1 input.mp4

# Width x Height
ffprobe -v error -select_streams v:0 \
  -show_entries stream=width,height \
  -of csv=p=0:s=x input.mp4

# Total frame count (decodes the whole file — slow but accurate)
ffprobe -v error -count_frames -select_streams v:0 \
  -show_entries stream=nb_read_frames \
  -of default=noprint_wrappers=1:nokey=1 input.mp4

# Audio channel layout (stereo, 5.1, etc.)
ffprobe -v error -select_streams a:0 \
  -show_entries stream=channels,channel_layout \
  -of default=noprint_wrappers=1:nokey=1 input.mp4
ffprobe → JSON → Python·python
import json, subprocess

def probe(path: str) -> dict:
    out = subprocess.check_output([
        "ffprobe", "-v", "quiet", "-print_format", "json",
        "-show_format", "-show_streams", path,
    ])
    return json.loads(out)

info = probe("input.mp4")
print("duration:", info["format"]["duration"])
for s in info["streams"]:
    if s["codec_type"] == "video":
        print("video:", s["codec_name"], s["width"], "x", s["height"])
    elif s["codec_type"] == "audio":
        print("audio:", s["codec_name"], s["channels"], "ch")

External links

Exercise

Write a one-liner shell function vinfo <file> that prints, in order: duration (seconds), resolution (WxH), video codec, audio codec, audio channel layout. Test it on three different files. Bonus: add the average video bitrate (stream=bit_rate).

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.