[FFmpeg-user] Consistent RTMP stream crashing with high resolution and bit-rate video (av_interleaved_write_frame(): Unknown error)

Gabriel Balaich roderrooder at gmail.com
Thu Apr 15 10:20:41 EEST 2021


I'm attempting to send a 4K60 50Mbps stream from FFmpeg to YouTube, and
can't seem to get any system fully working.

I started by trying to send the stream directly from FFmpeg to YouTube:
ffmpeg `
-guess_layout_max 0 -thread_queue_size 9999 -indexmem 9999 -f dshow
-rtbufsize 2147.48M -video_size 3840x2160 -framerate 60 `
-pixel_format nv12 -i video="Video (00-1 Pro Capture Dual HDMI
4K+)":audio="Audio (00-1 Pro Capture Dual HDMI 4K+)" `
-map 0:0,0:1 -map 0:1 -c:v h264_nvenc -preset: p1 -rc:v cbr -pix_fmt nv12
-r 60 -rc-lookahead 120 -strict_gop 1 `
-flags +cgop -g 120 -forced-idr 1 -sc_threshold 0 -force_key_frames
"expr:gte(t,n_forced*2)" -b:v 50M -minrate 50M `
-maxrate 50M -bufsize 50M -c:a mp3 -ac 2 -ar 44100 -b:a 128K -af
"atrim=0.316, asetpts=PTS-STARTPTS, aresample=async=250" `
-vsync 1 -max_muxing_queue_size 9999 -f flv -flvflags no_duration_filesize `
rtmp://a.rtmp.youtube.com/live2/<Stream Key>

But for reasons I still don't fully understand, the above command will only
run at 0.2x speed. The only "bottleneck" I was able to find was that my
network send was seemingly stuck at 10Mbps (via task manager), this is
notable because via YouTube's documentation
<https://support.google.com/youtube/answer/2853702?hl=en> 4K60 @ 50Mbps is
within spec. It's also worth noting that running the above command to a
local file instead of a stream works flawlessly, it barely touches my
hardware (AMD 1950X, GTX 1080, 32GB of RAM, 1TB 860 Evo). After updating to
Gyan's latest git build, running FFmpeg in an elevated instance of
Powershell as an administrator, completely disabling my system Firewall,
bypassing my router going straight to my modem, calling my ISP (I have a
1000/1000Mbps fiber optic connection), and searching far and wide online; I
couldn't find an answer as to why my network was being capped. Eventually
someone suggested that I run a RTMP server locally to see how that would
work, and to my surprise it did change the results.

If I run the above command, but send it to a local instance of Nginx
compiled with the RTMP module (latest Nginx build running on WLS2 Ubuntu
20.04) and then I relay that to YouTube, I get the full 50Mbps uplink. So
the only changes I made to that first command is final line / output:
rtmp://$((wsl hostname -I).Trim())/YouTube

Relevant Nginx configuration:
rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application YouTube {
            record off;
            live on;
            push rtmp://a.rtmp.youtube.com/live2/<Stream Key>;
        }
    }
}

This seems to work great on the surface, however, if my scene ever shifts
from something high complexity to something low complexity or vice versa
the FFmpeg instance crashes with error "av_interleaved_write_frame():
Unknown error". For example, in the case that I'm streaming a game from my
PS5 and I go from running around in a 3D environment to pulling up the game
menu, which in many cases is a still image, the stream crashes with the
aforementioned error message. This happens fairly consistently, and is
totally unavoidable when capturing certain sources. I couldn't see any
errors in Nginx's log, so I thought it was a problem with YouTube's ingest
servers. I tried just commenting out the push line in my Nginx
configuration file, but I still got the same error. This told me it was
something on my end...

First thing I tried was lowering the bitrate, and it would seem that
anything under 20Mbps is a go. It doesn't matter how complex or the lack
thereof the source is, doesn't matter how often I switch between the
extremes, it doesn't seem to crash, I was able to stream continuously for
8+ hours. But since my goal is really to get the maximum quality YouTube
has to offer, I went on to test changing the resolution. This is where
things get interesting I feel... as long as my RTMP stream is at or below
1920x1080 60FPS I can't get that error to generate, even when pushing
400Mbps everything is hunky dory. As soon as I go above 400Mbps @ 1080p60
my command stops running in real-time, or in other words I hit a new
bottleneck. So I've been able to narrow it down, at least seemingly, to
streams running at 2560x1440 60FPS or greater, with bit-rates exceeding
20Mbps, where scene complexity has sudden changes.

