ffmpeg streaming to rtmp at 30fps

0

I am trying to stream my desktop to facebook rtmp server using screen-capture-recorder:

ffmpeg -re -rtbufsize 256M -f dshow -i audio="Mikrofon (Realtek Audio)" 
-rtbufsize 256M -f dshow -i audio="virtual-audio-capturer"  
-rtbufsize 1024M -f dshow -i video=screen-capture-recorder -r 30  
-filter:v scale=1280:720 -c:v  h264_nvenc -pix_fmt yuv420p -preset fast 
-b:v 8M -maxrate:v 10M  -c:a aac -b:a 128k -ar 44100 
-f flv rtmp://live-api.facebook.com:80/rtmp/..............

I am using h264_nvenc codec for gpu acceleration, but I can stream to rtmp at only 12-18 fps. However, when I stream into a file:

ffmpeg -re  -rtbufsize 256M -f dshow -i audio="Mikrofon (Realtek Audio)" 
-rtbufsize 256M -f dshow -i audio="virtual-audio-capturer"  
-rtbufsize 1024M -f dshow -i video=screen-capture-recorder -r 30  
-filter:v scale=1280:720 -c:v  h264_nvenc -pix_fmt yuv420p -preset fast 
-b:v 8M -maxrate:v 10M  -c:a aac -b:a 128k -ar 44100 
D:\test.mp4 -y

I get 30 fps without problem, even when playing game (eg. Call of duty 6, pretty HW draining).

Also, when streaming (to rtmp) starts, after a while I keep getting this error, altough my -rtbufsize size is 1024M, which I consider pretty big, and many frames are lost:

real-time buffer too full or near too full! frame dropped!

Can you help me how to prevent rtbufsize error, and is it possible to modify my command so I can stream to rtmp at 30 fps ? Thank you

If needed, my ffmpeg build config is:

ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 7.1.0 (GCC) configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib

user6326558

Posted 2018-01-24T08:15:20.610

Reputation: 3

Answers

0

To start, I would lose the individual -rtbufsize for each input. If ffmpeg is lagging, increasing the real time buffer's not going to help, unless you're trying to remedy occasional spikes. I'm not sure how much headroom ffmpeg reserves on windows, but I think it's safe to assume that if you're getting 12fps with the output frame rate set to 30, it's never going to catch up. It's basically recording up to 1GB of the screen capture to encode later, acting as a buffer of maybe a minute, probably shorter before it drops frames.

You said you were able to save to file at 30fps with no problem, so it's probably the upload speed to facebook. So you have to make the output smaller, basically.

I'm pretty sure ffmpeg reads all input as 25fps by default, so setting the output to 25fps instead of 30 would probably bump your fps up to over 20 for free. I'm not sure about how dshow works though, so I might be wrong about that, if you really want 30fps.

and I just noticed you put -b:v 8M for the encoder... is that realistic for your internet connection? A lot of ISP's will throttle uploads for its residential customers, so you might not be able to do more than 3-4mbps, especially if you want to live stream.

You want to use -preset=slow or medium if you're going to use a preset. It might be different for the hardware encoder, so you might want to check its options, but with network speeds as the bottleneck, there's not much you can do if you want real-time streaming, the video's gotta be smaller, either in frame rate, resolution, or compression.

user3052786

Posted 2018-01-24T08:15:20.610

Reputation: 136