11

I have an audio stream, im using ffmpeg to stream it to youtube live with an image as background with following command,

ffmpeg -loop 1 -i x.jpg -i http://xxx.xxx.xxx.xxxx:5305/stream -c:a aac -s 1280x720 -ab 128k -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/xxxxx

But im getting the following message on youtube,

YouTube is not receiving enough video to maintain smooth streaming. As such, viewers will experience buffering this cause buffering in the output stream.

Any one know how to fix it ?

Helps would be appreciated.

Vishnu Prassad
  • 333
  • 1
  • 3
  • 12

2 Answers2

13

After a lot of trial and error the solution below works pretty much perfectly. To make sure it runs 24/7 wrap it inside a service of some description.

This is with an up to date version of FFMPEG to include -stream_loop -1.
The background is an mp4 file.
http://localhost:3888 = an audio stream.

ffmpeg -stream_loop -1 -i $MYPATH/background/$background \
-i http://localhost:3888 -filter:a "volume=$volume" \
-r 24 -g 48 -pix_fmt yuv420p -x264-params keyint=48:min-keyint=48:scenecut=-1 \
-s $size -b:v $bitrate -b:a 128k -ar 44100 -acodec aac \
-vcodec libx264 -preset superfast -bufsize 960k -crf 28 -threads 2 \
-f flv rtmp://a.rtmp.youtube.com/live2/$key

Config File:

# Config File
background=out.mp4
size=1280x720
bitrate=1500k
key=----KEY----
volume=0.5

EDIT -- Old Solution below

So i have a solution.

ffmpeg -re -loop 1 -framerate 2 -i test1.jpg -i https://xxxxxxx:8443/live.ogg -c:a aac -s 2560x1440 -ab 128k -maxrate 2048k -bufsize 2048k -framerate 30 -g 60 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/xxxxxxxxxxxxx

The important parts are the

-re

at the start which deals with a buffering issue.
Then the

-framerate 2

between the "-loop 1" and the image. This works and i get a good clean high quality stream that does not buffer.

Hoped this helped!

Edit 1

ffmpeg -re -loop 1 -framerate 2 -i test1.jpg -i https://xxxxxxxxxxx:8443/live.ogg -c:a aac -s 2560x1440 -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/xxxxxxxxxxxxx

Ok So this updated version should fix almost all problems with the stream.

-vcodec libx264 -pix_fmt yuv420p

Changed to H.264 Codex Fixed that problem

-g 2

This fixes the final buffering issue.

Jonese1234
  • 193
  • 8
  • what version of ffmpeg are you on? – moeiscool Jun 20 '17 at 00:02
  • @moeiscool should work on the current verson, i have not tested! – Jonese1234 Jun 20 '17 at 19:52
  • my problem is that i tried 3.3(a static build) and 3.2.4 (ppa).. this is on ubuntu 17 btw... It refuses to work. When i start FFMPEG it will give the green light on youtube for about 20 seconds then go grey and nothing shows up.. eventually it will say offline... leaving me with a video uploaded to my channel possibly blasting all my users with a whole lot of nothing :P – moeiscool Jun 21 '17 at 03:40
  • I wonder if there is away to hide YouTube key from the command line. Running `ffmpeg` like this can make your key visible to other system users, they can do `ps -Af ` and see your key (if they have enough privileges on the system) in the process list. A possible solution could be reading the target YouTube url from a file, is it possible? – Alex Paramonov Sep 20 '18 at 08:54
  • 1
    @AlexParamonov Is this possible via: `ffmpeg ... "$YTUBE/$(cat keyfile)"`? – ARF Oct 20 '19 at 04:49
3

The last code is excellent, but I am still getting error message regarding "video resolution" on youtube Live with the latest command. I fixed it by replacing:

yuv420p with yuvj420p

I probed jpg with ffprobe and it returned the above yuv420p

user43964
  • 31
  • 1