(没有可接受的答案)如何使用ffmpeg或opencv将2个重叠的视频合并为一个视频? [英] (no accepted answer) How to merge 2 overlapping videos into one video using ffmpeg or opencv?

查看:82
本文介绍了(没有可接受的答案)如何使用ffmpeg或opencv将2个重叠的视频合并为一个视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

合并两个视频很容易,已经被回答了两次.我有多个重叠的视频.视频可能与之前的视频重叠.这意味着如果视频1覆盖了1-5个时间轴,那么视频2可能会重叠1,并且覆盖3到8.按原样合并它们会导致1-5 | 3-8,而我只需要1-8.

Merging two videos is easy, been answered couple of times. What I have is multiple overlapping videos. A video might have overlaps with video before it. Meaning if video 1 covers 1-5 timeline then video 2 may overlap 1, and cover 3 to 8. Merging them as is would result in 1-5|3-8, when i need 1-8 only.

视频按字母顺序排序.

我一般的解决方案是...

My general idea of solution is...

  • 抓住视频的最后一帧
  • 如果是第一个视频,请继续
  • 如果它不是第一个视频,即2,逐帧搜索上一步中保存的帧
  • 如果到达当前视频的最后一帧,则没有重叠继续
  • 如果找到一个帧,则将第二个视频剪辑到该帧(包括该帧),然后转到下一个帧
  • 分析完所有视频后,将它们合并为一个视频.

我需要将其翻译为ffmpeg命令.如果是更好的工具,请使用opencv.

I need to translate this to ffmpeg commands. Or opencv if that's a better tool.

如果有更好的方法,我对此也很感兴趣.

If there is better way of doing that, I'm interested in that too.

推荐答案

对于ffmepg,您可以使用以下脚本.它测试了它.但是在时间上明智的做法是,您必须在视频中将此STARTPTS + 5更改为+25.我在这里输入5来测试合并是否正在发生.

for ffmepg you can use the script below. it tested it. But timing wise, you have to change of this STARTPTS+5 to +25 in your video. I put 5 here to test the merging is happening.

ffmpeg -i 2.mp4 -i 1.mp4 -filter_complex "[1]setpts=PTS-STARTPTS+5/TB[top];[0:0][top]overlay=enable='between(t\,10,15)'[out]" -shortest -map [out] -map 0:1        -pix_fmt yuv420p -c:a copy -c:v libx264 -crf 18 output1.mp4

限制这需要源足够长,这意味着您需要视频画布,然后使用此脚本将每个视频添加到画布中.

Limitation This one need the source to be long enough which means you need video canvas then use this script to add each video into the canvas.

并且在ffmpeg中没有完全自主的使用方式.

And there is no fully autonomous way of use it in ffmpeg.

你是对的.Opencv无法处理音频.需要第3方库支持才能同时运行.在此之前,我必须使用ROS从网络摄像头获取声音和视觉到机器人系统.然后,使用NLP处理声音以用于母语用户界面,并将视觉分别用于locozlaiton和制图.

You are right. Opencv cant deal with audio. need 3rd party library support to run concurrently. Before then I have to use ROS to get both sound and vision to the robot system from a webcam. The sound is then process with NLP for natual language user interface and vision is used separately for locozlaiton and mapping.

有一些走动的方式.

首先,您在本地窗口批处理上使用OpenCV模板匹配或图像差异.最小的错误位置将为您提供正确的位置A插入.就毫秒级而言,这应该是准确的.(如果错误总是很大,则意味着没有重叠并返回异常)

First, you use OpenCV template matching or image difference on a local window batch. The smallest error position will give you the correct location A to insert. This should be accurate in terms of mili-second level. (if error is always big, then it means there is no overlap and return exception)

第二,基于从opencv获得的正确位置.调用system.call以使用A参数作为输入来调用上述脚本以进行自动合并.

Second, based on the correct location obtained from opencv. call system.call to invoke the above script with A parameter as input to do auto merge.

取决于您的应用程序,如果您需要经常执行此操作,请将opencv python脚本编写为自动保险丝.如果每个月只有一次,那么用ffmepg手动完成就足够了

Depends on your application, if you need to do it frequently, write opencv python script to automatic fuse. If just once every month, do it manually with ffmepg is good enough

这篇关于(没有可接受的答案)如何使用ffmpeg或opencv将2个重叠的视频合并为一个视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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