以编程方式并排合并两个视频

问题描述 投票:2回答:2

我需要并排合并两个avi视频,并且我成功使用python + gstreamer进行了如下代码。

pipe = """
videomixer2 name=mix background=1 
  sink_0::xpos=0 sink_0::ypos=60 sink_0::zorder=0 
  sink_1::xpos=640 sink_1::ypos=60 sink_1::zorder=0 !
ffmpegcolorspace name=colorsp_saida ! 
video/x-raw-yuv, format=(fourcc)I420, width=1280, height=480, framerate=25/1 ! 
x264enc quantizer=45 speed-preset=6 profile=1 ! queue ! 
mp4mux name=mux  ! queue ! filesink location="output.mp4"

filesrc location="video1.avi" ! decodebin2 name=dbvideo1 ! 
aspectratiocrop aspect-ratio=16/9 ! videoscale ! videorate ! 
ffmpegcolorspace name=colorsp_video1 ! 
video/x-raw-yuv, format=(fourcc)AYUV, framerate=25/1, width=640, height=360 ! 
mix.sink_0 

filesrc location="video2.avi" ! decodebin2 name=dbvideo2 ! 
aspectratiocrop aspect-ratio=16/9 ! videoscale ! videorate ! 
ffmpegcolorspace name=colorsp_video2 ! 
video/x-raw-yuv, format=(fourcc)AYUV, framerate=25/1, width=640, height=360 ! 
mix.sink_1 
"""

import gst
pipeline = gst.Pipeline()
bus = pipeline.get_bus()

gst_bin = gst.parse_bin_from_description(pipe, False)
pipeline.add(gst_bin)

pipeline.set_state(gst.STATE_PLAYING)
msg = bus.timed_pop_filtered(gst.CLOCK_TIME_NONE, gst.MESSAGE_ERROR | gst.MESSAGE_EOS)
pipeline.set_state(gst.STATE_NULL)

我正在使用ubuntu 12.04 LTS,python 2.7和gstreamer。

我有以下几个问题,

  • 当我使用较大的输入文件(持续时间超过30分钟)时,程序在挂载阶段挂起,但仍给出output.mp4。
  • 这非常慢,如果我转换30分钟,程序也会运行20 -25分钟
  • 两个输入文件可能有几秒钟(10-20秒)的时间间隔,这会成为问题吗?

如果我有任何其他方式可以合并和转换此文件,除了gstreamer以外,也可以接受。

UPDATE 1:

经过几天的工作,我发现程序挂在pipeline.set_state(gst.STATE_NULL)行上。任何人都有一个主意,如何克服这一点。

基本上,我需要释放管道资源而没有任何麻烦。

UPDATE 2:

我需要并排合并两个视频(avi)文件(两个文件都将有音频)并转换为MP4格式,这是这个问题的完整概念。我尝试使用gstreamer,然后卡在上面已经描述的地方。

python ubuntu-12.04 gstreamer
2个回答
2
投票

有效的ffmpeg代码,

./ffmpeg -i video1.avi -i video2.avi -r 30 -filter_complex "[0:v]scale=640:480, setpts=PTS-STARTPTS, pad=1280:720:0:120[left]; [1:v]scale=640:480, setpts=PTS-STARTPTS, pad=640:720:0:120[right]; [left][right]overlay=w; amerge,pan=stereo:c0<c0+c2:c1<c1+c3" -vcodec libx264 -acodec aac -strict experimental output.mp4

1
投票
© www.soinside.com 2019 - 2024. All rights reserved.