[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 20:18:53 EEST 2021

On Thu, 15 Apr 2021 at 01:20, Gabriel Balaich <roderrooder at gmail.com> wrote:

> 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...
> 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?

It would seem that the actual issue is bitrate variability, for example
when I put my -bufsize at 10M I'm not getting the error nearly as often:
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 10M -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>

About 50% of the time I get the error on startup if I start on a complex
scene, if I start the stream on a still image it never crashes on startup,
and then I can switch off of it just fine (kind of an annoying work around
though). It's my understanding that the lower the -bufsize (in relation to
the bitrate) the worse it affects quality, so it's kind of a bummer if this
is the "solution".  It also doesn't explain to me why great variability
isn't causing problems at 1080p60 <, as well as higher resolutions at lower
bitrates. There seems to be a problem with specifically higher resolutions
/ bitrates and bitrate variability, can't seem to wrap my head around it.

Is it possible to absolutely force FFmpeg to output a specific bitrate?
Even going as far as artificially filling or cutting?

More information about the ffmpeg-user mailing list