0

I am trying to apply the overlay filter on the video to blend a single image for a few seconds. Since my video duration is about 1 min it seems wasteful when FFMPEG tries to re-encode the whole video again instead of reencoding the portion of the video that needs to be altered.

My blend video command is:

ffmpeg -i beach.mp4 -i logo.png 
-filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,20)'" 
-pix_fmt yuv420p -c:a copy output.mp4

Does anyone knows how can I avoid this ? (I was thinking to split the video, but is seems that the video can not be split accurately by specifying the start and the end frame)

dajuric
  • 119

1 Answers1

2

Since you're okay with some inaccuracy, I suggest the following method:

Segment the video input

ffmpeg -i beach.mp4 -c copy -segment_time 20 -f segment beach_seg%02d.mp4

Overlay logo on first segment

ffmpeg -i beach_seg00.mp4 -loop 1 -i logo.png 
-filter_complex "[0:v][1:v] overlay=25:25:shortest=1" 
-pix_fmt yuv420p -c:a copy overlay.mp4

Concat segments

First, prepare a text file segments.txt

file 'overlay.mp4'
file 'beach_seg01.mp4'
file 'beach_seg02.mp4'
file 'beach_seg03.mp4'
...

Then, concat

ffmpeg -f concat -i segments.txt -c copy beach_with_logo.mp4

The caveat here is that the timebase of overlay.mp4 may not match those of the beach segments. In which case, check the timebase of one of the beach segments (the tbn) and add -video_track_timescale <tbn> to the overlay command.

llogan
  • 63,280
Gyan
  • 38,955