windows 上的 ffmpeg 网络摄像头流到 sdl

ffmpeg webcam stream on windows to sdl

您好,我正在尝试在 windows 上显示网络摄像头流。

我可以使用“ffplay”,但我想使用“ffmpeg”命令。

c:\>ffmpeg -f dshow -i video="USB2.0 VGA UVC WebCam" -f sdl test
ffmpeg version 2020-12-27-git-bff6fbead8-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 10.2.0 (Rev5, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 62.100 / 56. 62.100
  libavcodec     58.115.102 / 58.115.102
  libavformat    58. 65.100 / 58. 65.100
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 94.100 /  7. 94.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, dshow, from 'video=USB2.0 VGA UVC WebCam':
  Duration: N/A, start: 92136.240000, bitrate: N/A
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422, 640x480, 30 fps, 30 tbr, 10000k tbn, 10000k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Output #0, sdl,sdl2, to 'test':
  Metadata:
    encoder         : Lavf58.65.100
    Stream #0:0: Video: rawvideo (YUY2 / 0x32595559), yuyv422(progressive), 640x480, q=2-31, 147456 kb/s, 30 fps, 30 tbn
    Metadata:
      encoder         : Lavc58.115.102 rawvideo
av_interleaved_write_frame(): Operation not permitted
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.03 bitrate=N/A speed=0.448x
video:600kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

下面的工作虽然:

ffmpeg -i file.webm -f sdl test

知道失败的原因吗?

添加 format 滤镜以输出不同的像素格式:

ffmpeg -f dshow -i video="USB2.0 VGA UVC WebCam" -vf format=yuv420p -f sdl test

虽然 yuyv422 和 uyvy422 在 libavdevice/sdl2.c 中的 sdl_texture_format_map[] 中列出,但不确定为什么它们不起作用。否则它应该输出 Unsupported pixel format 错误。