[FFmpeg-user] problem with fast seeking and splitting

Ferdi Scholten ferdi at sttc-nlp.nl
Mon May 2 23:59:08 EEST 2022

On 02-05-2022 10:18, Paul B Mahol wrote:
> On Mon, May 2, 2022 at 9:54 AM Alexander Solonsky <
> alexander.solonsky at castlabs.com> wrote:
>> Monday, May 2, 2022, 2:21:17 PM, you wrote:
>> On Mon, May 2, 2022 at 7:27 AM Alexander Solonsky via ffmpeg-user <
>> ffmpeg-user at ffmpeg.org> wrote:
>>> Dear Experts,
>>> I'm trying to split an input file into 2 second chunks, transcode and
>>> assemble using a concat muxer. And experiencing two problems:
>>> major one:
>>> 1) when using ffmpeg -ss 00:00:08 -t 2 -i <input_file> -c:v libx264 ....
>>> instead of seeking to second 8, ffmpeg seeks somewhere to second 15 or so.
>>> The first segments are correct, and then it start to go haywire.
>>> Using accurate seek ffmpeg  -i <input_file> -ss 00:00:08 -t 2 -c:v
>>> libx264 ....  resolves the problem. But it is completely unusuble if you
>>> want to split the whole file.
>>> Minor one:
>>> 2) when concatenating the resulting files - there happens a noticeable
>>> break between the chunks. For both audio and video and is equal to 2
>>> additional frame durations (e.g. prev chunk ends at 1.981333 and the next
>>> chunk (after concat) while it should start at 2.023000 actually starts at
>>> 2.095744 for 24 fps video, and for audio prev chunk ends at 1.927256 and
>>> starts at 2.023220 while it should start at 1.950476).
>>> adding all additional flags like copyts, copytb, enctimebase, vsync
>>> doesn't change anything. And it's really curious when using the hls demuxer
>>> - it splits the file accurately and fast, without these breaks.
>>> Can you please help me fix those two problems or suggest to understand
>>> which command like I could use to reproduce splitting behavior from the HLS
>>> demuxer?
HLS demuxer is a totally different beast than ffmpeg, it operates from 
an audio/video stream (from hlssink2) and it generates keyframes when 
desired e.g. when the stream needs cutting it generates a keyframe for 
that purpose from which the cut can be made.

ffmpeg works with the encoded audio/video container that has fixed 
keyframes, if you want the same behaviour you will need to work with 
uncompressed audio/video.

Ferdi Scholten

More information about the ffmpeg-user mailing list