Skip to content
Akimoto-san edited this page Nov 15, 2014 · 7 revisions

playing back v4l2loopback devices using MPlayer

producer

again a dummy producer, using gstreamer
gst-launch -v videotestsrc ! "video/x-raw-yuv,width=640,height=360,framerate=30/1,format=(fourcc)I420" ! v4l2sink device=/dev/video1

consumer

minimal mplayer playback mplayer tv:// -tv device=/dev/video1

feeding the pipe with MPlayer's "v4l2" output module

It seems like MPlayer's "v4l2" output module is really only meant for MPEG-decoders. It doesn't support uncompressed video, which is what v4l2loopback is using.

feeding the pipe with MPlayer's "yuv4mpeg" output module

In order to feed the loopback device with MPlayer's "yuv4mpeg" output module, you will need an intermediate program, that pushes the yuv4mpeg stream into the v4l2 device. An example for such a module can be found in the examples/ directory; it's called yuv4mpeg_to_v4l2 and is courtesy by Eric Cooper.

producer

mkfifo /tmp/pipe
./yuv4mpeg_to_v4l2 < /tmp/pipe &
mplayer movie.mp4 -vo yuv4mpeg:file=/tmp/pipe

flash webcam

To make it work with flash webcam you have to change in the examples/yuv4mpeg_to_v4l2.c the line

v.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;

to

v.fmt.pix.pixelformat = V4L2_PIX_FMT_YVU420;

and then use the producer above (mplayer with yuv4mpeg) but with the scaling filter to 480:360 pixels. As a one liner:

videofile=movie.mp4; (yuv4mpeg_to_v4l2 /dev/video0 < /tmp/pipe & ); mplayer $videofile -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe

where you replace movie.mp4 with the name of your video file. And replace /dev/video0 with your loopback device.

This was mentioned in https://github.com/umlaeute/v4l2loopback/issues/8

debian 7

Another working solution. May solve problems with colorspace:

mkfifo /tmp/pipe

in first terminal: mplayer -vo yuv4mpeg:file=/tmp/pipe <file to play>

in second terminal: mencoder /tmp/pipe -nosound -noskip -ovc raw -vf scale=640:480,format=yuy2 -of rawvideo -rawvideo w=640:h=360:format=yuy2 -cache 8192 -o /dev/video0