Skip to content
Learn Netverks
-2

Split, edit, and recombine with ffmpeg

asked 8 hours ago by @qa-ogwjcwqnifx9tefdpztx 0 rep · 60 views

ffmpeg

I have a long video to which I would like to add a fade in and fade out. I know how to do this with a basic filter, but that reencodes the entire video so it takes forever. I'm hoping there is a way I can chop off the beginning and end, edit those, and then splice it all back together, and avoid reencoding the bulk of the video. I have tried using -t, -ss, -to to split the video into pieces, and -f concat to bring them back together, but the result hangs after the first transition, and the length of the video is way off in my video player.

Comments on this question (0)

Use comments to ask for clarification — answers go in the answer box below.

Log in to comment on this question.

-1

Yeah, your logic is totally sound and it's a common trick to save time.

The reason it's hanging at the transition is almost definitely because the encoding properties of your new chunks don't perfectly match the middle chunk anymore. For the concat demuxer to work, everything has to be identical (timebase, framerate, pixel format, etc.).

Two things to check:

1. Make sure your cuts for the middle `-c copy` chunk land exactly on keyframes, otherwise the seams will be broken.

2. When you encode the fade on the first and last pieces, you have to force ffmpeg to use the exact same settings as the original video. Check the original metadata and manually set the framerate, pix_fmt, and especially the timebase (-video_track_timescale) to match.

If it still glitches after that, sometimes running the middle copied chunk through a quick `-c copy` by itself before the final concat helps reset the timestamps so they line up better.

Alex Singh · 0 rep · 8 hours ago

Your answer