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

ffprobe 깊게 — 뭐든 검사하기

~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는 X-ray

실 workflow 에선 ffmpeg 보다 ffprobe 를 10배 더 돌려. 모든 encoder 버그, '왜 이 audio가 silent해' 순간, '잠깐 이거 frame rate 뭐야' 질문 — ffprobe 가 2초에 답해. 아래 다섯 flag 조합이 필요한 거 ~90% 커버.

출력 형식

-print_formatjson, xml, csv, flat, ini, 또는 default 사람 읽기 좋은. scripting 용은 무조건 json — 안정적으로 파싱되는 유일한 구조 있는 형식이야.

흔한 패턴

ffprobe 손 가는 순간: duration (초), 총 frame count, 정확한 frame rate (rational, 30000/1001 = 29.97), bitrate, dimension, color space, audio channel layout, metadata tag, chapter, stream 개수, 또는 그냥 'decode 가능한지' (에러는 stderr에 떠).

Code

ffprobe — 재사용할 recipe·bash
# Duration (초) — 배너 없이 숫자만
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

# 총 frame 개수 (전체 decode — 느리지만 정확)
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

shell 함수 한 줄짜리 vinfo <file> 작성: 순서대로 duration (초), 해상도 (WxH), video codec, audio codec, audio channel layout 출력. 다른 파일 셋에 테스트. 보너스: 평균 video bitrate 추가 (stream=bit_rate).

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.