假设我有以下文件列表:音频:
file1.mp3 //audiotrack 1
file2.mp3 //audiotrack 2
file3.mp3 //audiotrack 3
字幕:
file1.vtt //subtitle 1
file2.vtt //subtitle 2
file3.vtt //subtitle 3
视频:
file1_320x280.mp4 //video quality 1
file2_640x11024.mp4 //video quality 2
file3_1200x1600.mp4 //video quality 3
如何使用 FFMPEG 将所有这些文件转换为带有 m3u8 文件的 .TS 片段?
另外,video.js HLS 扩展是否允许用户选择质量?
答案1
我不是这个领域的专业人士,但这是我的处理方式。
参考文献: 您想要的体现的完美示例。
首先:
为每个视频制作 .m3u8 播放列表
ffmpeg -i file1_320x280.mp4 -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls file1_320x280.m3u8
ffmpeg -i file2_640x11024.mp4 -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls file2_640x11024.m3u8
ffmpeg -i file3_1200x1600.mp4 -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls file3_1200x1600.m3u8
第二:
为每个音频制作 .m3u8 播放列表(我使用与视频相同的命令)
ffmpeg -i file1.mp3 -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls file1_320x280.m3u8
ffmpeg -i file2.mp3 -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls file2.m3u8
ffmpeg -i file3.mp3 -profile:v baseline -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls file3.m3u8
然后我为每个字幕手动创建包含以下内容的 .m3u8 文件:
#EXTM3U
#EXT-X-TARGETDURATION: <<VIDEO RUNTIME HERE>>
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF: <<VIDEO RUNTIME HERE>>,
file1.vtt
#EXT-X-ENDLIST
其中 #EXTINF 和 #EXT-X-TARGETDURATION 是视频的时长(以秒为单位)。例如(假设视频时长为 00:14:47):
sub1.m3u8:
#EXTM3U
#EXT-X-TARGETDURATION:887
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:887.0,
file1.vtt
#EXT-X-ENDLIST
sub2.m3u8:
#EXTM3U
#EXT-X-TARGETDURATION:887
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:887.0,
file2.vtt
#EXT-X-ENDLIST
sub3.m3u8:
#EXTM3U
#EXT-X-TARGETDURATION:887
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:887.0,
file3.vtt
#EXT-X-ENDLIST
最后,我为此示例手动创建了包含以下内容的 master.m3u8 文件:
#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="stereo",LANGUAGE="lang",NAME="Some audio name",DEFAULT=YES,AUTOSELECT=YES,URI="file1.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="stereo",LANGUAGE="lang2",NAME="Some audio name",DEFAULT=NO,AUTOSELECT=YES,URI="file2.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="stereo",LANGUAGE="lang3",NAME="Some audio name",DEFAULT=NO,AUTOSELECT=YES,URI="file3.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Deutsch",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="de",URI="sub1.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=YES,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI="sub2.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="Espanol",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="es",URI="sub3.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=258157,CODECS="avc1.4d400d,mp4a.40.2",AUDIO="stereo",RESOLUTION=320x280,SUBTITLES="subs"
file1_320x280.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=520929,CODECS="avc1.4d4015,mp4a.40.2",AUDIO="stereo",RESOLUTION=file2_640x11024,SUBTITLES="subs"
file2_640x11024.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1144430,CODECS="avc1.4d401f,mp4a.40.2",AUDIO="stereo",RESOLUTION=1200x1600,SUBTITLES="subs"
file3_1200x1600.m3u8