문제

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,

  • when I use bigger input files(duration more than 30 minutes) program is hang on lator stage, but still its giving the output.mp4.
  • this is very slow, if I convert 30 minutes, program also running for 20 -25 minutes
  • two input files may have few seconds(10-20 seconds) time gap, will it be the issue?

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.

도움이 되었습니까?

해결책

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

다른 팁

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top