Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFMPEG to Youtube Live

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.

like image 626
Vishnu Prassad Avatar asked Apr 24 '17 11:04

Vishnu Prassad


People also ask

How do I livestream with FFmpeg?

To start live streaming with FFmpeg, you have to download and install the software on your computer. You can choose the right installation method for your operating system from the three options above in this FFmpeg tutorial. At this point, you can also create a streaming channel on your video hosting platform.


2 Answers

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.

like image 107
Jonese1234 Avatar answered Sep 23 '22 19:09

Jonese1234


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

like image 30
user43964 Avatar answered Sep 22 '22 19:09

user43964