Obviously 4K60 @ 50Mbps is a lighter load than 1080p60 @ 400Mbps, so it
doesn't seem to be tied to total throughput which doesn't make sense to me.
Additionally, the trigger being sudden changes in scene complexity is
bizarre, especially when you consider that I'm utilizing CBR.

 Any idea why this would be happening?


Here's the full output of a stream that ran for 22 seconds before crashing:
PS C:\Users\gabri> ffmpeg `
>> -guess_layout_max 0 -thread_queue_size 9999 -indexmem 9999 -f dshow
-rtbufsize 2147.48M -video_size 3840x2160 -framerate 60 `
>> -pixel_format nv12 -i video="Video (00-1 Pro Capture Dual HDMI
4K+)":audio="Audio (00-1 Pro Capture Dual HDMI 4K+)" `
>> -map 0:0,0:1 -map 0:1 -c:v h264_nvenc -preset: p1 -rc:v cbr -cbr true
-pix_fmt nv12 -r 60 -rc-lookahead 120 -strict_gop 1 `
>> -flags +cgop -g 120 -forced-idr 1 -sc_threshold 0 -force_key_frames
"expr:gte(t,n_forced*2)" -b:v 50M -minrate 50M `
>> -maxrate 50M -bufsize 50M -c:a mp3 -ac 2 -ar 44100 -b:a 128K -af
"atrim=0.316, asetpts=PTS-STARTPTS, aresample=async=250" `
>> -vsync 1 -max_muxing_queue_size 9999 -f flv -flvflags
no_duration_filesize `
>> rtmp://$((wsl hostname -I).Trim())/YouTube
ffmpeg version 2021-04-14-git-c5ca18fd1b-full_build-www.gyan.dev Copyright
(c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, 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-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. 72.100 / 56. 72.100
  libavcodec     58.136.101 / 58.136.101
  libavformat    58. 78.100 / 58. 78.100
  libavdevice    58. 14.100 / 58. 14.100
  libavfilter     7.111.100 /  7.111.100
  libswscale      5. 10.100 /  5. 10.100
  libswresample   3. 10.100 /  3. 10.100
  libpostproc    55. 10.100 / 55. 10.100
Input #0, dshow, from 'video=Video (00-1 Pro Capture Dual HDMI
4K+):audio=Audio (00-1 Pro Capture Dual HDMI 4K+)':
  Duration: N/A, start: 18236.953000, bitrate: N/A
  Stream #0:0: Video: rawvideo (NV12 / 0x3231564E), nv12, 3840x2160, 60
fps, 60 tbr, 10000k tbn, 10000k tbc
  Stream #0:1: Audio: pcm_s16le, 44100 Hz, 2 channels, s16, 1411 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 [sync #0:1] (rawvideo (native) -> h264 (h264_nvenc))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, flv, to 'rtmp://172.18.22.104/YouTube':
  Metadata:
    encoder         : Lavf58.78.100
  Stream #0:0: Video: h264 (Main) ([7][0][0][0] / 0x0007),
nv12(progressive), 3840x2160, q=2-31, 50000 kb/s, 60 fps, 1k tbn
    Metadata:
      encoder         : Lavc58.136.101 h264_nvenc
    Side data:
      cpb: bitrate max/min/avg: 50000000/0/50000000 buffer size: 50000000
vbv_delay: N/A
  Stream #0:1: Audio: mp3 ([2][0][0][0] / 0x0002), 44100 Hz, stereo, s16p,
128 kb/s
    Metadata:
      encoder         : Lavc58.136.101 libmp3lame
av_interleaved_write_frame(): Unknown errortime=00:00:22.03
bitrate=49714.0kbits/s speed=0.966x
Error writing trailer of rtmp://172.18.22.104/YouTube: Error number -10054
occurred
frame= 1376 fps= 60 q=13.0 Lsize=  134973kB time=00:00:22.13
bitrate=49945.6kbits/s speed=0.959x
video:134621kB audio:346kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.004339%
Conversion failed!


More information about the ffmpeg-user mailing list