How to live stream on facebook via ffmpeg?

K. Talha picture K. Talha · Aug 17, 2016 · Viewed 15.8k times · Source

I am trying live streaming on facebook via ffmpeg but I get one error. As the error, I must use AAC instead of mp3. But I don't know how to do it.

Error: Bad audio codec 2 (MP3). Accepted audio codecs: AAC

Normally, I can run command below for youtube succesfully.

ffmpeg -i "rtmp://..." -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset medium -r 30 -g 60 -b:v 2500k -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv "rtmp://a.rtmp.youtube.com/live2/key"

But when I run command below with facebook rtmp, error gets.

ffmpeg -i "rtmp://..." -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset medium -r 30 -g 60 -b:v 2500k -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv "rtmp://rtmp-api.facebook.com:80/rtmp/key"

I am user of Ubuntu 14.04.

Thanks in advance.

Answer

Zs File picture Zs File · Oct 13, 2017

In your ffmpeg command, you have this:

-acodec libmp3lame

This is encoding the audio stream into MP3. You'll need to change that. You might need to use something like this:

-acodec libfdk_aac

https://trac.ffmpeg.org/wiki/Encode/AAC

To reference Facebook's "Live Video Specs" from https://www.facebook.com/facebookmedia/get-started/live:

The Live API accepts H264 encoded video and AAC encoded audio only.