[FFmpeg-user] segment muxer and hls muxer, strange behavior when seeking

Steffen Deusch steffen at deusch.me
Thu Mar 3 15:55:32 CET 2016


Hi all,

I’ve noticed that the generic file segmenter and the HLS segmenter act differently when seeking:

ffmpeg -i /path/to/file.mkv 
-map 0:0 -codec:0 copy -bsf:0 h264_mp4toannexb
-map 0:1 -codec:1 aac -strict:1 experimental -channel_layout:1 stereo
-segment_format mpegts -f segment -flags -global_header -segment_time 10 
-segment_start_number 0 -segment_time_delta 0.0625 -max_delay 5000000
-avoid_negative_ts disabled -map_metadata -1 media-%05d.ts -start_at_zero
-copyts -vsync cfr

file.mkv has a length of 1391.232000 seconds, reported by ffprobe. Using a segment_time of 10, we
expect about 140 segments: 001-138 with 10 seconds length, 139 with 1 second length.
When we do not seek, we will get 138 segments, which is approximately what we expected.

But now the problem:
If we want to start at segment 130 -> ffmpeg with -ss 1300 and -segment_start_number 130,
we would expect ffmpeg generating about 10 segments: 130-138 with 10 seconds length and 
139 with 1 second length

ffmpeg -ss 1300 -noaccurate_seek -i /path/to/file.mkv 
-map 0:0 -codec:0 copy -bsf:0 h264_mp4toannexb
-map 0:1 -codec:1 aac -strict:1 experimental -channel_layout:1 stereo
-segment_format mpegts -f segment -flags -global_header -segment_time 10
-segment_start_number 130 -segment_time_delta 0.0625 -max_delay 5000000
-avoid_negative_ts disabled -map_metadata -1 media-%05d.ts -start_at_zero
-copyts -vsync cfr

But this command will create more than ~140 segments. In this example the last segment suddenly gets the number
185, which does absolutely not fit to the calculation.

When using -f hls the segmenter acts as expected:

ffmpeg -ss 1300 -noaccurate_seek -i /path/to/file.mkv 
-map 0:0 -codec:0 copy -bsf:0 h264_mp4toannexb
-map 0:1 -codec:1 aac -strict:1 experimental -channel_layout:1 stereo
-segment_format mpegts -f hls -hls_time 10 -start_number 130
-segment_time_delta 0.0625 -max_delay 5000000
-avoid_negative_ts disabled -map_metadata -1 -hls_segment_filename 
media-%05d.ts playlist.m3u8 -start_at_zero -copyts -vsync cfr

We get 138 segments, exactly like without seeking.
Is this behavior expected?

Thanks for any help,
Steffen Deusch


More information about the ffmpeg-user mailing list