Unable to get video via uvc_gadget to the host pc

I am trying to setup a raspberry pi board as a piping device which could receive video from a camera or any other source and pipe it to the host pc. I am following the tutorial mentioned here

I am able to successfully stream webcam video to the host pc. What I wanted to do was to use a video file instead of the stream from the webcam. In order to do that I did as follows

  • Created a dummy v4l2loopback device
  • Created uvc_gadget following the tutorial above

My setup looks like this

pi@raspberrypi:~ $ v4l2-ctl --list-devices fe980000.usb (gadget):
/dev/video1
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
mmal service 16.1 (platform:bcm2835-v4l2):
/dev/video0
Dummy video device (0x0000) (platform:v4l2loopback-000):
/dev/video2

Afterwards I was able to start uvc_gadget as follows

pi@raspberrypi:~ $ ~/uvc-gadget/uvc-gadget -d /dev/video2 -u /dev/video1 -r 1 -f 1
uvc device is fe980000.usb on bus gadget
uvc open succeeded, file descriptor = 3
control request (req 86 cs 02)
control request (req 86 cs 02)
streaming request (req 87 cs 01)
streaming request (req 01 cs 01)
setting probe control, length = 26
streaming request (req 81 cs 01)

Now when I tried to stream a video file to /dev/video2 I only got colored stripes on the host pc with the error no jpeg data found

pi@raspberrypi:~ $ ffmpeg -re -i file_example_MP4_480_1_5MG.mp4 -map 0:v -f v4l2 /dev/video2
ffmpeg version 4.1.4-1+rpt7~deb10u1 Copyright (c) 2000-2019 the FFmpeg developers

On host PC I checked which video devices were available to me

zain@zain-Creator-17M-A10SD:~$ v4l2-ctl --list-devices
Dummy video device (0x0000) (platform:v4l2loopback-000): /dev/video2
PI4 USB Device: UVC Camera (usb-0000:00:14.0-4): /dev/video0 /dev/video1

RPI4 was showing up as UVC camera.

I tried to read video device using ffplay but there was no stream only the error.

zain@zain-Creator-17M-A10SD:~$ ffplay /dev/video0
ffplay version 3.4.8-0ubuntu0.2 Copyright (c) 2003-2020 the FFmpeg developers built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04) configuration: --prefix=/usr --extra-version=0ubuntu0.2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat 57. 83.100 / 57. 83.100 libavdevice 57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc 54. 7.100 / 54. 7.100
[mjpeg @ 0x7fecf40020e0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40020e0] No JPEG data found in image= 0B f=0/0
[video4linux2,v4l2 @ 0x7fecf4000b80] decoding for stream 0 failed
[video4linux2,v4l2 @ 0x7fecf4000b80] Could not find codec parameters for stream 0 (Video: mjpeg, none(bt470bg/unknown/unknown), 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, video4linux2,v4l2, from '/dev/video0': Duration: N/A, start: 331989.158354, bitrate: N/A Stream #0:0: Video: mjpeg, none(bt470bg/unknown/unknown), 1280x720, 0.20 fps, 0.20 tbr, 1000k tbn, 1000k tbc
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image Last message repeated 2 times
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0
[mjpeg @ 0x7fecf40044c0] No JPEG data found in image= 0B f=0/0 

I get almost similar behavior if I create a gadget using g_webcam instead of configFS with the change that I get striped color lines instead of this error.

Would be thankful for any help. I am assuming there are some issues with the encoding.

1 Answer

Because uvc-gadget does not support your mp4 size.

ffmpeg -re -i /home/pi/test.mp4 -vf scale=640:480 -map 0:v -f v4l2 /dev/video0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like