我需要合并两个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)
我使用的是Ubuntu12.04LTS、Python2.7和gstreamer。在
我有以下几个问题
如果我有其他方法合并和转换这个文件,除了gstreamer也可以接受。在
更新1:
经过几天的工作,我发现程序挂在pipeline.set_state(gst.STATE_NULL)
行上。谁有办法,怎么克服这个问题。在
基本上我需要释放管道的资源,没有任何麻烦。在
更新2:
我需要合并两个视频(avi)文件(任何一个文件都会有音频)并排并转换成MP4格式,是这个问题的一个整体思路。我尝试了gstreamer,并坚持在上面描述的地方。在
工作
ffmpeg
代码我相信ffmpeg可能会快一点,看看这些链接:
http://ffmpeg.org/pipermail/ffmpeg-user/2013-June/015662.htmlhttps://trac.ffmpeg.org/wiki/FilteringGuide#multipleinputoverlayin2x2grid
有针对python的ffmpeg包装器:
https://code.google.com/p/pyffmpeg/
相关问题 更多 >
编程相关推荐