我正在使用以下 FFMPEG 命令将桌面流式传输到 RTMP 端点:
ffmpeg.exe -report -fflags nobuffer -framerate 30 -use_wallclock_as_timestamps 1 -f gdigrab -thread_queue_size 256 -offset_x 0 -offset_y 136 -video_size 1280x720 -i desktop -c:v libx264 -c:a aac -b:v 1000k -vf "format=yuv420p" -g 60 -f flv -movflags faststart -crf 23 rtmp://75cw3w9g:[email protected]/app-D2TFw12x/dCs4YjV5 -f dshow -rtbufsize 200M -thread_queue_size 1024 -i "audio=CABLE Output (VB-Audio Virtual Cable)"
操作系统是Windows 10。
该命令按预期工作,但出乎意料的是,CPU 使用率和帧速率下降到非常低的水平,并且 RTMP 流明显中断。以下是发生情况的示例:
ffmpeg started on 2022-01-14 at 21:32:42
Report written to "ffmpeg-20220114-213242.log"
Log level: 48
ffmpeg version 2021-06-23-git-947122f111-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
built with gcc 10.3.0 (Rev2, 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-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --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 57. 0.100 / 57. 0.100
libavcodec 59. 1.102 / 59. 1.102
libavformat 59. 3.101 / 59. 3.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.102 / 8. 0.102
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
[gdigrab @ 000002547ea616c0] Capturing whole desktop as 1280x720x32 at (0,136)
[gdigrab @ 000002547ea616c0] Stream #0: not enough frames to estimate rate; consider increasing probesize
Input #0, gdigrab, from 'desktop':
Duration: N/A, start: 1642195962.552738, bitrate: 884748 kb/s
Stream #0:0: Video: bmp, bgra, 1280x720, 884748 kb/s, 30 fps, 1000k tbr, 1000k tbn
Guessed Channel Layout for Input Stream #1.0 : stereo
Input #1, dshow, from 'audio=CABLE Output (VB-Audio Virtual Cable)':
Duration: N/A, start: 1569.872000, bitrate: 1411 kb/s
Stream #1:0: Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s
[rtmp @ 000002540239b540] Ignoring unsupported var reason
Stream mapping:
Stream #0:0 -> #0:0 (bmp (native) -> h264 (libx264))
Stream #1:0 -> #0:1 (pcm_s16le (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000002547ead5fc0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 AVX512
[libx264 @ 000002547ead5fc0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 000002547ead5fc0] 264 - core 164 r3065 ae03d92 - H.264/MPEG-4 AVC codec - Copyleft 2003-2021 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=60 keyint_min=6 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, flv, to 'rtmp://75cw3w9g:[email protected]/app-D2TFw12x/dCs4YjV5':
Metadata:
encoder : Lavf59.3.101
Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuv420p(tv, progressive), 1280x720, q=2-31, 1000 kb/s, 30 fps, 1k tbn
Metadata:
encoder : Lavc59.1.102 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: N/A
Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc59.1.102 aac
frame= 1 fps=0.0 q=0.0 size= 0kB time=00:00:00.44 bitrate= 7.4kbits/s speed=9.33x
frame= 17 fps=0.0 q=0.0 size= 0kB time=00:00:00.44 bitrate= 7.4kbits/s speed=0.798x
frame= 32 fps= 30 q=0.0 size= 0kB time=00:00:00.44 bitrate= 7.4kbits/s speed=0.413x
frame= 46 fps= 29 q=0.0 size= 0kB time=00:00:00.44 bitrate= 7.4kbits/s dup=0 drop=1 speed=0.281x
frame= 57 fps= 28 q=29.0 size= 40kB time=00:00:02.63 bitrate= 124.9kbits/s dup=0 drop=1 speed=1.27x
frame= 64 fps= 24 q=29.0 size= 135kB time=00:00:02.96 bitrate= 374.3kbits/s dup=0 drop=1 speed=1.12x
frame= 76 fps= 23 q=29.0 size= 179kB time=00:00:03.44 bitrate= 425.3kbits/s dup=0 drop=1 speed=1.05x
frame= 82 fps= 22 q=29.0 size= 209kB time=00:00:03.96 bitrate= 432.2kbits/s dup=0 drop=1 speed=1.04x
frame= 85 fps= 18 q=29.0 size= 227kB time=00:00:03.96 bitrate= 470.3kbits/s dup=0 drop=1 speed=0.861x
frame= 87 fps= 16 q=29.0 size= 247kB time=00:00:03.96 bitrate= 510.9kbits/s dup=0 drop=1 speed=0.741x
frame= 92 fps= 16 q=29.0 size= 279kB time=00:00:03.96 bitrate= 576.8kbits/s dup=0 drop=1 speed=0.676x
frame= 94 fps= 14 q=29.0 size= 300kB time=00:00:03.96 bitrate= 620.6kbits/s dup=0 drop=1 speed=0.608x
frame= 104 fps= 15 q=29.0 size= 335kB time=00:00:04.44 bitrate= 616.9kbits/s dup=0 drop=1 speed=0.632x
frame= 108 fps= 14 q=29.0 size= 353kB time=00:00:04.44 bitrate= 649.7kbits/s dup=0 drop=1 speed=0.585x
frame= 114 fps= 14 q=29.0 size= 382kB time=00:00:04.95 bitrate= 630.4kbits/s dup=0 drop=1 speed=0.601x
frame= 118 fps= 10 q=29.0 size= 475kB time=00:00:04.95 bitrate= 784.8kbits/s dup=0 drop=1 speed=0.433x
frame= 124 fps=9.6 q=29.0 size= 490kB time=00:00:04.95 bitrate= 809.8kbits/s dup=0 drop=1 speed=0.385x
frame= 134 fps= 10 q=29.0 size= 525kB time=00:00:05.44 bitrate= 790.0kbits/s dup=0 drop=1 speed=0.407x
[gdigrab @ 000002547ea616c0] Thread message queue blocking; consider raising the thread_queue_size option (current value: 256)
frame= 143 fps= 10 q=29.0 size= 560kB time=00:00:05.95 bitrate= 770.5kbits/s dup=0 drop=1 speed=0.416x
frame= 150 fps= 10 q=29.0 size= 591kB time=00:00:05.95 bitrate= 812.3kbits/s dup=0 drop=1 speed=0.402x
frame= 156 fps= 10 q=29.0 size= 615kB time=00:00:06.44 bitrate= 781.6kbits/s dup=0 drop=1 speed=0.42x
frame= 162 fps= 10 q=27.0 size= 665kB time=00:00:06.44 bitrate= 845.0kbits/s dup=0 drop=1 speed=0.399x
frame= 167 fps=9.9 q=29.0 size= 686kB time=00:00:06.44 bitrate= 872.2kbits/s dup=0 drop=1 speed=0.384x
frame= 169 fps=9.6 q=29.0 size= 701kB time=00:00:06.95 bitrate= 826.2kbits/s dup=0 drop=1 speed=0.396x
frame= 171 fps=9.2 q=29.0 size= 721kB time=00:00:06.95 bitrate= 849.1kbits/s dup=0 drop=1 speed=0.373x
frame= 173 fps=8.8 q=29.0 size= 730kB time=00:00:06.95 bitrate= 860.1kbits/s dup=0 drop=1 speed=0.356x
frame= 178 fps=8.1 q=29.0 size= 821kB time=00:00:06.95 bitrate= 967.3kbits/s dup=0 drop=1 speed=0.316x
在这种情况下,问题发生在启动 ffmpeg 之后。在大多数情况下,这种情况发生在时间间隔非常不稳定以至于很难识别任何模式之后。例如,它可以顺利运行(恒定 30 fps)1 小时,然后突然 CPU 使用率和帧速率下降到非常低的水平,并且 RTMP 流明显中断。我可以提供您可能需要的任何其他信息。
有谁可以给我一些建议或意见吗?
谢谢。