[FFmpeg-user] Streaming to YouTube Live

Moritz Barsnick barsnick at gmx.net
Sat Apr 18 01:45:22 EEST 2020

On Fri, Apr 17, 2020 at 17:02:21 -0500, First Last wrote:
> I am uncertain whether this question is outside the scope of this forum, so
> please advise me if it is.

It's a little bit off topic, but fine by me.

This was handled here recently, and there's a lot of stuff on the web
about it. Not detailed enough in my experience, so experimenting and
asking here is the way to go.

You'll find a few useful hints here:

> /home/ec2-user/ffmpeg-git-20200324-amd64-static/ffmpeg -re -loop 1
> -framerate 2 -i /home/ec2-user/testrun.jpg -s 1920x1080 -ab 128k -vcodec
> libx264 -pix_fmt yuv420p -maxrate 2048k -bufsize 2048k -framerate 30 -g 2
> -strict experimental -f flv
> rtmp://a.rtmp.youtube.com/live2/xxxx-xxxx-xxxx-xxxx
> It is a command I adapted from the edit on the response of the solution
> found on:
> https://stackoverflow.com/questions/43586435/ffmpeg-to-youtube-live
> The only modifications I have made to the core command is removing the audio
> stream, and changing the output resolution to match the optimal resolution
> recommended for YouTube.

It turns out exactly that is your big mistake. ;-) Try recommended
command lines first, modify later (if possible):
In my experience, an audio stream is a *must* for YouTube live
streaming. You can help yourself with silent audio with minimal
bandwidth. I believe I have succeeded with 8 and 16 kb/s AAC. (I used
to believe it needs to be two-channel audio, but my notes say I
succeeded with mono.)

You can add silence by adding a second input:
  -f lavfi -i anullsrc
and encoding it with low bandwidth AAC:
  -c:a aac -b:a 8k

Other remarks regarding your command line:
- You're using "-framerate" twice. Only one takes effect - the one
  before the input. The output option for framerate would be "-r".
- That results in the output being 2 fps - YouTube won't accept that,
  IIUC. Always use 24, 25, 30 or 60 fps (or those divided by 1.001).
- I don't see why you set the input image loop at 2 fps, only to (try
  to) expand it to 30 fps on the output. You may as well use
  "-framerate 30" as an input option (before the "-i") and drop the
  output option.
- "-g 2" is a very low GOP size. (ffmpeg interprets this option as
  number of frames in a GOP, not GOP size in seconds.) YouTube recommends
  otherwise: GOP of 2, max 4 seconds. At 30 fps, that's "-g 60".

> The resulting problem is that while ffmpeg appears to be successfully
> streaming data, albeit with a few warnings I do not have an understanding
> of, YouTube is not receiving data.

Don't forget to check your YouTube live stream console. It gives some
(hazy) indications about your stream's health.

YouTube has some codec recommendations, but I believe you can deviate
from them with little harm:

In other words: More experimenting. It gets more exciting, once you
need to encode motion video in real time. ;-)

Good luck, and tell us how it went,

More information about the ffmpeg-user mailing list