Reputation: 3844
I need to merge two avi videos side by side and I succeeded with python + gstreamer as below code.
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)
I am using ubuntu 12.04 LTS, python 2.7 and gstreamer.
I have few issues as below,
If I have any other way to merge and convert this files, other than gstreamer also acceptable.
UPDATE 1:
After few days of works I found that program get hang on pipeline.set_state(gst.STATE_NULL)
line. Anyone have an idea ,how to overcome this.
Basically I need to free the resources of pipeline without any trouble.
UPDATE 2:
I need to merge two video(avi) files(either file will have a audio) side by side and convert to MP4 format, is a whole idea of this question. I tried with gstreamer and stuck on a place that I have described in above.
Upvotes: 3
Views: 5914
Reputation: 3844
working ffmpeg
code,
./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
Upvotes: 2
Reputation: 587
I belive ffmpeg may be a bit faster, take a look at these links:
http://ffmpeg.org/pipermail/ffmpeg-user/2013-June/015662.html https://trac.ffmpeg.org/wiki/FilteringGuide#multipleinputoverlayin2x2grid
There is ffmpeg wrapper for python:
https://code.google.com/p/pyffmpeg/
Upvotes: 1