Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg - Overlay one video onto another video?

I understand that this is a very open ended question. I have done some initial reading into FFmpeg, but now require some guidance.

Problem

  • I have a video input.mov.
  • I would like to overlay another video on top of overlay.wov.
  • The result should be a single video (output.mov).

Notes

  • Done some initial reading into FFmpeg and read this question.

Thanks - C.

Edits

  1. Backend is Go/Ruby. Open to using a new language.
  2. The audio from the first video should be kept.
  3. Setting the interval at which the overlay starts would be great.

Current Solution

ffmpeg -i input.mov -i overlay.mov -filter_complex "[0:0][1:0]overlay[out]" -shortest -map [out] -map 0:1 -pix_fmt yuv420p -c:a copy -c:v libx264 -crf 18  output.mov

This nearly works, however:

  • Overlay is cut short even though the two videos (input.mov & overlay.mov) are the same length.
  • I cannot start the overlay at any interval apart from 0:00.
like image 299
cdrev Avatar asked Feb 08 '16 12:02

cdrev


People also ask

What is overlay FFmpeg?

FFmpeg offers the overlay filter as a way to overlay images (or even other videos) onto video streams. To centre overlay/watermark on a video, use this command: ffmpeg -i inputvideo.avi -i watermarklogo.png -filter_complex \ "overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2" -codec:a copy output.flv.

Can FFmpeg cut video?

FFmpeg offers different commands that you can use to split up a video. We'll take a look at how to use the seeking parameter -ss , but you can also use other commands such as the trim filter. To cut a specific part of a video, you use the seeking option -ss to get to a specific part that you want to cut.


1 Answers

If you just want a ffmpeg command, try

ffmpeg -i input.mov -i overlay.mov \
-filter_complex "[1:v]setpts=PTS-10/TB[a]; \
                 [0:v][a]overlay=enable=gte(t\,5):shortest=1[out]" \
-map [out] -map 0:a \
-c:v libx264 -crf 18 -pix_fmt yuv420p \
-c:a copy \
output.mov

This starts the overlay at 5 seconds with the overlaid video start point being 00:15.

setpts=PTS-10/TB is setpts=PTS+(overlay_delay-video_trim_in)/TB

overlay=enable=gte(t\,5) is overlay=enable=gte(t\,overlay_delay)

like image 175
Gyan Avatar answered Oct 17 '22 19:10

Gyan