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)

6
  • You can encode the 20 second segment with the overlay as a separate file, then trim the first ~20 seconds from the original with -c copy. Then use the concat demuxer to join them. Note that the two resulting segments to be joined must match parameters (codec, timebase, etc), and you'll need to cut on a keyframe for best results. A lot of work for a one minute video. My laziness would tell me just re-encode it all or simply not deal with the overlay. If you're using a web based player you can have it add the logo instead.
    – llogan
    Commented Feb 29, 2016 at 23:41
  • @LordNeckbeard Thanks, but this operation will be executed many times, not just once. That is why I need performance.
    – dajuric
    Commented Mar 1, 2016 at 0:00
  • I assumed that was a possibility, but you didn't mention it in the question. You should show the complete console output from your command.
    – llogan
    Commented Mar 1, 2016 at 0:14
  • @LordNeckbeard Sorry for not mentioning. That was the complete output; I did not write anything else as I stuck on the first step.
    – dajuric
    Commented Mar 1, 2016 at 2:04
  • Does the overlay have to happen for exactly 20 seconds?
    – Gyan
    Commented Mar 1, 2016 at 5:10

1 Answer 1

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.

1
  • Thanks a lot (Mulvya and LordNeckbeard)! Can you just explain me if I cut a video to three pieces and I need to process the middle piece with a software, and that software requires the frame offset, how should i obtain that frame offset ? (I used force_keyframes to set the keyframes and then I did the cutting - is this OK ?)
    – dajuric
    Commented Mar 3, 2016 at 21:27

You must log in to answer this question.

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