[FFmpeg-user] Capturing audio + video from mplayer

Oliver Fromme oliver at fromme.com
Wed Jul 23 19:13:11 CEST 2014


Jason Gullickson wrote:
 > [...]
 > mplayer dvdnav:////dev/dvd -ao pcm:file=audio.wav -vo
 > yuv4mpeg:file=video.y4m -slave
 > 
 > ffmpeg -i audio.wav -f yuv4mpegpipe -i video.y4m -vcodec mpeg2video
 > -me_method epzs -threads 4 -r 29.97 -g 45 -b 2500k -bt 300
 > http://localhost:8090/dvdfeed.ffm
 > 
 > Normally when I do the video-only set of commands ffmpeg starts spewing
 > data about the transcoding process (fps, etc.).  When I add audio as shown
 > above, ffmpeg starts but then stops displaying output after it shows it's
 > configuration parameters and never gets to the transcoding status output
 > stage, like it's waiting for input.

Using two (or more) named pipes between two different programs
almost never works, because the pipes are not read and written
at the same speed, so sooner or later (rather sooner) a deadlock
occurs.

In this case, for example, mplayer may write a frame of video
data to the video pipe.  This write will block because the size
of a raw yuv4m frame at DVD resolution is about 800 KB for PAL
or 700 KB for NTSC, which is much more than the typical buffer
size of a named pipe (between 8 and 64 KB, depending on the OS).
That means that the writing process will block until the reading
process has read the data.  However, at the same time, ffmpeg
may choose to read from the audio pipe first.  Since no data
is available from that pipe yet, the ffmpeg process will block,
too.

Things like that only work if at least one of the two programs
is prepared for such a situation.  It requires buffering the
data and handling both pipes asynchronously.  I don't think
ffmpeg does that, and mplayer doesn't do that either.

You could try to decouple the programs by using a buffering tool
in between.  There are several such tools, for example this one
called "sob":

http://www.secnetix.de/olli/software/sob/

The setup would be like this:

mplayer --> pipe --> buffer (e.g. sob) --> pipe --> ffmpeg

Of course you need to do that twice, once for the video stream
and once for the audio stream.  Usage for "sob" is simple, e.g.
for a 20 MB buffer:

sob -q -i input_pipe -o output_pipe -b 20M

For the video pipe I'd start with a buffer size of 20 MB, that
would be roughly 1 s of raw yuv4m video at DVD resolution.
For PCM stereo audio, 1 MB should be sufficient.

Best regards
   Oliver


-- 
``We are all but compressed light'' (Albert Einstein)

Donations: http://www.amazon.de/wishlist/A0LHFK68RV8S


More information about the ffmpeg-user mailing list