ffmpeg 流 Windows 7 桌面到 Youtube 给出无效参数

ffmpeg stream Windows 7 desktop to Youtube give invalid argument

我正在尝试将我的 Windows 7 桌面直播到 YouTube。

首先是设备列表:

ffmpeg-N-100616-gca21cb1e36-win64-gpl\bin\ffmpeg.exe -list_devices true -f dshow -i dummy

给出:

ffmpeg version N-100616-gca21cb1e36 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9.3-win32 (GCC) 20200320
  configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --a
rch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv
--enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-open
cl --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-li
bdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-li
bopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --en
able-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-
libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-li
bxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
  libavutil      56. 63.100 / 56. 63.100
  libavcodec     58.116.100 / 58.116.100
  libavformat    58. 65.101 / 58. 65.101
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 95.100 /  7. 95.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
[dshow @ 000000000052ca00] DirectShow video devices (some may be both video and audio devices)
[dshow @ 000000000052ca00]  "VF0700 Live! Cam Chat HD"
[dshow @ 000000000052ca00]     Alternative name "@device_pnp_\?\usb#vid_041e&pid_4088&mi_00#7&b015b04&0&0000#{65e8773d-8f56-11d0-a3
b9-00a0c9223196}\global"
[dshow @ 000000000052ca00]  "UScreenCapture"
[dshow @ 000000000052ca00]     Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\UScreenCapture"
[dshow @ 000000000052ca00]  "screen-capture-recorder"
[dshow @ 000000000052ca00]     Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{4EA69364-2C8A-4AE6-A561-56E4B504
4439}"
[dshow @ 000000000052ca00] DirectShow audio devices
[dshow @ 000000000052ca00]  "Microphone (VF0700 Live! Cam Ch"
[dshow @ 000000000052ca00]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Microphone (VF0700 Live! Cam Ch"
[dshow @ 000000000052ca00]  "virtual-audio-capturer"
[dshow @ 000000000052ca00]     Alternative name "@device_sw_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\{8E146464-DB61-4309-AFA1-3578E927
E935}"
dummy: Immediate exit requested

ffmpeg-N-100616-gca21cb1e36-win64-gpl\bin\ffmpeg.exe -list_devices true -f dshow -i dummy

给出:

ffmpeg version 4.3.1-2021-01-01-full_build-www.gyan.dev Copyright (c) 2000-2021 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 --enab
le-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libss
h --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-li
brav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --en
able-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-libm
fx --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. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
[dshow @ 0000000000485ac0] DirectShow video devices (some may be both video and audio devices)
[dshow @ 0000000000485ac0]  "VF0700 Live! Cam Chat HD"
[dshow @ 0000000000485ac0]     Alternative name "@device_pnp_\?\usb#vid_041e&pid_4088&mi_00#7&b015b04&0&0000#{65e8773d-8f56-11d0-a3
b9-00a0c9223196}\global"
[dshow @ 0000000000485ac0]  "UScreenCapture"
[dshow @ 0000000000485ac0]     Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\UScreenCapture"
[dshow @ 0000000000485ac0]  "screen-capture-recorder"
[dshow @ 0000000000485ac0]     Alternative name "@device_sw_{860BB310-5D01-11D0-BD3B-00A0C911CE86}\{4EA69364-2C8A-4AE6-A561-56E4B504
4439}"
[dshow @ 0000000000485ac0] DirectShow audio devices
[dshow @ 0000000000485ac0]  "Microphone (VF0700 Live! Cam Ch"
[dshow @ 0000000000485ac0]     Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Microphone (VF0700 Live! Cam Ch"
[dshow @ 0000000000485ac0]  "virtual-audio-capturer"
[dshow @ 0000000000485ac0]     Alternative name "@device_sw_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\{8E146464-DB61-4309-AFA1-3578E927
E935}"
dummy: Immediate exit requested

现在尝试使用以下命令进行直播:

ffmpeg-N-100616-gca21cb1e36-win64-gpl\bin\ffmpeg.exe -f dshow -i video='screen-capture-recorder':audio='Microphone (VF0700 Live! Cam Ch' -r 24 -s 1920x1080 -qmin 3 'rtmp://a.rtmp.youtube.com:1935/live2/the-stream-key'

我得到:

ffmpeg version 4.3.1-2021-01-01-full_build-www.gyan.dev Copyright (c) 2000-2021 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 --enab
le-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libss
h --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-li
brav1e --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --en
able-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-libm
fx --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. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
leaving aero onGuessed Channel Layout for Input Stream #0.1 : stereo
Input #0, dshow, from 'video=screen-capture-recorder:audio=Microphone (VF0700 Live! Cam Ch':
  Duration: N/A, start: 758394.360000, bitrate: N/A
    Stream #0:0: Video: rawvideo, bgr0, 1920x1080, 30 fps, 30 tbr, 10000k tbn, 10000k tbc
    Stream #0:1: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
[NULL @ 00000000006645c0] Unable to find a suitable output format for 'rtmp://a.rtmp.youtube.com:1935/live2/the-stream-key
'
rtmp://a.rtmp.youtube.com:1935/live2/the-stream-key: Invalid argument
[dshow @ 0000000000607400] real-time buffer [screen-capture-recorder] [video input] too full or near too full (545% of size: 3041280
 [rtbufsize parameter])! frame dropped!
    Last message repeated 5 times

简而言之,错误是:

[NULL @ 00000000006645c0] Unable to find a suitable output format for 'rtmp://a.rtmp.youtube.com:1935/live2/the-stream-key
'
rtmp://a.rtmp.youtube.com:1935/live2/the-stream-key: Invalid argument
[dshow @ 0000000000607400] real-time buffer [screen-capture-recorder] [video input] too full or near too full (545% of size: 3041280

我试过使用和不使用 :1935 端口号,使用 ffmpeg_x64.exe 但没有区别。流密钥是 invalid argument 还是其他?

想通了。 -f 参数用于指定输入格式 dshow,但如果放置在输入和输出之前,此参数也是位置相关的,适用于输入 and/or 输出格式。

所以解决方案是将 -f flv 也添加到输出中:

ffmpeg-N-100616-gca21cb1e36-win64-gpl\bin\ffmpeg.exe -f dshow -i video='screen-capture-recorder':audio='Microphone (VF0700 Live! Cam Ch' -r 24 -s 1920x1080 -qmin 3 -f flv 'rtmp://a.rtmp.youtube.com:1935/live2/the-stream-key'

所以,我们说输入格式是 dshow 放在 -i 标志之前,输出是 flv 放在输出之前(流通道).