1

I have a webradio streamed by Liquidsoap+Icecast on a DigitalOcean droplet (Ubuntu 16.04), and I want to combine this audio stream with a simple jpeg image with ffmpeg, transform it to a video stream and send it to Facebook live.

Facebook Live specifications :

Video Format :

We accept video in maximum 720p (1280 x 720) resolution, at 30 frames per second. (or 1 key frame every 2 seconds). You must send an I-frame (keyframe) at least once every two seconds throughout the stream.. Recommended max bit rate is 4000 Kbps. Titles must be less than 255 characters otherwise the stream will fail. The Live API accepts H264 encoded video and AAC encoded audio only.

Video Length :

240 minute maximum length, with the exception of continuous live (see above). 240 minute maximum length for preview streams (either through Live dialog or publisher tools). After 240 minutes, a new stream key must be generated.

Advanced Settings :

Pixel Aspect Ratio: Square. Frame Types: Progressive Scan. Audio Sample Rate: 44.1 KHz. Audio Bitrate: 128 Kbps stereo. Bitrate Encoding: CBR.

And the ffmpeg command I tried :

ffmpeg -loop 1 -i radio-background.jpg -thread_queue_size 20480 -i http://localhost:8000/radio -framerate 30 -r 30 -acodec aac -strict -2 -c:v libx264 -strict experimental -b:a 128k -pix_fmt yuvj444p -x264-params keyint=60 -b:v 256k -minrate 128k -maxrate 512k -bufsize 768k -f flv 'rtmp://rtmp-api.facebook.com:80/rtmp/<fb-streaming-key>'

This is actually working, as Facebook receives the live video and allows me to publish it. But I can't figured out why there is a lag almost every 2 or 3 seconds. I asked different people to watch the test video, and everyone gets the same problem : every 2 or 3 seconds the playing "freezes" for half a second and seems to load the video, I even can see the loading icon spinning on the screen.

I tried different combinations of values for the following options : -thread_queue_size / -b:v / -minrate / -maxrate / -bufsize. Nothing seems to produce any change.

Video streaming is new for me, I'm not really confortable with the options listed before, so I think I'm missing something here...

Also, note that the icecast audio stream perfectly works, and according to DigitalOcean graphs, the server is not overloaded. So I think my ffmpeg command is wrong.

What ffmpeg parameters would be working for that case?

8
  • This is probably a quirk in how Facebook is handling your video stream. You might consider actually cranking up the bitrate of your video to 1 or 2 megabit and see what happens. I suspect there's something somewhere buffering on byte size rather than time.
    – Brad
    Jan 14, 2017 at 19:19
  • I already made tests with that kind of value for the bitrate, but to be sure I just run another test with the following values : ffmpeg -loop 1 -i radio-background.jpg -thread_queue_size 20480 -i http://localhost:8000/radio -framerate 30 -r 30 -acodec aac -strict -2 -c:v libx264 -strict experimental -b:a 128k -pix_fmt yuvj444p -x264-params keyint=60 -b:v 2048k -minrate 1024k -maxrate 4000k -bufsize 4000k -f flv 'rtmp://rtmp-api.facebook.com:80/rtmp/<fb-streaming-key> Result is exactly the same. This seems to change nothing.
    – Matthieu
    Jan 15, 2017 at 17:17
  • What if you leave off the -pix_fmt option?
    – Brad
    Jan 15, 2017 at 18:59
  • 1
    I have ffmpeg warnings if I try without that option. I think I found a solution : the jpg I was used was too big according to fb specs (1280*720 max). I resized that image to 1280*720 px and the result is much better. But there still are some freeze issues, around every 1 or 2 minutes. It's not perfect, and honestly for a radio it's not good enough. I'll try with different values for bitrate and buffer and see where it goes. But for now, the issue is only half fixed :s
    – Matthieu
    Jan 16, 2017 at 5:23
  • You should post that as an answer.
    – Brad
    Jan 16, 2017 at 5:23

1 Answer 1

0

specify a frame rate for the image. this would go before the input item.

-r 30 -loop 1 -i radio-background.jpg

if your radio stream is is already aac you can just stream copy, there is no need to re-encode the audio. you can use -c:a copy.

-c:a copy

if you still want to use aac you should switch to using libfdk_aac. ffmpeg by default uses 128k bitrate for audio so there is no need to specify -b:a

-c:a libfdk_aac

ffmpeg will use the input framerate of the first item for the output by default so you dont need to specify anymore frame rates. (you have the output frame rate specified twice. -framerate 30 and -r 30 are the same)

ultrafast preset for better CPU performance, tune, and pixel format. you can also use -g for the keyent.

-c:v h264 -preset ultrafast -tune stillimage -pix_fmt yuvj444p -g 60

set the profile and profile level, bframes

-profile:v high444 -level 4.2

use either -b:v or -minrate -maxrate -bufsize but not both.

-b:v 768k

and out we go

-f flv rtmp://rtmp-api.facebook.com:80/rtmp/streamkey

now to put it all together

    ffmpeg -r 30 -loop 1 -i radio-background.jpg \
-i http://localhost:port/mount -c:a libfdk_aac -c:v h264 -b:v 768k \
-preset ultrafast -tune stillimage -pix_fmt yuvj444p -g 60 \
-profile:v high444 -level 4.2 -f flv rtmp://rtmp-api.facebook.com:80/rtmp/streamkey

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.