Score:2

Creating HLS Playlists (M3u8) Using FFmpeg

cg flag

I created my own bash script that will create videos on demand with different resolutions and bit rates. I used "ffmpeg" tool do that, "ffmpeg" is a must, hence I can not use any other tool.

The result of my script is:

enter image description here

And each folder has:

enter image description here

The default video and the other videos with different bit rates.

I want to create a "HLS" playlist using "ffmpeg". I found a website that shows a script that is doing all of it :

ffmpeg -i brooklynsfinest_clip_1080p.mp4 \
-filter_complex \
"[0:v]split=3[v1][v2][v3]; \
[v1]copy[v1out]; [v2]scale=w=1280:h=720[v2out]; [v3]scale=w=640:h=360[v3out]" \
-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 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 \
-f hls \
-hls_time 2 \
-hls_playlist_type vod \
-hls_flags independent_segments \
-hls_segment_type mpegts \
-hls_segment_filename 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" stream_%v.m3u8 

I am more focused on the last part that I can not figure it out:

-f hls \
-hls_time 2 \
-hls_playlist_type vod \
-hls_flags independent_segments \
-hls_segment_type mpegts \
-hls_segment_filename 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" stream_%v.m3u8 

Does someone know how to do that in my case, I just need a ffmpeg command that works and I will be able to modified and adapted to my script.

I tried to do this, but it gives me an error:

enter image description here

Thank you so much for you time!

Score:2
br flag

The purpose of -var_stream_map is to group media streams together. In your example, v:0,a:0 means that video stream 1 and audio stream 1 are being grouped together.

All that's left to do is to name the streams and change the directory of the segments using -hls_segment_filename. To do this, update the -var_stream_map and -hls_segment_filename options like this:

-var_stream_map "v:0,a:0,name:1080p v:1,a:1,name:720p v:2,a:2,name:360p"
-hls_segment_filename akiyo.mp4_%v_directory/data%02d.ts

In these options, %v represents the stream name and %02d the segment number.

ilie alexandru avatar
cg flag
Thank you! I figure it out at the end, it was a stupid mistake. Thank you so much!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.