0

Basically, I want to take two rectangles ouf of sixth minute of the video and overlay them at an earlier point in the video.

If I use ffmpeg three times like this:

ffmpeg -i a.mp4 -filter_complex "[0:v]trim=start_frame=9000:end_frame=9001,crop=1280:100:0:0,null,setpts=PTS-STARTPTS[v]" -map [v] -c:v libx264 -c:a null -crf 15 -preset slow -y -t 0.1 still1.mp4
ffmpeg -i a.mp4 -filter_complex "[0:v]trim=start_frame=9000:end_frame=9001,crop=100:100:600:500,null,setpts=PTS-STARTPTS[v]" -map [v] -c:v libx264 -c:a null -crf 15 -preset slow -y -t 0.1 still2.mp4
ffmpeg -i a.mp4 -i still1.mp4 -i still2.mp4 -filter_complex \
"[0:v][1:v]overlay=0:0:enable='between(t,60,61)'[v0]; \
[v0][2:v]overlay=600:500:enable='between(t,60,61)'[v1]" \
-map [v1] -c:v libx264 -crf 17 -preset slow -y -t 362 p.mp4

The consumption of RAM as measured by top stays around 3 GB. However, when I try it in one command, it quickly eats up 13GB of my free memory and the process quickly gets killed by OOM killer:

ffmpeg -i a.mp4 -filter_complex \
"[0:v]trim=start_frame=9000:end_frame=9001,crop=1280:100:0:0,setpts=PTS-STARTPTS[still1]; \
[0:v]trim=start_frame=9000:end_frame=9001,crop=100:100:600:500,setpts=PTS-STARTPTS[still2]; \
[0:v][still1]overlay=0:0:enable='between(t,61,62)'[v0]; \
[v0][still2]overlay=600:500:enable='between(t,61,62)'[v1]" \
-map [v1] -c:v libx264 -crf 17 -preset slow -y  p.mp4

I suspect ffmpeg keeps all the frames decoded in memory when trimming, but is there any way around this? It sounds wastefull, I am interested in two little frames, that should not eat up GB of memory!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.