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

라이브 Streaming (RTMP)

~10 min · rtmp, live, twitch, youtube-live

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

RTMP push

YouTube Live, Twitch, Restream, 대부분 streaming service 가 RTMP push 받아. 패턴: H.264 + AAC 로 encode, stable bitrate (CBR 또는 near-CBR) target, rtmp://server/path/streamkey 로 push.

여기서 CBR 이 중요한 이유

Live viewer 가 high-bitrate frame 을 'wait' 못 함. Buffer 가 짧고 server 가 stable byte rate 기대. 작은 bufsize 의 CBR 이 encoder predictable 유지.

Code

YouTube 라이브·bash
# Video 파일을 'live' source 로 capture 후 YouTube Live 에 push
# Stream key 는 YouTube Studio → Go Live → Stream Key
STREAM_KEY="xxxx-xxxx-xxxx-xxxx"

ffmpeg -re -i in.mp4 \
  -c:v libx264 -preset veryfast -b:v 4500k -maxrate 4500k -bufsize 9000k \
  -g 60 -keyint_min 60 -sc_threshold 0 \
  -pix_fmt yuv420p \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv \
  "rtmp://a.rtmp.youtube.com/live2/$STREAM_KEY"

# -re = native frame rate 로 input 읽기 (라이브 인 척하며 파일 push 할 때
# mandatory — 없으면 FFmpeg 이 가능한 가장 빠르게 업로드 + buffer overflow
# 로 disconnect)
라이브 화면 capture push·bash
# Apple Silicon — 화면 + 시스템 audio 를 라이브 RTMP stream 으로 push
ffmpeg \
  -f avfoundation -framerate 30 -capture_cursor 1 -i "1:0" \
  -c:v h264_videotoolbox -b:v 5000k -maxrate 5000k -bufsize 5000k \
  -pix_fmt yuv420p -g 60 \
  -c:a aac -b:a 128k -ar 44100 \
  -f flv "rtmp://a.rtmp.youtube.com/live2/$STREAM_KEY"

# Linux 동일은 x11grab + pulse 사용:
# ffmpeg -f x11grab -framerate 30 -i :0.0 -f pulse -i default ...

External links

Exercise

Private YouTube Live stream 셋업 + FFmpeg 으로 local video 파일 (-re trick) 60초 push. YouTube Studio stream health monitor 봐 — bitrate stable? Buffer warning 없음? 그 다음 -bufsize 값 1×, 2×, 4× bitrate 로 실험 + flaky network 에서 viewer 측 stall 어떻게 변하는지 관찰.

Progress

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

댓글 0

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

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