ffmpeg 水平翻转网络摄像头到虚拟摄像机

标签 ffmpeg webcam flip v4l2 v4l2loopback

我需要水平翻转我的网络摄像头图像以进行 session 。
我尝试了本网站 https://wiki.archlinux.org/index.php/Webcam_setup#Applications 中的说明,它使用 v4l2 和 v4l2loopback 生成虚拟相机。

# modprobe v4l2loopback
检查新创建的相机的名称:
$ v4l2-ctl --list-devices

Dummy video device (0x0000) (platform:v4l2loopback-000):
       /dev/video1
然后,您可以运行 ffmpeg 从您的实际网络摄像头(此处为/dev/video0)中读取数据并将其反转并将其馈送到虚拟摄像头:
$ ffmpeg -f v4l2 -i /dev/video0 -vf "vflip" -f v4l2 /dev/video1
您可以在应用程序中使用“虚拟”相机而不是“集成”相机。
通过这些设置,我成功地垂直翻转了我的视频。但这不是我想要的。我希望它水平翻转。
所以我尝试了这个:
$ ffmpeg -f v4l2 -i /dev/video0 -vf **"hflip"** -f v4l2 /dev/video1
但是我没有从我的摄像头中得到任何图像。
我究竟做错了什么?
我在桌面上使用 Fedora 31。
完整的日志:
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers

  built with gcc 9 (GCC)

  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect

  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

Input #0, video4linux2,v4l2, from '/dev/video0':

  Duration: N/A, start: 233168.222502, bitrate: 147456 kb/s

    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 147456 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc

Stream mapping:

  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))

Press [q] to stop, [?] for help

Output #0, video4linux2,v4l2, to '/dev/video2':

  Metadata:

    encoder         : Lavf58.29.100

    Stream #0:0: Video: rawvideo (Y42B / 0x42323459), yuv422p, 640x480, q=2-31, 147456 kb/s, 30 fps, 30 tbn, 30 tbc

    Metadata:

    encoder         : Lavc58.54.100 rawvideo

frame=   31 fps=0.0 q=-0.0 size=N/A time=00:00:01.03 bitrate=N/A dup=16 drop=0 sframe=   46 fps= 46 q=-0.0 size=N/A time=00:00:01.53 bitrate=N/A dup=16 drop=0 sframe=   61 fps= 40 q=-0.0 size=N/A time=00:00:02.03 bitrate=N/A .....

最佳答案

在它到达 ffmpeg 之前修复它
您可以使用 v4l2-ctl to flip the video at the driver level所以这是正确的开始方向。
或者直接使用 ffmpeg使用 hflipvflip过滤器:

ffmpeg -f v4l2 -i /dev/video0 -vf "hflip,format=yuv420p" -f v4l2 /dev/video1
format=yuv420p需要避免 Unknown V4L2 pixel format equivalent错误。
欲了解更多信息,请参阅 How to use ffmpeg to send video to /dev/video*?

关于ffmpeg 水平翻转网络摄像头到虚拟摄像机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61485726/

相关文章:

c++ - 从 ffmpeg 1.1 升级到 3.3 后没有帧解码

opencv - 查找从相机到已知大小物体的距离

javascript - 在 Canvas 中翻转 Sprite

matlab - 使用 Matlab 对 3D 矩阵的左右翻转进行矢量化

qt - 如何通过 id 使用 ffmpeg 记录窗口?

ffmpeg - 使用 Android NDK 从 OGG 音乐文件中提取原始音频帧

c# - 从使用 Nreco 的视频 GetThumbnail 的 URL

c++ - VideoCapture dosnt 从网络摄像头读取 openCV2.4.0 linux

JavaCV Canvas 保持空白

javascript - 如何限制对元素的点击