这是我正在使用的命令:
ffmpeg -fflags genpts+igndts+discardcorrupt+ignidx+nobuffer -rtsp_transport tcp -i rtsp://*************** -c:v copy -af aresample=async=1:min_hard_comp=0.100000:first_pts=0 -c:a aac -ar 44100 -b:a 128k -bsf:a aac_adtstoasc -f flv rtmp://a.rtmp.youtube.com/live2/***************
不幸的是,这有时会在音频中产生几毫秒的静音间隙和咔嗒声,我认为这与异步有关(增加异步值会使音频失真,使声音变得波浪形)。我用 audacity 录制了音频,向您展示我的意思:
最初我只是复制了音频流(-c:a copy),但 Youtube 端的声音却严重失真且不连贯。
我尝试了不同的参数,但都无法解决问题。有人知道是什么原因导致此行为吗?
日志:
ffmpeg version 4.3.1-2020-10-01-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10.2.0 (Rev3, 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-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-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
[tcp @ 000000000012ea80] Starting connection attempt to X.X.X.X port XXXX
[tcp @ 000000000012ea80] Successfully connected to X.X.X.X port XXXX
[rtsp @ 000000000012e300] SDP:
v=0
o=- 2251938195 2251938195 IN IP4 0.0.0.0
s=Media Server
c=IN IP4 0.0.0.0
t=0 0
a=control:*
a=packetization-supported:DH
a=rtppayload-supported:DH
a=range:npt=now-
m=video 0 RTP/AVP 96
a=control:trackID=0
a=framerate:12.000000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=42001F;sprop-parameter-sets=Z0IAH52oFAFum4CAgKAAAH0AAAu4EIAA,aM48gAA=
a=recvonly
m=audio 0 RTP/AVP 97
a=control:trackID=1
a=rtpmap:97 MPEG4-GENERIC/32000
a=fmtp:97 streamtype=5;profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1288
a=recvonly
[rtsp @ 000000000012e300] setting jitter buffer size to 0
Last message repeated 1 times
[h264 @ 0000000000133840] Reinit context to 1280x720, pix_fmt: yuvj420p
Input #0, rtsp, from 'rtsp://****************************************':
Metadata:
title : Media Server
Duration: N/A, start: 0.041000, bitrate: N/A
Stream #0:0: Video: h264 (Baseline), 1 reference frame, yuvj420p(pc, bt709, progressive, left), 1280x720, 12 fps, 25 tbr, 90k tbn, 24 tbc
Stream #0:1: Audio: aac (LC), 32000 Hz, mono, fltp
[tcp @ 00000000001b3100] Starting connection attempt to 216.58.208.204 port 1935
[tcp @ 00000000001b3100] Successfully connected to 216.58.208.204 port 1935
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[graph_0_in_0_1 @ 000000000014d580] tb:1/32000 samplefmt:fltp samplerate:32000 chlayout:0x4
[Parsed_aresample_0 @ 0000000000191e40] ch:1 chl:mono fmt:fltp r:32000Hz -> ch:1 chl:mono fmt:fltp r:44100Hz
[Parsed_aresample_0 @ 0000000000191e40] [SWR @ 00000000001385c0] adding 16384 audio samples of silence
Last message repeated 3 times
[Parsed_aresample_0 @ 0000000000191e40] [SWR @ 00000000001385c0] adding 11264 audio samples of silence
Output #0, flv, to 'rtmp://a.rtmp.youtube.com/live2/********************':
Metadata:
title : Media Server
encoder : Lavf58.45.100
Stream #0:0: Video: h264 (Baseline), 1 reference frame ([7][0][0][0] / 0x0007), yuvj420p(pc, bt709, progressive, left), 1280x720 (0x0), q=2-31, 12 fps, 25 tbr, 1k tbn, 90k tbc
Stream #0:1: Audio: aac (LC) ([10][0][0][0] / 0x000A), 44100 Hz, mono, fltp, delay 1024, 128 kb/s
Metadata:
encoder : Lavc58.91.100 aac
frame= 0 fps=0.0 q=-1.0 size= 0kB time=00:00:03.55 bitrate= 1.0kbits/s speed= 6.7x
frame= 0 fps=0.0 q=-1.0 size= 0kB time=00:00:04.06 bitrate= 0.8kbits/s speed=3.68x
frame= 1 fps=0.6 q=-1.0 size= 87kB time=00:00:04.13 bitrate= 172.6kbits/s speed=2.35x
frame= 15 fps=6.6 q=-1.0 size= 147kB time=00:00:05.29 bitrate= 227.8kbits/s speed=2.32x
frame= 21 fps=7.5 q=-1.0 size= 168kB time=00:00:05.82 bitrate= 236.6kbits/s speed=2.08x
frame= 25 fps=6.9 q=-1.0 size= 243kB time=00:00:06.10 bitrate= 325.9kbits/s speed=1.68x
frame= 36 fps=8.7 q=-1.0 size= 289kB time=00:00:07.10 bitrate= 333.4kbits/s speed=1.71x
frame= 44 fps=9.5 q=-1.0 size= 317kB time=00:00:07.66 bitrate= 338.7kbits/s speed=1.65x
frame= 49 fps=8.7 q=-1.0 size= 396kB time=00:00:08.12 bitrate= 399.0kbits/s speed=1.45x
frame= 61 fps= 10 q=-1.0 size= 446kB time=00:00:09.12 bitrate= 400.5kbits/s speed=1.49x
frame= 67 fps= 10 q=-1.0 size= 470kB time=00:00:09.63 bitrate= 399.8kbits/s speed=1.45x
frame= 73 fps=9.7 q=-1.0 size= 553kB time=00:00:10.12 bitrate= 447.5kbits/s speed=1.35x
frame= 84 fps= 10 q=-1.0 size= 601kB time=00:00:11.07 bitrate= 444.2kbits/s speed=1.37x
frame= 90 fps= 11 q=-1.0 size= 624kB time=00:00:11.58 bitrate= 440.8kbits/s speed=1.35x
frame= 96 fps= 11 q=-1.0 size= 646kB time=00:00:12.07 bitrate= 438.0kbits/s speed=1.33x
frame= 98 fps= 10 q=-1.0 size= 713kB time=00:00:12.19 bitrate= 479.2kbits/s speed=1.27x
frame= 109 fps= 11 q=-1.0 size= 760kB time=00:00:13.11 bitrate= 474.7kbits/s speed= 1.3x
frame= 116 fps= 11 q=-1.0 size= 786kB time=00:00:13.60 bitrate= 472.9kbits/s speed=1.28x
frame= 121 fps= 10 q=-1.0 size= 872kB time=00:00:14.11 bitrate= 505.9kbits/s speed=1.21x
frame= 132 fps= 11 q=-1.0 size= 916kB time=00:00:15.04 bitrate= 499.0kbits/s speed=1.21x
frame= 143 fps= 11 q=-1.0 size= 956kB time=00:00:15.97 bitrate= 490.3kbits/s speed=1.23x
frame= 145 fps= 11 q=-1.0 size= 1029kB time=00:00:16.13 bitrate= 522.6kbits/s speed=1.18x
frame= 159 fps= 11 q=-1.0 size= 1083kB time=00:00:17.22 bitrate= 514.9kbits/s speed=1.21x
frame= 165 fps= 11 q=-1.0 size= 1108kB time=00:00:17.74 bitrate= 511.7kbits/s speed= 1.2x
frame= 169 fps= 11 q=-1.0 size= 1188kB time=00:00:18.11 bitrate= 537.3kbits/s speed=1.16x
frame= 182 fps= 11 q=-1.0 size= 1242kB time=00:00:19.17 bitrate= 530.5kbits/s speed=1.19x
frame= 189 fps= 11 q=-1.0 size= 1265kB time=00:00:19.69 bitrate= 526.2kbits/s speed=1.18x
frame= 193 fps= 11 q=-1.0 size= 1348kB time=00:00:20.13 bitrate= 548.7kbits/s speed=1.14x
frame= 206 fps= 11 q=-1.0 size= 1400kB time=00:00:21.13 bitrate= 542.9kbits/s speed=1.17x
frame= 212 fps= 11 q=-1.0 size= 1426kB time=00:00:21.66 bitrate= 539.3kbits/s speed=1.16x
frame= 217 fps= 11 q=-1.0 size= 1512kB time=00:00:22.12 bitrate= 559.9kbits/s speed=1.13x
frame= 230 fps= 11 q=-1.0 size= 1566kB time=00:00:23.17 bitrate= 553.5kbits/s speed=1.15x
frame= 236 fps= 11 q=-1.0 size= 1587kB time=00:00:23.66 bitrate= 549.5kbits/s speed=1.14x
frame= 241 fps= 11 q=-1.0 size= 1672kB time=00:00:24.10 bitrate= 568.2kbits/s speed=1.12x
frame= 253 fps= 11 q=-1.0 size= 1723kB time=00:00:25.12 bitrate= 561.9kbits/s speed=1.14x
frame= 260 fps= 11 q=-1.0 size= 1746kB time=00:00:25.61 bitrate= 558.4kbits/s speed=1.13x
frame= 265 fps= 11 q=-1.0 size= 1833kB time=00:00:26.14 bitrate= 574.2kbits/s speed=1.11x
frame= 278 fps= 12 q=-1.0 size= 1887kB time=00:00:27.16 bitrate= 569.1kbits/s speed=1.12x
frame= 285 fps= 12 q=-1.0 size= 1910kB time=00:00:27.69 bitrate= 564.9kbits/s speed=1.12x
frame= 289 fps= 11 q=-1.0 size= 1993kB time=00:00:28.14 bitrate= 580.2kbits/s speed= 1.1x
frame= 301 fps= 12 q=-1.0 size= 2044kB time=00:00:29.11 bitrate= 574.9kbits/s speed=1.11x
frame= 308 fps= 12 q=-1.0 size= 2069kB time=00:00:29.67 bitrate= 571.1kbits/s speed=1.11x
frame= 313 fps= 11 q=-1.0 size= 2154kB time=00:00:30.11 bitrate= 585.8kbits/s speed=1.09x
frame= 325 fps= 12 q=-1.0 size= 2204kB time=00:00:31.11 bitrate= 580.3kbits/s speed=1.11x
frame= 331 fps= 12 q=-1.0 size= 2226kB time=00:00:31.57 bitrate= 577.4kbits/s speed= 1.1x
frame= 337 fps= 11 q=-1.0 size= 2312kB time=00:00:32.13 bitrate= 589.4kbits/s speed=1.09x
frame= 350 fps= 12 q=-1.0 size= 2364kB time=00:00:33.13 bitrate= 584.5kbits/s speed= 1.1x
frame= 356 fps= 12 q=-1.0 size= 2388kB time=00:00:33.64 bitrate= 581.5kbits/s speed= 1.1x
frame= 362 fps= 11 q=-1.0 size= 2473kB time=00:00:34.13 bitrate= 593.4kbits/s speed=1.08x
frame= 373 fps= 12 q=-1.0 size= 2522kB time=00:00:35.10 bitrate= 588.6kbits/s speed=1.09x
frame= 380 fps= 12 q=-1.0 size= 2548kB time=00:00:35.64 bitrate= 585.5kbits/s speed=1.09x
frame= 386 fps= 11 q=-1.0 size= 2632kB time=00:00:36.12 bitrate= 596.9kbits/s speed=1.08x
frame= 398 fps= 12 q=-1.0 size= 2681kB time=00:00:37.12 bitrate= 591.6kbits/s speed=1.09x
frame= 404 fps= 12 q=-1.0 size= 2704kB time=00:00:37.61 bitrate= 588.9kbits/s speed=1.09x
frame= 410 fps= 12 q=-1.0 size= 2790kB time=00:00:38.12 bitrate= 599.5kbits/s speed=1.07x
frame= 421 fps= 12 q=-1.0 size= 2839kB time=00:00:39.10 bitrate= 594.8kbits/s speed=1.08x
frame= 427 fps= 12 q=-1.0 size= 2861kB time=00:00:39.59 bitrate= 592.1kbits/s speed=1.08x
frame= 433 fps= 11 q=-1.0 size= 2947kB time=00:00:40.10 bitrate= 602.0kbits/s speed=1.06x
frame= 446 fps= 12 q=-1.0 size= 2997kB time=00:00:41.19 bitrate= 596.0kbits/s speed=1.08x
frame= 453 fps= 12 q=-1.0 size= 3020kB time=00:00:41.70 bitrate= 593.2kbits/s speed=1.08x
frame= 458 fps= 12 q=-1.0 size= 3103kB time=00:00:42.12 bitrate= 603.4kbits/s speed=1.06x
frame= 469 fps= 12 q=-1.0 size= 3151kB time=00:00:43.12 bitrate= 598.7kbits/s speed=1.08x
frame= 475 fps= 12 q=-1.0 size= 3173kB time=00:00:43.58 bitrate= 596.5kbits/s speed=1.07x
frame= 481 fps= 12 q=-1.0 size= 3260kB time=00:00:44.09 bitrate= 605.7kbits/s speed=1.06x
[Parsed_aresample_0 @ 0000000000191e40] [SWR @ 00000000001385c0] discarding 9657 audio samples
[flv @ 00000000030400c0] Non-monotonous DTS in output stream 0:0; previous: 44682, current: 44525; changing to 44682. This may result in incorrect timestamps in the output file.
[flv @ 00000000030400c0] Non-monotonous DTS in output stream 0:0; previous: 44682, current: 44605; changing to 44682. This may result in incorrect timestamps in the output file.
frame= 493 fps= 12 q=-1.0 size= 3302kB time=00:00:44.81 bitrate= 603.6kbits/s speed=1.06x
frame= 500 fps= 12 q=-1.0 size= 3329kB time=00:00:45.39 bitrate= 600.7kbits/s speed=1.07x
frame= 505 fps= 12 q=-1.0 size= 3412kB time=00:00:45.86 bitrate= 609.6kbits/s speed=1.05x
frame= 517 fps= 12 q=-1.0 size= 3462kB time=00:00:46.85 bitrate= 605.2kbits/s speed=1.06x
frame= 525 fps= 12 q=-1.0 size= 3488kB time=00:00:47.43 bitrate= 602.4kbits/s speed=1.06x
frame= 529 fps= 12 q=-1.0 size= 3570kB time=00:00:47.87 bitrate= 610.9kbits/s speed=1.05x
frame= 542 fps= 12 q=-1.0 size= 3620kB time=00:00:48.87 bitrate= 606.6kbits/s speed=1.06x
frame= 548 fps= 12 q=-1.0 size= 3642kB time=00:00:49.38 bitrate= 604.1kbits/s speed=1.06x
frame= 553 fps= 12 q=-1.0 size= 3724kB time=00:00:49.83 bitrate= 612.3kbits/s speed=1.05x
frame= 565 fps= 12 q=-1.0 size= 3774kB time=00:00:50.85 bitrate= 608.0kbits/s speed=1.06x
frame= 571 fps= 12 q=-1.0 size= 3797kB time=00:00:51.36 bitrate= 605.6kbits/s speed=1.06x
frame= 577 fps= 12 q=-1.0 size= 3882kB time=00:00:51.82 bitrate= 613.6kbits/s speed=1.05x
frame= 589 fps= 12 q=-1.0 size= 3931kB time=00:00:52.84 bitrate= 609.4kbits/s speed=1.06x
frame= 595 fps= 12 q=-1.0 size= 3951kB time=00:00:53.36 bitrate= 606.6kbits/s speed=1.06x
frame= 601 fps= 12 q=-1.0 size= 4038kB time=00:00:53.82 bitrate= 614.5kbits/s speed=1.04x
frame= 613 fps= 12 q=-1.0 size= 4086kB time=00:00:54.86 bitrate= 610.1kbits/s speed=1.05x
frame= 619 fps= 12 q=-1.0 size= 4109kB time=00:00:55.33 bitrate= 608.3kbits/s speed=1.05x
frame= 625 fps= 12 q=-1.0 size= 4195kB time=00:00:55.82 bitrate= 615.6kbits/s speed=1.04x
frame= 637 fps= 12 q=-1.0 size= 4243kB time=00:00:56.86 bitrate= 611.2kbits/s speed=1.05x
frame= 644 fps= 12 q=-1.0 size= 4267kB time=00:00:57.37 bitrate= 609.3kbits/s speed=1.05x
frame= 649 fps= 12 q=-1.0 size= 4350kB time=00:00:57.84 bitrate= 616.1kbits/s speed=1.04x
frame= 661 fps= 12 q=-1.0 size= 4400kB time=00:00:58.79 bitrate= 613.1kbits/s speed=1.05x
frame= 667 fps= 12 q=-1.0 size= 4421kB time=00:00:59.30 bitrate= 610.7kbits/s speed=1.05x
frame= 672 fps= 12 q=-1.0 size= 4439kB time=00:00:59.79 bitrate= 608.2kbits/s speed=1.05x
frame= 674 fps= 12 q=-1.0 size= 4512kB time=00:00:59.90 bitrate= 616.9kbits/s speed=1.04x
frame= 686 fps= 12 q=-1.0 size= 4560kB time=00:01:00.92 bitrate= 613.1kbits/s speed=1.05x
frame= 692 fps= 12 q=-1.0 size= 4580kB time=00:01:01.44 bitrate= 610.7kbits/s speed=1.05x
frame= 697 fps= 12 q=-1.0 size= 4664kB time=00:01:01.83 bitrate= 617.9kbits/s speed=1.04x
frame= 708 fps= 12 q=-1.0 size= 4711kB time=00:01:02.78 bitrate= 614.6kbits/s speed=1.05x
frame= 715 fps= 12 q=-1.0 size= 4737kB time=00:01:03.27 bitrate= 613.3kbits/s speed=1.04x
frame= 721 fps= 12 q=-1.0 size= 4822kB time=00:01:03.80 bitrate= 619.1kbits/s speed=1.04x
frame= 733 fps= 12 q=-1.0 size= 4872kB time=00:01:04.87 bitrate= 615.2kbits/s speed=1.04x
frame= 741 fps= 12 q=-1.0 size= 4898kB time=00:01:05.38 bitrate= 613.7kbits/s speed=1.04x
frame= 745 fps= 12 q=-1.0 size= 4979kB time=00:01:05.80 bitrate= 619.8kbits/s speed=1.04x
frame= 757 fps= 12 q=-1.0 size= 5029kB time=00:01:06.75 bitrate= 617.1kbits/s speed=1.04x
frame= 763 fps= 12 q=-1.0 size= 5051kB time=00:01:07.26 bitrate= 615.1kbits/s speed=1.04x
frame= 768 fps= 12 q=-1.0 size= 5069kB time=00:01:07.75 bitrate= 612.8kbits/s speed=1.04x
frame= 770 fps= 12 q=-1.0 size= 5141kB time=00:01:07.87 bitrate= 620.5kbits/s speed=1.04x
frame= 781 fps= 12 q=-1.0 size= 5187kB time=00:01:08.80 bitrate= 617.6kbits/s speed=1.04x
frame= 788 fps= 12 q=-1.0 size= 5209kB time=00:01:09.35 bitrate= 615.2kbits/s speed=1.04x
frame= 793 fps= 12 q=-1.0 size= 5293kB time=00:01:09.79 bitrate= 621.3kbits/s speed=1.03x
frame= 804 fps= 12 q=-1.0 size= 5340kB time=00:01:10.72 bitrate= 618.5kbits/s speed=1.04x