[MEncoder-users] Problem encoding raw video output of mencoder

Bram bram at mencoder.as.avontuur.org
Tue May 20 11:04:58 CEST 2008


R.L. Horn wrote:
> On Mon, 19 May 2008, Bram wrote:
> 
> > With this patch applied to the latest svn revision (26838), I tried to
> > transcode video using pipes. This results in a transcoded video stream,
> > but the horizontal alignment of the result is wrong:
> 
> > # start consumer of video pipe first
> > mencoder /tmp/videopipe -o "$OUT" -ofps 25 -noaspect -demuxer rawvideo 
> > -rawvideo fps=25:w=${WIDTH}:h=${HEIGHT}:format=i420 -nosound -ovc xvid 
> > -xvidencopts bitrate=800 &
> >
> > # demux video stream to named pipe
> > mencoder -quiet -of rawvideo -ovc raw -rawvidopts pipe=6 -ofps 25 -vf 
> > harddup,format=i420 -nosound "$IN" -o NUL 6>/tmp/videopipe
> >
> > wait # waits for encoder background job to complete
> 
> The only thing that stood out when I glanced through the patch is that 
> you're not checking the results of write() calls.  Since the I/O 
> primitives are interruptable, this can lead to incomplete writes.
> 
That is not pretty indeed. I'm not sure if such interrupts can occur
within mencoder (which do not result in program termination which would
be detected). 

It's not the source of this problem though. I've taken the patch almost
as-is from the mediacoder project without actually looking at it, as it
seems to work for that project. I only selected the bits necessary for
the pipes to work.

Taking a good look at the patch, it seems that this is the culprit:

+       if (pipefd)      {
+               YUV_INFO yuv_info = {
+                       0,
+                       mux_v->bih->biWidth,
+                       mux_v->bih->biHeight,
+                       'p',
+                       mux_v->h.dwRate,
+                       mux_v->h.dwScale,
+                       pixelaspect.num, pixelaspect.den,
+                       0
+               };
+               int len = sizeof(yuv_info);
+               write(pipefd, &len, sizeof(len));
+               write(pipefd, &yuv_info, len);

Not being an expert on raw video formats, I figured this header was used
by mencoder to determine the raw video properties, but it appears not to
be the case (so it really expects just raw data). If I skip 40 bytes in
the resulting raw video stream (size of the header + the prefixed header
length), the raw video stream appears to be correct. E.g.:

dd if=rawstream bs=40 skip=1 | mplayer -demuxer rawvideo -rawvideo fps=25:w=720:h=576:format=i420 -

> But why patch mencoder to accomplish the above anyway?  It's perfectly 
> capable of writing to a named pipe using "-o" unless something has changed 
> since SVN 26759.
>
Mainly for outputting audio streams only; I couldn't figure out how to
get mencoder to just decode audio without video. Now I can using this:

mencoder -quiet -oac pcm -pcmopts pipe=5 -ovc frameno -of rawvideo -aid 1 -af channels=2 -o NUL input.avi 5> audiopipe

I can't get at just the audiostream without the patch. Is it possible?

Kind regards,
Bram



More information about the MEncoder-users mailing list