3

I am trying to stream a webpage to Facebook Live video using ffmpeg. I know I can use OBS, but I'm trying to do it from a server, so I can't go with OBS. It works fine when I'm previewing, but as soon as I press 'Go live', at first it seems like it's starting, but then when it takes me to the live view it just says that the video has ended. I even checked the error of the video log using Graph API, nothing. I'm using PhantomJS to pipe screenshots to ffmpeg:

phantomjs phantom.js | ffmpeg -y -c:v mjpeg \
-f image2pipe \
-r 5 -i \
- -c:v libx264 \
-x264-params keyint=5 \
-b:v 1000k -minrate 1000k -maxrate 1000k -bufsize 500k \
-f flv 'rtmp://rtmp-api.facebook.com:80/rtmp/xxxxxxxxxxxxxxxx'

As I said, it's working fine in the preview of the live stream on Facebook, but just ends immediately when I go live. I added the bitrate options to try to keep a constant bitrate as mandated by Facebook (https://developers.facebook.com/docs/videos/live-video/production-broadcasts), and I have a keyframe every 5 frames (rather low frame rate at 5fps) so that requirement is fulfilled as well.

I'm not sending any audio, could that cause a problem?

  • I'm having exactly the same problem. I'm also not sending any audio. Preview works, but when I press "Go Live" it takes a while and then shows the video has ended. Shortly after ffmpeg will stop. – BugHunterUK Nov 17 '16 at 13:46
  • Tried adding audio, no luck. I'm thinking this actually has to do with the framerate varying slightly due to the live processing, trying to find ways to get around that so ffmpeg can pull images at the exact right moment – Einar Magnússon Nov 17 '16 at 17:37
  • I got it working with this: https://gist.github.com/JamesTheHacker/56fb9caf36244de582540e7d5c2fd6a5 – BugHunterUK Nov 17 '16 at 18:02
  • @BugHunterUK 404'd – bumpkin Feb 11 '18 at 16:16
  • @bumpkin Sorry, it's because I changed my username on github. Here it is: https://gist.github.com/JamesJefferyUK/56fb9caf36244de582540e7d5c2fd6a5 – BugHunterUK Feb 12 '18 at 13:12

1 Answers1

1

Facebook Live requires a frame rate of 30 FPS. You're sending it 5, so you'll need to convert up. You also need a keyframe interval of 2 seconds max. Try adding an output frame rate:

phantomjs phantom.js | ffmpeg -y -c:v mjpeg \
-f image2pipe \
-framerate 5 \
-i - \
-r 30 \
-c:v libx264 \
-x264-params keyint=60 \
-b:v 1000k -minrate 1000k -maxrate 1000k -bufsize 500k \
-f flv 'rtmp://rtmp-api.facebook.com:80/rtmp/xxxxxxxxxxxxxxxx'
llogan
  • 121,796
  • 28
  • 232
  • 243
Brad
  • 159,648
  • 54
  • 349
  • 530
  • Still not working, outputs at low framerate. can you help. – bhargav joshi Nov 17 '16 at 18:20
  • 1
    @bhargavjoshi If you don't have audio add silence `-f lavfi -i anullsrc` & `-c:a aac` (might be BS but some seem to expect or require audio). You also may need to use YUV 4:2:0, so add `-pix_fmt yuv420p` as an output option, and try using `-re` with your inputs. – llogan Nov 17 '16 at 19:03
  • @bhargavjoshi Can you output to a file to verify that the output is 5 FPS and not 30? And can you show the order of your parameters? The `-r 30` needs to be after the specification of STDIN and before the output URL. – Brad Nov 17 '16 at 20:51
  • @bhargavjoshi did you figure this out? – bumpkin Feb 11 '18 at 16:15
  • 1
    @bumpkin yes it required to add some audio and then it worked. – bhargav joshi Feb 14 '18 at 03:49