1

I have many h265 clips, all six seconds long. Now I want to string these together with ffmpeg (preferably without reencoding), but only use the parts from second 2 to 4 of each clip. I do this with the concat demuxer, but as soon as i specify inpoint and duration, my results get pretty random. It does not throw any errors and produces new clips, but lengths and inpoints are totally off.
As my clips are h265 and rather short, my first suspicion was, that there are simply no keyframes it can edit to, so I tried the same with Quicktime Prores clips (intraframe encoded) – which gave me similarly weired results though. So I'm wondering wether the problem might be somewhere else?

This is my code (calling from Python):

subprocess.call(['ffmpeg', '-f', 'concat', '-safe', '0', '-i', 'concatlist.txt', '-c', 'copy', '-hide_banner', '-loglevel', 'error', output])

This is a sample of my (auto-generated) text file:

file videos_squares/vt_5Hn8lze0G8A.mp4
inpoint 2.0
duration 2.0
file videos_squares/vt_J8DuC93hLq0.mp4
inpoint 2.0
duration 2.0
file videos_squares/vt_u8twUOpagZs_seg3.mp4
inpoint 2.0
duration 2.0

1 Answer 1

1

To limit the duration using the concat demuxer, set outpoint (with value inpoint + intended duration).

The duration keyword is badly named and it basically sets the offset for the starting timestamp for the next clip with respect to the starting timestamp of the current clip. But it does not limit the output from the current clip.

5
  • works nicely now! actually, i initially did in- and outpoints, but changed that AFTER reading the ffmpeg docs - they are really misleading. anyway, thanks for clearing this up! Commented Jan 8, 2021 at 12:24
  • sorry, one more question: strangely it still does not work for the first clip: in the concatenated result, all clips are 2 sec long (as they should), but the very first one in each file is the double, 4 seconds (so the resulting clip is also 2 sec longer then expected). the in- and oupoints in the list are the same for all clips though... any ideas? Commented Jan 8, 2021 at 14:27
  • Where are the keyframes in the first clip?
    – Gyan
    Commented Jan 8, 2021 at 14:41
  • your are right, this time it actually is a keyframe problem as it only happens with h265 but not with prores. there are other problems with that, but these might be unrelated though – let me sort this out, then i'll get back to you. for the time being: thanks a lot for your help with this!!!! Commented Jan 8, 2021 at 15:47
  • so, for the record: after some more testing, i figured this just works way better with prores, especially if the trim offsets are small - which is not surprising given it's an intraframe codec. also, it's much faster. i also ran into a bunch of problems with audio too, so stripping that helped - and even then, it's no perfect science but i guess video durations rarely are... Commented Jan 8, 2021 at 17:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .