[FFmpeg-user] Generating aligned HLS segments for ABR delivery

Stefan Moro stefan.moro at gmail.com
Wed Mar 30 11:39:21 CEST 2016


I am using the segment muxer as part of a system to create an adaptive HLS
stream. The segment muxer creates MPEG-TS segments from key-frame-aligned,
closed-GOP and audio aligned renditions of the same content. The renditions
are transcoded such that is should be possible to segment them into PTS
aligned, equal length segments.

One of the renditions is encoded with H264 high profile, which utilizes
B-frames. When the high profile rendition is segmented, I see that it has a
different start PTS than the segments of the other renditions. It seems
that this causes the number of audio frames in the high profile segments to
differ from the number of audio frames in the other segments. I am aware
that it might make sense to change the start PTS of an MPEG TS in order to
avoid a negative DTS, but since all renditions start with a key-frame, we
should not encounter a negative DTS.

What I want is to not change any timing information at all, which would
ensure that each segment has the same number of video- and audio frames
with the same timing information. Is there any way for me to do this? I
have tried several combinations of vsync, copyts, avoid_negative_ts etc,
but with no success. The segments of the high profile rendition always has
a different number of audio frames compared the segments of the other
If it would help, adding the same offset to all A/V timestamps would also
be OK, e.g. adding 10 seconds to every timestamp. The important thing is
that all timestamps stay the same, relative to each other.

Below is the version of ffmpeg I last tried with and one version of the
ffmpeg command line I tried with. As I mentioned above, I also tried many
other variations using -copyts, -vsync, avoid_negative_ts, muxdelay,
mpegts_copyts etc but I'm posting the "basic" version of the command here.

Please see the following link for the script and the video renditions I am
using to test:

ffmpeg version:
ffmpeg version N-79160-gb73c271 Copyright (c) 2000-2016 the FFmpeg
built with gcc 5.2.1 (Ubuntu 5.2.1-22ubuntu2) 20151010
configuration: --prefix=/tmp/tmp_build_dir --pkg-config-flags=--static
--extra-ldflags=-L/tmp/tmp_build_dir/lib --bindir=/root/bin --enable-gpl
--enable-nonfree --enable-libx264 --enable-libsoxr --enable-libfdk-aac
libavutil      55. 19.100 / 55. 19.100
libavcodec     57. 32.100 / 57. 32.100
libavformat    57. 29.101 / 57. 29.101
libavdevice    57.  0.101 / 57.  0.101
libavfilter     6. 40.102 /  6. 40.102
libswscale      4.  0.100 /  4.  0.100
libswresample   2.  0.101 /  2.  0.101
libpostproc    54.  0.100 / 54.  0.100

Script (Basic version):

rm dst/*

for src in low mid high
    ffmpeg -i src/${src}.mp4 \
        -map 0:v:0 \
        -map 0:a:0 \
        -codec copy \
        -bsf:v h264_mp4toannexb \
        -f segment \
        -segment_format mpegts \
        -reference_stream 0:v:0 \
        -segment_list_type m3u8 \
        -segment_list_size 0 \
        -segment_time 9 \
        -segment_time_delta 0.1 \
        -segment_list dst/${src}.m3u8 \


More information about the ffmpeg-user mailing list