用ffmpeg產生dash串流並播放


這裡簡化這篇的指令
https://stackoverflow.com/questions/48256686/how-to-create-multi-bit-rate-dash-content-using-ffmpeg-dash-muxer

產生多個bitrate及解析度的串流
./ffmpeg -y -i /content/FHD.ts \
  -c:v libx264 \
  -c:a copy \
  -map 0:v:0 -b:v:0 250k -filter:v:0 "scale=-2:240" -profile:v:0 baseline \
  -map 0:v:0 -b:v:1 750k -filter:v:1 "scale=-2:480" -profile:v:1 main \
  -map 0:v:0 -b:v:2 1.5M -filter:v:2 "scale=-2:720" -profile:v:2 high \
  -map 0:v:0 -b:v:3 8M   -profile:v:3 high \
  -map 0:a:0 \
  multiple_bitrate.mp4

這裡設定的影片bitrate和解析度分別為
250k, 240p(426x240)
750k, 480p(854x480)
1.5M, 720p(1280x720)
8M, 原始大小(1920x1080)
audio不改變bitrate

用多birate及解析度的串流產生dash
./ffmpeg -y -re -i multiple_bitrate.mp4 \
  -map 0 \
  -f dash sample_dash.mpd

產生出dash串流檔案,包括一個mpd(xml格式), 還有一大堆類似HLS的影音segment
init-stream0.m4s
init-stream1.m4s
init-stream2.m4s
...
chunk-stream0-00001.m4s
chunk-stream0-00002.m4s
chunk-stream0-00003.m4s
....

如果要作其他調整請參考ffmpeg官方文件
https://ffmpeg.org/ffmpeg-formats.html#dash-2

常用調整
-seg_duration 每個 segment的長度(秒)
-init_seg_name 初始segment的檔案名字,預設是"init-stream$RepresentationID$.$ext$"
-media_seg_name segment的檔案名字,預設是"chunk-stream$RepresentationID$-$Number%05d$.$ext$".
-dash_segment_type segment的輸出類型mp4/webm

播放dash串流
./ffplay sample_dash.mpd

切換video在播放時按v, 可以看到解析度改變,只是ffplay按v不會自動改視窗大小, 你只會覺得畫面變差了。


其他參考
x264 - 高品質 H.264 編碼器
https://www.mobile01.com/topicdetail.php?f=510&t=3735840

X264 Settings
http://www.chaneru.com/Roku/HLS/X264_Settings.htm

留言