FFmpeg-将一个视频叠加到另一个视频上?

问题描述:

我知道这是一个非常开放的问题.我已经初步阅读了 FFmpeg ,但现在需要一些指导.

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

问题

  • 我有一个视频input.mov.
  • 我想在overlay.wov上方叠加另一个视频.
  • 结果应为单个视频(output.mov).
  • 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).
      • 完成对 FFmpeg 的初步阅读,并阅读
      • Done some initial reading into FFmpeg and read this question.

      谢谢-C.

  1. 后端是Go/Ruby.开放使用新语言.
  2. 应该保留第一个视频中的音频.
  3. 设置覆盖开始的时间间隔会很好.

当前解决方案

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

这几乎可行,但是:

  • 即使两个视频(input.mov& overlay.mov)的长度相同,覆盖也会被缩短.
  • 我不能在除0:00之外的任何时间间隔开始覆盖.
  • 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.

如果只需要ffmpeg命令,请尝试

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

这会在5秒钟时开始覆盖,覆盖的视频起点为00:15.

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

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

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