4

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?

moberemk
  • 1,597
  • 1
  • 18
  • 39

2 Answers2

3

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.

Simon
  • 1,194
  • 7
  • 11
  • 1
    The `hls_list_size` flag solved it perfectly, thanks. I saw that in the docs and overlooked it because I assumed that they'd just use the (to me) sensible default that would include all of the files. Thanks! – moberemk Feb 17 '16 at 14:39
2

Try

ffmpeg -i SampleVideo_1280x720_10mb.mp4 -c:v libx264 -c:a aac -strict -2 -start_number 1 -hls_list_size 0 out.m3u8
Gyan
  • 85,394
  • 9
  • 169
  • 201