Search code examples
videoffmpeghttp-live-streamingtranscoding

FFMpeg HLS Video Transcoding Generating Partial Playlist


I'm trying to convert a basic mp4 video into an HLS video using ffmpeg (running on OSX) using the following command:

ffmpeg -i SampleVideo_1280x720_10mb.mp4 -codec:v libx264 -codec:a aac -strict experimental -start_number 1 out.m3u8

It does manage to generate all of the .ts segment files, but the resulting .m3u8 playlist file only lists the final four segment files, cutting out any earlier segments. Help?


Solution

  • According to the ffmpeg documentation, the playlist defaults to 5 entries and a segment duration of 2 seconds. This probably explains why you are only seeing a limited number of entries in the playlist. Try setting the length of the playlist (-hls_list_size) to 0, which will include all the segments. Apple recommends a segment duration of 10 seconds. You can set the segment duration with the -hls_time option.

    For reference, you can also use the segment muxer. Here's the command I usually use when segmenting video with ffmpeg:

    ffmpeg -y \
     -i input.mov \
     -codec copy \
     -bsf h264_mp4toannexb \
     -map 0 \
     -f segment \
     -segment_time 10 \
     -segment_format mpegts \
     -segment_list "/Library/WebServer/Documents/vod/prog_index.m3u8" \
     -segment_list_type m3u8 \
     "/Library/WebServer/Documents/vod/fileSequence%d.ts"
    

    In this instance, the input video contains H.264 video and AAC audio so it doesn't need to be transcoded.