[gst-devel] How to write a format convertor

Tony Houghton h at realh.co.uk
Mon Oct 11 20:06:47 CEST 2010


I want to learn how to write gstreamer applications and I thought I'd
start by writing a python script to convert some videos from H264 HD to
an AVI file containing "DivX" at a lower resolution. My pipeline would
have this structure
(imagine it on one line joined at the multiqueue):

                    /-> videoscale -> ffenc_mp4 ->
filesrc -> decodebin                             > multiqueue sinks ...
                    \-> audioconvert -> lame    ->


                    ->
... multiqueue srcs -> avimux -> filesink
                    ->

Everything seems to link OK with no error messages, but after setting
the pipeline state to PLAYING nothing happens, and if I try to query the
position I get a QueryError. I've tried all sorts of playing around,
replacing bits with fakesink elements etc and usually I get the same
"hanging" but can query the position (which returns 0 to the nearest
second). I found a setup where it appeared to progress correctly, but
not one that was actually doing anything useful. It was using a filesink
with a location of /dev/null, but if I set the location to a real file,
or even replaced it with a fakesink it hung again.

Would it be OK to post the entire script here? It's about 210 lines.

Next I tried the nearest equivalent I could manage with gst-launch in a
shell script:

#!/bin/sh

Size='width=544,height=304'
ScaleCaps="video/x-raw-rgb,${Size};video/x-raw-yuv,${Size}"

gst-launch-0.10 filesrc location="$1" ! decodebin name=decode \
    decode. ! videoscale ! "$ScaleCaps" ! \
        ffenc_mpeg4 bitrate=2200000 ! queue ! mux. \
    decode. ! audioconvert ! lame vbr=4 vbr-mean-bitrate=128 ! queue !
mux. \
    avimux name=mux ! filesink location="$2"

That sort of worked, but the audio is out of sync and also keeps
"dropping out" in totem (but plays smoothly in mplayer).

Another problem is that I didn't get the video bitrate I asked for; I
noticed the file was smaller than expected and mplayer reports the video
bitrate as 1518.6Kbps instead of 2200. I've noticed that happening with
other conversions I've done in the past with mencoder. Is that because
the ffmpeg encoder can only give the desired bitrate if you use 2
passes?

-- 
TH * http://www.realh.co.uk




More information about the gstreamer-devel mailing list