[gst-devel] Transcoding with gstreamer

Ronald S. Bultje rbultje at ronald.bitfreak.net
Sat Nov 27 13:22:34 CET 2004


Hi David,

lots of questions in one email. Let's go oevr them one by one. Try to do
this in separate emails for legibility.

On Fri, 2004-11-26 at 16:54, David Given wrote:
> (Incidentally, various typos in the gst-launch command line can result in 
> strange crashes --- anyone interested?)

The gst-launch parser isn't supposed to be robust really. It's a
developer's tool, not an end user solution. If you think they're easily
fixable, sure, submit them, but I don't thin too many of us are dying to
make gst-launch the best tool of the world. ;).

> Trying to use gstreamer to repackage an mpeg file as an avi, without actually 
> doing any transcoding, I've come up with this:
> 
> gst-launch \
>  filesrc location=infile.mpg ! ffdemux_mpeg name=demux \
>  avimux name=mux ! filesink location=out.avi \
>  { demux.video_0 ! queue ! mux.video_0 } \
>  { demux.audio_0 ! queue ! mux.audio_0 }
> 
> (Newlines inserted to make it more readable.)
> 
> Now, I would expect this to either (a) work or (b) fail if the video and audio 
> types aren't compatible. Instead it does (c), which is to hang. Any 
> suggestions as to why?

OK, that's very unrelated to the above. Yes, I know why. Your muxer and
demuxer run in the same thread, while separated by other threads in the
middle. This will hang. It's a bad pipeline. Like I said, gst-launch is
not an end-user solution. We don't check for all possible mistakes.
We're a building box, and I can build lego houses that will collapse
instantly with no problem. You see the point?

Let's see on how to fix this. You have four parts in that pipeline: 1 is
the reader+demuxer, one is the muxer+writer, one is the audio elementary
stream and one is the video elementary stream. You'll need 4-1 threads
(one part runs in the mainloop) for that. So let's start by the mainloop
part:

avimux name=m ! filesink location=file.avi

now let's do the demuxer part:

{ filesrc location=file.mpg ! mpegdemux name=d }

Those are simple. Now, for the parts in between, you'll need *two*
queues. Reason is simple: there's two elementary streams. Those need to
run in different threads. If you would use one thread for that, you'd
hang. So you need two threads in the middle. Since you need a queue per
thread change, you'll need a queue on both out- and input side. You can
put an identity in the middle to make it look better:

{ d.video_00 ! queue ! identity ! queue ! m.video_%d }

and

{ d.audio_00 ! queue ! identity ! queue ! m.audio_%d }

So the end then looks like this:

gst-launch avimux name=m ! filesink location=file.avi { filesrc
location=file.mpg ! mpegdemux name=d { d.video_00 ! queue ! identity !
queue ! m.video_%d } { d.audio_00 ! queue ! identity ! queue !
m.audio_%d } }

I've used that many times and it "works for me". Now replace the
identity by random other sequences of elements to do re-encoding, e.g.
"mpeg2dec ! ffmpegcolorspace ! divxenc" (to convert MPEG-2 to
MPEG-4/DivX) and "mad ! audioconvert ! lame" (to convert mp2 to mp3).

Ronald

-- 
Ronald S. Bultje <rbultje at ronald.bitfreak.net>





More information about the gstreamer-devel mailing list