Question / Help Stream recode with ffmpeg

Yasaka

Member
Hey guys, ive got a linuxserver with 2 cpus so ive got an idea. i encode the stream on my pc with 15 Mbit with very good quality(my upload at home is 20mbit) and send the stream to my linuxserver and the linuxserver recode the stream with 2 - 2,5 MBit with a slower preset for twitch. so i setup everything. i have on my pc a nginx server, obs send the stream to localhost(nginx) and my linuxserver gets the stream with ffmpeg. everything works fine but ffmpeg doesnt encode with the desired bitrate. i saw my stream on twitch while i tested it but with a very bad quality because the bitrate is too low. the only problem now is how i can force ffmpeg to use the desired bitrate? this is my actual ffmpeg command:
ffmpeg -i rtmp://HomeIp/live/d0r -c:v libx264 -preset slower -b:v 2300 -minrate 2300k -maxrate 2300k -crf 19 -threads 8 -c:a copy -f flv rtmp://live-fra.twitch.tv/app/Streamkey | -f flv rtmp://a.rtmp.youtube.com/live2/streamkey

so i hope somebody know how i can fix this problem. how i said ffmpeg wont use the desired bitrate.
 

NalaNosivad

Member
Okay, well the first problem I see....

Why are you using such a high (or low, depending on your viewpoint) CRF when you're sending video out for streaming AND specifying a bitrate?

Give

ffmpeg -i rtmp://HomeIp/live/d0r -c:v libx264 -preset slower -b:v 2300k -minrate 2300k -maxrate 2300k -threads 8 -c:a copy -f flv rtmp://live-fra.twitch.tv/app/Streamkey | -f flv rtmp://a.rtmp.youtube.com/live2/streamkey

a try. You had -minrate 2300 and -maxrate 2300 instead of -minrate 2300k and -maxrate 2300k, and the CRF parameter is meaningless there as far as I know. That should get you 2300Kbps on average.
 

Yasaka

Member
thank you this solved my problem. i didnt noticed the mistake with the bitrate. i removed the crf parameter. the test looks really good but i noticed that my stream dont reach youtube. i googled multiple outputs in ffmpeg and this "copy -f flv rtmp://live-fra.twitch.tv/app/Streamkey | -f flv rtmp://a.rtmp.youtube.com/live2/streamkey" should work. for a test i wrote the youtube link first and it worked. so how i can send the stream to twitch and youtube?
 

Simes

Member
If you have a reasonably recent ffmpeg version, try this instead:

ffmpeg -i rtmp://HomeIp/live/d0r -c:v libx264 -preset slower -b:v 2300k -minrate 2300k -maxrate 2300k -threads 8 -c:a copy -f tee "[f=flv]rtmp://live-fra.twitch.tv/app/Streamkey|[f=flv]rtmp://a.rtmp.youtube.com/live2/streamkey"

The command you're using uses a pipe separator, which is normally used to send output to another command. You're not specifying another command to run, which is why it isn't working. This one uses the "tee" pseudomuxer, which is specifically for creating duplicate outputs from ffmpeg.
 

Yasaka

Member
idk why but it doesnt work it says "Output file #0 does not contain any stream". but it dont really matter. i started a nginx rtmp server to send my stream to twitch & youtube.the only problem now is that ffmpeg ignores the maxrate. this are my settings now:
ffmpeg -i rtmp://ip/live/d0r -c:v libx264 -preset slow -b:v 2150k -minrate 1800k -maxrate 2300k -g 60 -refs 2 -bf 1 -threads 8 -c:a copy -f flv rtmp://127.0.0.1/live/
the problem is ffmpeg uses when the stream has high motion 4mbit. how can i force that ffmpeg dont use more bitrate than 2300k?
 

Simes

Member
You haven't set a buffer size, and you've got parameters for both constant bit rate "-b:v" and variable bit rate "-maxrate". According to "https://trac.ffmpeg.org/wiki/Limiting the output bitrate", without a buffer size set, ffmpeg will take longer to check that your bit rate conforms to the constant value you've set. The docs recommend no more than 2 seconds for live streaming, so you'd want to set "-bufsize 4300k".

Might also be worth reading http://superuser.com/questions/5360...ith-vb-and-minrate-maxrate-settings-in-ffmpeg
 

Yasaka

Member
i removed max and minrate. now i just use bitrate and a bufsize which is bitrate*2 and it works very well. thank you guys for help.
 
Top