简体   繁体   English

Stream static 图像到 v4l2loopback 使用带有 v4l2 插件、ffmpeg 或 gstreamer 的 obs

[英]Stream static image to v4l2loopback using obs with v4l2 plugin, ffmpeg or gstreamer

I want to stream a static image to the android studio emulator.我想将 stream 一个 static 图像发送到 android 工作室模拟器。 To do that I created a virtual camera using v4l2loopback v.12.5 in linux ubuntu 20.04.为此,我在 linux ubuntu 20.04 中使用 v4l2loopback v.12.5 创建了一个虚拟相机。 The virtual camera is created in /dev/video2.虚拟摄像机在 /dev/video2 中创建。 I can stream there using obs and a plugin, ffmpeg or gstreamer but I've got different issues with each one.我可以使用 obs 和插件 ffmpeg 或 gstreamer 在那里 stream ,但每个人都有不同的问题。 I don't care which software works... I always use an image with the resolution 1920x1080 to test this.我不在乎哪个软件可以工作……我总是使用分辨率为 1920x1080 的图像来测试它。

OBS: I installed the obs plugin following this tutorial here . OBS:我在这里按照本教程安装了 obs 插件。 It explains how to install v4l2loopback and add the plugin to obs.它解释了如何安装 v4l2loopback 并将插件添加到 obs。 The plugin is called obs-v4l2sink.该插件名为 obs-v4l2sink。 I start v4l2loopback using this command:我使用以下命令启动 v4l2loopback:

sudo modprobe v4l2loopback exclusive_caps=1 video_nr=2 card_label=virtualCam

and then:接着:

v4l2loopback-ctl set-caps "video/x-raw, format=NV12, width=1920, height=1080" "/dev/video2"

Then I start Obs with the base canvas 1920x1080 and output 1920x1080 too.然后我也用基础 canvas 1920x1080 和 output 1920x1080 启动 Obs。 In the plugin I choose NV12 as the video format and /dev/video2 as the V4L2 Device.在插件中,我选择 NV12 作为视频格式,/dev/video2 作为 V4L2 设备。 The image is successfully sent to the emulator but the resolution is wrong.图像成功发送到模拟器,但分辨率错误。 Using ffplay I get this message:使用 ffplay 我收到此消息:

"Input #0, video4linux2,v4l2, from '/dev/video2':B sq= 0B f=0/0 Duration: N/A, start: 1650.347834, bitrate: 27648 kb/s Stream #0:0: Video: rawvideo (NV12 / 0x3231564E), nv12, 320x240, 27648 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc" “输入#0,video4linux2,v4l2,来自'/dev/video2':B sq= 0B f=0/0 持续时间:N/A,开始:1650.347834,比特率:27648 kb/s Stream #0:0:视频: rawvideo (NV12 / 0x3231564E), nv12, 320x240, 27648 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc"

It seems, that the resolution is scaled down to 320x240 and I have no clue why.看来,分辨率缩小到 320x240,我不知道为什么。

ffmpeg: I can stream to /dev/video2 with ffmpeg using this command: ffmpeg:我可以 stream 使用 ffmpeg 到 /dev/video2 使用此命令:

ffmpeg -re loop 1 -i licensePlate.png -f v4l2 /dev/video2 

But I only get wrong pixels in ffplay, which outputs this:但我在 ffplay 中只得到错误的像素,输出如下:

[video4linux2, v4l2 @ 0x7fb494000bc0] Dequeued v4l2 buffer contains 118784 bytes, but 115200 were expected. [video4linux2, v4l2 @ 0x7fb494000bc0] 出队的 v4l2 缓冲区包含 118784 字节,但预期为 115200。 Flags: 0x00000001.标志:0x00000001。

Gstreamer: Gstreamer only works if I don't use the following command after the modprobe (If I use it, the pipeline is blocked for Gstreamer): Gstreamer: Gstreamer 仅在我在 modprobe 之后不使用以下命令时才有效(如果我使用它,则管道被 Gstreamer 阻塞):

v4l2loopback-ctl set-caps "video/x-raw, format=NV12, width=1920, height=1080" "/dev/video2"

Instead I call this command:相反,我调用这个命令:

gst-launch-1.0 -v multifilesrc location=licensePlate2.png loop=1 caps="image/png,framerate=10/1" ! pngdec ! videoscale ! videoconvert ! "video/x-raw,format=NV12,width=1920,height=1080" ! v4l2sink device=/-dev/video2

Using ffplay I see the image I desire in 1920x1080 and everything seems fine, but in the android studio emulator I only get a weird greenscreen.使用 ffplay 我在 1920x1080 中看到了我想要的图像,一切似乎都很好,但在 android 工作室模拟器中,我只得到一个奇怪的绿屏。 I got this greenscreen before and I think it has got something to do with a wrong resolution.我之前得到了这个绿屏,我认为它与错误的分辨率有关。 I don't really know what is wrong here.我真的不知道这里有什么问题。 The emulator shows these logs many times:模拟器多次显示这些日志:

 emulator: ERROR: camera_device_start_capturing: Dimensions 0x0 are wrong for pixel format NV12 emulator: ERROR: _camera_client_start: Cannot start camera '/dev/video2' for NV12[0x0]: Inappropriate ioctl for device

The avd I'm using is Pixel2 1920x1080 Android 11 x86 64 and I'm starting it using this command:我正在使用的 avd 是 Pixel2 1920x1080 Android 11 x86 64 ,我正在使用以下命令启动它:

./emulator -avd Pixel264 -camera-back webcam1 -no-snapshot
Pixel264 is my avd and webcam1 is the virtual webcam, that is linked to /dev/video2

I just tried it with Android Studio Emulator API 28 (Google X86_ARM) and it works.我刚刚用 Android Studio Emulator API 28 (Google X86_ARM) 试了一下,它可以工作。 So it seems that it is related to the CPU Architecture of the emulator and x86 64 does not work.所以看起来它与模拟器的CPU架构有关,x86 64 不起作用。 I needed arm though and thankfully Google added Arm translation to an image in Api 28.不过,我需要 arm,谢天谢地,谷歌在 Api 28 中添加了 Arm 对图像的翻译。

It seems that only images with resolution 1920x1080 work, but maybe it is only related to the ratio.似乎只有分辨率为 1920x1080 的图像才有效,但可能只与比例有关。

Obs does not work now for some reason but this command works perfectly: ffmpeg -loop 1 -re -i licensePlate2.png -f v4l2 -vcodec rawvideo -pixfmt nv12 -vf transpose=4 /dev/video2由于某种原因,Obs 现在无法正常工作,但此命令可以正常工作: ffmpeg -loop 1 -re -i licensePlate2.png -f v4l2 -vcodec rawvideo -pixfmt nv12 -vf transpose=4 /dev/video2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM