如何从 mp4 视频创建视频块 (.ts) 和 .m3u8 文件?

How to create chunks of videos (.ts) and .m3u8 file from a mp4 video?

我需要从 mp4 视频创建固定时长(比如 5 或 10 秒)的视频块 (.ts)。而且我还需要不同格式的块(260p、480p、720p、1080p)。

我可以使用以下命令创建块和 m3u8:

ffmpeg -i input.mp4 -g 60 -hls_time 10 out.m3u8

但无法为上述不同的分辨率创建。

使用scale filter and the HLS muxer:

ffmpeg -i input.mp4 -filter_complex "[0]scale=-2:260[260];[0]scale=-2:480[480];[0]scale=-2:720[720];[0]scale=-2:1080[1080]" -map "[260]" -map 0:a -map "[480]" -map 0:a -map "[720]" -map 0:a -map "[1080]" -map 0:a -f hls -hls_time 10 -var_stream_map "v:0,a:0,name:260 v:1,a:1,name:480 v:2,a:2,name:720 v:3,a:3,name:1080" -hls_segment_filename "%v_%03d.ts" -master_pl_name "master.m3u8" "output_%v.m3u8"