FFmpeg - 将一个视频叠加到另一个视频上? [英] FFmpeg - Overlay one video onto another video?

查看:117
本文介绍了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).
      • 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)

      这篇关于FFmpeg - 将一个视频叠加到另一个视频上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