1

I found the following question and tried to send a mp4 video to my camera: Is there any way ffmpeg send video to /dev/video0 on Ubuntu?

I used the following command:

ffmpeg -re -i fakezoom.mp4 -map 0:v -f h264 /dev/video0

According to Ubuntu, the file properties of the mp4 are H.264, 30 frames per second, 414kbps bitrate.

When I run the command, I get the following output:

ffmpeg -re -i fakezoom.mp4 -map 0:v -f h264 /dev/video0
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libaribb24 --enable-liblensfun --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56370afc9700] st: 0 edit list: 1 Missing key frame while searching for timestamp: 0
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x56370afc9700] st: 0 edit list 1 Cannot find an index entry before timestamp: 0.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'fakezoom.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2021-04-20T09:39:14.000000Z
    encoder         : vlc 3.0.9.2 stream output
    encoder-eng     : vlc 3.0.9.2 stream output
  Duration: 00:13:18.78, start: 0.000000, bitrate: 416 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, unknown/bt709/bt709), 1280x720 [SAR 1:1 DAR 16:9], 414 kb/s, 17.91 fps, 17.67 tbr, 90k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-04-20T09:39:14.000000Z
      handler_name    : VideoHandler
File '/dev/video0' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x56370afce880] using SAR=1/1B time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    
[libx264 @ 0x56370afce880] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x56370afce880] profile High, level 3.1
Output #0, h264, to '/dev/video0':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    encoder         : Lavf58.29.100
    Stream #0:0(eng): Video: h264 (libx264), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 17.67 fps, 17.67 tbn, 17.67 tbc (default)
    Metadata:
      creation_time   : 2021-04-20T09:39:14.000000Z
      handler_name    : VideoHandler
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
av_interleaved_write_frame(): Invalid argumente=00:00:02.88 bitrate= 665.2kbits/s dup=0 drop=1 speed=0.408x     
Error writing trailer of /dev/video0: Invalid argument
frame=  121 fps= 16 q=27.0 Lsize=     258kB time=00:00:03.22 bitrate= 654.2kbits/s dup=0 drop=1 speed=0.432x    
video:258kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
[libx264 @ 0x56370afce880] frame I:1     Avg QP:17.14  size: 45994
[libx264 @ 0x56370afce880] frame P:31    Avg QP:20.92  size:  9074
[libx264 @ 0x56370afce880] frame B:89    Avg QP:22.87  size:   853
[libx264 @ 0x56370afce880] consecutive B-frames:  0.8%  3.3%  0.0% 95.9%
[libx264 @ 0x56370afce880] mb I  I16..4:  7.1% 77.3% 15.7%
[libx264 @ 0x56370afce880] mb P  I16..4:  0.2%  2.1%  0.5%  P16..4: 18.5%  7.1%  3.1%  0.0%  0.0%    skip:68.4%
[libx264 @ 0x56370afce880] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8: 10.1%  0.4%  0.1%  direct: 0.3%  skip:89.1%  L0:48.1% L1:48.4% BI: 3.6%
[libx264 @ 0x56370afce880] 8x8 transform intra:76.2% inter:67.0%
[libx264 @ 0x56370afce880] coded y,uvDC,uvAC intra: 57.3% 80.2% 42.2% inter: 3.4% 5.5% 0.1%
[libx264 @ 0x56370afce880] i16 v,h,dc,p: 20% 15% 10% 55%
[libx264 @ 0x56370afce880] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 13% 12%  7%  9% 11%  7%  7%  6%
[libx264 @ 0x56370afce880] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 25% 18% 10%  6% 11% 11%  9%  6%  6%
[libx264 @ 0x56370afce880] i8c dc,h,v,p: 46% 20% 21% 13%
[libx264 @ 0x56370afce880] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x56370afce880] ref P L0: 56.5% 16.3% 20.0%  7.2%
[libx264 @ 0x56370afce880] ref B L0: 75.3% 20.1%  4.6%
[libx264 @ 0x56370afce880] ref B L1: 98.8%  1.2%
[libx264 @ 0x56370afce880] kb/s:470.92
Conversion failed!

It ends with a conversation failed but also includes some other weird messages like

av_interleaved_write_frame(): Invalid argumente=00:00:02.88 bitrate= 665.2kbits/s dup=0 drop=1 speed=0.408x     
Error writing trailer of /dev/video0: Invalid argument

Is there anything I am doing wrong?

v4l2-ctl --list-devices

outputs:

OBS Video Source (platform:v4l2loopback-000):
    /dev/video10

UVC Camera (046d:081b) (usb-0000:02:00.0-5): /dev/video0 /dev/video1

It might be because of the loopback I am using there? I sometimes use a programme which maps /dev/video0 to video10 to simulate a greenscreen and add a virtual background when I want to use my camera the proper way.

Does anybody know how to solve that?

Hemmelig
  • 319
  • 2
  • 9

1 Answers1

2

The answer you linked to shows how to make a "fake camera". So the video of your choice can be directed to a /dev/video* that is not already being used by an actual device.

There should be no need to feed a video to an existing device. These devices only output video, so I doubt you can feed an arbitrary video to a camera anyway.

When you run sudo modprobe v4l2loopback it should make a new /dev/video using an ID number that is not currently in use (such as /dev/video2). Then run:

ffmpeg -re -i fakezoom.mp4 -map 0:v -f v4l2 /dev/video2

Note the change of -f h264 as in your question to -f v4l2.

llogan
  • 11,868