使用视频环回设备伪造网络摄像头?

isu*_*dor 18 video webcam 12.04

我想在 Google+ 环聊中使用循环视频剪辑作为我的网络摄像头源。我安装了 v4l2loopback 并创建了一个视频环回设备。但我还没有弄清楚如何将视频帧写入设备。给定的例子是:

gst-launch videotestsrc ! v4l2sink device=/dev/video1
Run Code Online (Sandbox Code Playgroud)

因此,在阅读了 gst-launch 的手册页并试图了解发生了什么之后,我做出了无力的尝试:

sudo gst-launch-0.10 filesrc location=/home/briankb/Videos/darthvaderdancing.mp4 ! v4l2sink device=/dev/video0
Run Code Online (Sandbox Code Playgroud)

这导致:

Setting pipeline to PAUSED ...
libv4l2: error getting pixformat: Invalid argument
Pipeline is PREROLLING ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...

(gst-launch-0.10:12622): GStreamer-CRITICAL **: gst_caps_get_structure: assertion `GST_IS_CAPS (caps)' failed
New clock: GstSystemClock

(gst-launch-0.10:12622): GStreamer-CRITICAL **: gst_structure_get_name: assertion `structure != NULL' failed
Caught SIGSEGV accessing address (nil)
#0  0x00007fc1890f0b03 in poll () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007fc18962bff6 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#2  0x00007fc18962c45a in g_main_loop_run ()
#3  0x00007fc189b5c4cb in gst_bus_poll ()
#4  0x0000000000404587 in ?? ()
#5  0x0000000000403c34 in ?? ()
#6  0x00007fc18902b76d in __libc_start_main ()
#7  0x00000000004043bd in ?? ()
#8  0x00007fff88253ed8 in ?? ()
#9  0x000000000000001c in ?? ()
#10 0x0000000000000006 in ?? ()
#11 0x00007fff882548c4 in ?? ()
#12 0x00007fff882548d4 in ?? ()
#13 0x00007fff882548dc in ?? ()
#14 0x00007fff88254904 in ?? ()
#15 0x00007fff88254906 in ?? ()
#16 0x00007fff8825490f in ?? ()
#17 0x0000000000000000 in ?? ()
Spinning.  Please run 'gdb gst-launch 12622' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.
Run Code Online (Sandbox Code Playgroud)

我尝试使用 29.97 fps、320x240 和 mp4 容器(来自 Youtube)的 h264 视频的剪辑。

小智 12

gst-launch手册页告诉我们,我们需要将视频解码第一,和这样做的最简单的方法是这样的:

gst-launch-0.10 filesrc location=[location] ! decodebin ! v4l2sink device=/dev/video0
Run Code Online (Sandbox Code Playgroud)

gst-launch不需要以root身份运行,也[location]可以是相对的!


eri*_*rik 11

只需将v4l2loopback 与 mplayer 一起使用

  1. 下载它,
  2. 编译它(makesu -c 'make install'),
  3. 加载模块su -c 'modprobe v4l2loopback'
  4. 然后examples/yuv4mpeg_to_v4l2.c将 v4l2loopback 源文件夹的文件中的一行从

    v.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
    
    Run Code Online (Sandbox Code Playgroud)

    v.fmt.pix.pixelformat = V4L2_PIX_FMT_YVU420;
    
    Run Code Online (Sandbox Code Playgroud)
  5. make在此文件夹中执行。

  6. 然后examples像这样从目录运行它:

    mkfifo /tmp/pipe  # only needed once, as long as you do not delete the file /tmp/pipe
    ./yuv4mpeg_to_v4l2 < /tmp/pipe &
    mplayer movie.mp4 -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe
    
    Run Code Online (Sandbox Code Playgroud)

    movie.mp4可以在其中替换为视频文件的名称。并替换/dev/video0为您的环回设备。

MPlayer 能够播放任何网络流、所有类型的视频文件等。我刚刚使用来自德国新闻网站http://www.tagesschau.de的文件对其进行了测试。

TS=$(wget 'http://www.tagesschau.de'$(wget http://www.tagesschau.de -q -O - | grep 'Letzte Sendung' | sed -e 's%.*href="%%' -e 's%".*%%') -q -O - | grep '\.webm\.webm' | sed -e 's%.*href="%%' -e 's%\.webm\.webm".*%.webm.webm%')
./yuv4mpeg_to_v4l2 < /tmp/pipe &
mplayer $TS -vf scale=480:360 -vo yuv4mpeg:file=/tmp/pipe
Run Code Online (Sandbox Code Playgroud)

  • @kkron:逐个字符比较两行(前后),您会注意到差异。;-) 提示:YUV 和 YVU。 (2认同)