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

Progress Monitoring

~8 min · progress, monitor, scripting

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

세 mode

  • Default — frame/time/bitrate stat 으로 single line redrawn. Interactive 사용에 좋음.
  • -progress pipe:1 — stdout 의 machine-readable progress event. Script 에 좋음.
  • -progress <file> — 같은 event 가 파일에 작성 (daemon/non-tty process 용).

Progress parsing

Machine format 이 newline 구분 key=value pair. out_time_us=12345678 = 현재 encode 위치 microsecond. fps=84.3, bitrate=4521.2kbits/s, progress=continue 또는 progress=end.

Code

Interactive vs scripted progress·bash
# Default interactive (redrawing line)
ffmpeg -i in.mp4 -c:v libx264 out.mp4

# Stdout 의 machine-readable, log noise 없음
ffmpeg -hide_banner -loglevel error -nostats \
  -i in.mp4 -c:v libx264 -crf 20 \
  -progress pipe:1 \
  out.mp4 | grep --line-buffered -E '^(out_time_us|progress)='

# 파일에 작성 (다른 데서 읽기)
ffmpeg -i in.mp4 -c:v libx264 \
  -progress /tmp/ffmpeg_progress.txt \
  out.mp4
Python progress callback·python
import subprocess

def encode_with_callback(src, dst, on_progress=lambda pct: None):
    # 총 duration 먼저 가져옴
    duration = float(subprocess.check_output([
        "ffprobe", "-v", "error", "-show_entries", "format=duration",
        "-of", "default=noprint_wrappers=1:nokey=1", src,
    ]))
    total_us = duration * 1_000_000

    p = subprocess.Popen([
        "ffmpeg", "-y", "-i", src,
        "-c:v", "libx264", "-crf", "20", "-preset", "slow",
        "-c:a", "copy",
        "-progress", "pipe:1",
        "-nostats", "-loglevel", "error",
        dst,
    ], stdout=subprocess.PIPE, text=True)
    for line in p.stdout:
        if line.startswith("out_time_us="):
            us = int(line.split("=", 1)[1])
            on_progress(min(100, us / total_us * 100))
    return p.wait()

encode_with_callback("in.mp4", "out.mp4",
                    on_progress=lambda p: print(f"\r{p:.1f}%", end="", flush=True))

External links

Exercise

Video encode + percentage progress bar 보이는 (-progress pipe:1 parsing) shell script 작성. 5분 clip 에 테스트. 그 다음 위 recipe 로 Python 으로 port. 보너스: 관찰된 encoding 속도 기반 ETA 계산 추가.

Progress

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

댓글 0

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

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