When using trim to crop the start and end of a video, the frames leading up to my "crop start" time are static instead of removed. However, the frames following the "crop end" time are correctly removed.

To clarify- if the input is 10s, crop start is 2s, crop end is 5s, I expect a 3s video. Instead I get a 5s video, where 0-2s are black frames.

What part of my command could be causing this?

const args = [
    // '-ss',           // not helping
    // `${trimStart}`,  // not helping
        [pre]trim=duration=${crossfadeDuration / 2},\
        fade=d=${crossfadeDuration / 2}:alpha=1,\
        setpts=PTS+(${trimStart + newDuration - crossfadeDuration / 2}/TB)[jt];\
        [body]trim=${crossfadeDuration / 2},\
        fps=${fps < 24 ? fps : 24},\
        // '-an',       // not helping
        // '-shortest', // not helping

For context- my app is adding seamless loops to videos with an interactive trimmer. Here is a GIF of what the above command currently does:

timeline editor showing missing start frames

I suspect it has to do with PTS, but I'm really struggling to wrap my head around which PTS settings do what depending on their order, especially when dealing with multiple streams of varrying length.

1 Answer 1



Also note that this filter does not modify the timestamps. If you wish for the output timestamps to start at zero, insert a setpts filter after the trim filter.

Add setpts=PTS-STARTPTS after your trim filter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.