ffmpeg HLS 分割音视频文件

我想执行 HLS 分段,并从带有音频的 .mp4 视频中为每个分段获取单独文件中的音频和视频。无需调整比特率,因为这会导致额外的延迟。

我试着用

ffmpeg -i videoInput.mp4 -c:v 复制 –c:a 复制 -hls_segment_type mpegts –map a:0 –map v:0 -hls_time 1 out.m3u8 audio.ts

它完美地生成了视频文件,但只有一个音频文件。

谢谢你。

stack overflow ffmpeg HLS segmentation audio and video files
原文答案

答案:

作者头像

I don't know the exact solution, but as a workaround, you can extract the audio first with:

ffmpeg -i video.mp4 -c:a copy -vn audio.aac 

Then apply segmentation for video and audio files separately

Audio:

 ffmpeg -i audio.aac -c:a copy -hls_segment_type mpegts -map a:0 -hls_time 1 out_aud.m3u8

Video:

ffmpeg -i video.mp4 -c:v copy -hls_segment_type mpegts -map v:0 -hls_time 1 out_vid.m3u8
作者头像

From the FFmpeg documentation I understand:

       When there are two or more variant streams, the output filename
       pattern must contain the string "%v", this string specifies the
       position of variant stream index in the output media playlist
       filenames. The string "%v" may be present in the filename or in the
       last directory name containing the file. If the string is present
       in the directory name, then sub-directories are created after
       expanding the directory name pattern. This enables creation of
       variant streams in subdirectories.

'''

For me:

ffmpeg -hide_banner  -t 5:00 -i "$IN" -c copy -map a:0 -map v:0  -hls_segment_type mpegts -hls_time 1 -f hls   -var_stream_map "a:0 v:0"    v_%v/file.m3u8

creates both streams in v_0 & v_1.