You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Issue with repeating segments at start of each export & merge clip #2804
This problem happens with all kinds of files that I try. For problem only with a particular file or type, use this other form instead
Operating System
Windows 11
Steps to reproduce
source a youtube video via yt-dlp that results in a .mkv video file
select several non-contiguous clips
export & merge
Expected behavior
File exports as expected regardless of container type, with maybe some differences depending on whether smart or keyframe cut is used.
Actual behavior
When exporting MKV clips to a new video with an MKV container, the preceding second or so leading up to the clip is repeated prior to the clip actually starting.
The problem does not exist when the clips are exported with an MP4 container.
Reproducing with GNOME screen recorder .webm files on Linux.
The root cause is that GNOME's screen recorder produces .webm files with only a single keyframe at the very beginning (~0.005s). With -ss before -i and -c copy, ffmpeg must seek to the nearest keyframe before the cut point — which in this case is always the very first frame of the file. So every exported segment starts from the beginning of the original video.
With no keyframes at the cut points, the output file contains all frames from 0.005s up to the segment end, not just the intended 15.73s–25.38s range. The container timestamps are adjusted correctly (starting at 0), but the actual frame data includes everything before the cut.
Workaround: Re-encode instead of stream copy (e.g. VP9 libvpx-vp9 -crf 18 -b:v 0), which allows frame-accurate cuts regardless of keyframe placement.
Possible fix: LosslessCut could detect sparse/missing keyframes at cut points and warn the user, or automatically fall back to re-encoding for those segments.
Workaround: Re-encode instead of stream copy (e.g. VP9 libvpx-vp9 -crf 18 -b:v 0), which allows frame-accurate cuts regardless of keyframe placement.
Possible fix: LosslessCut could detect sparse/missing keyframes at cut points and warn the user, or automatically fall back to re-encoding for those segments.
The workaround I got was to switch container format, no transcoding required?
...but when i open it in losslesscut and export it outputs the correct starting keyframe regardless of which output format i select (mp4/mkv). The cut i did is:
{start: 4.333333,end: 9.5,}
(2nd keyframe is at 4.333333, 1st is at 0.)
I can also get yt-dlp to download a webm file (with vp9 video):
...and i can reproduce your problem (I think) when cutting it and exporting as mkv: it will start from the first keyframe (time 0) instead of the desired keyframe at 4.333333. But when I select mp4 output format it plays from the correct keyframe at 4.33333 (with VLC because quicktime/macos doesn't allow playback of vp9 inside mp4).
So it works differently between mp4 and mkv, with otherwise the exact same ffmpeg command. I would most definitely say that this is yet another bug or quirk in FFmpeg which makes it even harder to reason about how FFmpeg chooses the start cutpoint. I will update docs.
I think I found the cause of this: for mkv/webm files with b-frames, ffmpeg seeks 3/23s earlier than asked, so a cut starting on a keyframe would start from the previous keyframe, repeating a part of the video at the start of each cut. #3131 should fix that and it's in the nightly now https://mifi.no/llc/nightly/ - it's only been tested on synthetic files so far, so would be great if you can try it
Activity
soup2002-rgb commentedon Mar 16, 2026
Having the exact same issue
spk commentedon Mar 18, 2026
Reproducing with GNOME screen recorder .webm files on Linux.
The root cause is that GNOME's screen recorder produces .webm files with only a single keyframe at the very beginning (~0.005s). With -ss before -i and -c copy, ffmpeg must seek to the nearest keyframe before the cut point — which in this case is always the very first frame of the file. So every exported segment starts from the beginning of the original video.
You can verify this with:
On my file this outputs a single line: packet,0.005000,K_
LosslessCut runs:
With no keyframes at the cut points, the output file contains all frames from 0.005s up to the segment end, not just the intended 15.73s–25.38s range. The container timestamps are adjusted correctly (starting at 0), but the actual frame data includes everything before the cut.
Workaround: Re-encode instead of stream copy (e.g. VP9 libvpx-vp9 -crf 18 -b:v 0), which allows frame-accurate cuts regardless of keyframe placement.
Possible fix: LosslessCut could detect sparse/missing keyframes at cut points and warn the user, or automatically fall back to re-encoding for those segments.
SignpostMarv commentedon Mar 18, 2026
The workaround I got was to switch container format, no transcoding required?
mifi commentedon May 30, 2026
I couldn't find a way for yt-dlp to download an mkv file directly, but I can get it to download an mp4 file (with h264):
yt-dlp -f 136 'https://www.youtube.com/watch?v=zgaN8OXLaOQ'...but when i open it in losslesscut and export it outputs the correct starting keyframe regardless of which output format i select (mp4/mkv). The cut i did is:
(2nd keyframe is at 4.333333, 1st is at 0.)
I can also get yt-dlp to download a webm file (with vp9 video):
...and i can reproduce your problem (I think) when cutting it and exporting as mkv: it will start from the first keyframe (time 0) instead of the desired keyframe at 4.333333. But when I select mp4 output format it plays from the correct keyframe at 4.33333 (with VLC because quicktime/macos doesn't allow playback of vp9 inside mp4).
So it works differently between mp4 and mkv, with otherwise the exact same ffmpeg command. I would most definitely say that this is yet another bug or quirk in FFmpeg which makes it even harder to reason about how FFmpeg chooses the start cutpoint. I will update docs.
mifi commentedon May 30, 2026
I've added a reference to this in #1216 - so i'm closing this issue because i don't know how to fix this also
fix keyframe warn logic
Compensate ffmpeg's B-frame seek offset for Matroska keyframe cuts
mifi commentedon Oct 18, 2026
I think I found the cause of this: for mkv/webm files with b-frames, ffmpeg seeks 3/23s earlier than asked, so a cut starting on a keyframe would start from the previous keyframe, repeating a part of the video at the start of each cut. #3131 should fix that and it's in the nightly now https://mifi.no/llc/nightly/ - it's only been tested on synthetic files so far, so would be great if you can try it