Skip to content

Instantly share code, notes, and snippets.

@janjachacz
Last active May 6, 2022 06:20
Show Gist options
  • Save janjachacz/dd4118a35a04ff98fdcd27742e7ab1fb to your computer and use it in GitHub Desktop.
Save janjachacz/dd4118a35a04ff98fdcd27742e7ab1fb to your computer and use it in GitHub Desktop.
Ffmpeg: Create m3u8 stream files
###
### to m3u8
###
FILE_NAME=video
FILE_EXT=m4v
ffmpeg -i ${FILE_NAME}.${FILE_EXT} \
-filter_complex \
"[0:v]split=4[v1][v2][v3][v4]; \
[v1]copy[v1out]; [v2]scale=w=1280:h=720[v2out]; [v3]scale=w=640:h=360[v3out]; [v4]scale=w=320:h=240[v4out]" \
-map "[v1out]" -c:v:0 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:0 5M -maxrate:v:0 5M -minrate:v:0 5M -bufsize:v:0 10M -preset slow -g 48 -sc_threshold 0 -keyint_min 48 \
-map "[v2out]" -c:v:1 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:1 3M -maxrate:v:1 3M -minrate:v:1 3M -bufsize:v:1 3M -preset slow -g 48 -sc_threshold 0 -keyint_min 48 \
-map "[v3out]" -c:v:2 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:2 1M -maxrate:v:2 1M -minrate:v:2 1M -bufsize:v:2 1M -preset slow -g 48 -sc_threshold 0 -keyint_min 48 \
-map "[v4out]" -c:v:3 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:3 0.5M -maxrate:v:2 1M -minrate:v:3 0.5M -bufsize:v:3 0.5M -preset slow -g 48 -sc_threshold 0 -keyint_min 48 \
-map a:0 -c:a:0 aac -b:a:0 96k -ac 2 \
-map a:0 -c:a:1 aac -b:a:1 96k -ac 2 \
-map a:0 -c:a:2 aac -b:a:2 48k -ac 2 \
-map a:0 -c:a:3 aac -b:a:3 48k -ac 2 \
-f hls \
-hls_time 2 \
-hls_playlist_type vod \
-hls_flags independent_segments \
-hls_segment_type mpegts \
-hls_segment_filename ${FILE_NAME}/stream_%v_data%02d.ts \
-master_pl_name master.m3u8 \
-var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2 v:3,a:3" ${FILE_NAME}/stream_%v.m3u8
###
### to quicktime
### CPU
ffmpeg -c:v libx265 -preset fast -crf 28 -tag:v hvc1 -c:a eac3 -b:a 224k -i <source> <target>
### GPU
ffmpeg -vcodec hevc_videotoolbox -b:v 6000k -tag:v hvc1 -c:a eac3 -b:a 224k -i <source> <target>
### Save stream
ffmpeg -i <source> -acodec copy -vcodec copy <target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment