How to create a Facebook Live with real-time reaction counters

Many have written to us in order that we help them broadcast via Facebook Live with real-time reaction counters using linux, For those who do not know, it is a boom that is manifesting itself in this social network, where each reaction is converted into a number that then added to others generates a counter.

In search of a solution to the need of some users, I have been researching and I got an excellent script and usage guide called Facebook Live Reactions, which meets this objective and uses a linux server to work. I have given myself the task of translating, improving and adding the dependencies facilities of the script, so that all of you can enjoy it.

What is Facebook Live Reactions?

Facebook Live Reactions, is an open source script made in php, which allows you to create Facebook Live Streams with reaction counters in real time. It also includes an interactive feature that gives live shoutouts to users who entered "shared" in the comment box.

Similarly, it has a series of predetermined shoutouts that can be configured, which are shown on the screen, with the fan page account. You can get the original repository for this script here..

Facebook live

Installing Dependencies of Facebook Live Reactions

  • Linux / OS X (For testing I used Ubuntu 14.04 on Amazon AWS EC2 Server).
  • PHP 7 + (Although the developer says it should work in 5.6, it didn't work for me).
$ sudo add-apt-repository ppa: ondrej / php $ sudo apt-get update $ sudo apt-get install php7.0
  • PHP GDImageMagick (I used PGP GD for php 7.0)
$ sudo apt-get install php7.0-gd
  • ffmpeg
$ sudo add-apt-repository ppa: mc3man / trusty-media $ sudo apt-get update $ sudo apt-get install ffmpeg
  • composer
$ sudo apt-get install curl $ curl -sS https://getcomposer.org/installer | php $ sudo mv ~ / composer.phar / usr / local / bin / composer
  • Inkscape (If you want to modify the image) *
  • youtube-dl (To download the audio of the broadcast, you can use the audio you want, the broadcast will last as long as the audio lasts. *
  • sox (to generate a new audio file, repeating the original audio n number of times). *
$ sudo apt-get install sox libsox-fmt-all

Installing Facebook Live Reactions

You can install it both on your computer and on a server. I recommend

Clone the repository

git clone http://github.com/JamesTheHacker/facebook-live-reactions
cd facebook-live-reactions

Install dependencies with composer

composer install

Setting up Facebook Live Reactions

For Facebook Live Reactions to be able to transmit correctly, we must perform the following settings:

Adding audio to the file

 Facebook Live requires an audio stream, which has not been included in the repository, as it would increase the size. The audio file must be a maximum of 4 hours long (Facebook video streams can only last 4 hours). If the audio file is shorter, streaming will stop when the audio ends.

With the help of youtube-dl we can download the audio of a video from youtube:

youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=15uF7r2rCQk

This will download a .mp3 of the video. In this case music to increase concentration while programming.

We rename the downloaded audio to audio.mp3

mv "Concentration  Programming Music-0r6C3z3TEKw.mp3" audio.mp3

The audio lasts just over an hour. If you need the audio to be 4 hours, we have to produce a new cyclic audio, with the help of sox.

sox audio.mp3 audio-loop.mp3 repeat 4

This will take a while to produce the new audio audio-loop.mp3 . Copy audio-loop.mp3 In the address book data.

Editing the configuration

Before modifying the settings, you must create a Facebook application, in case you don't have one, you can create it from here. The application is used to connect to the Graph API to get reactions and comments from the video. When configuring the application you only need to provide basic information.

All settings are stored in file settings.php . For the script to work, you will only have to modify the following fields:

'POST_ID'       => '',
'ACCESS_TOKEN'  => '',
'APP_ID'        => '',
'APP_SECRET'    => ''

Once you have the application configured, you should get the 'ACCESS_TOKEN', which you can do from the  Access Token Tool. Enter the information in the corresponding field, together with the app ID and the app secret.

El POST_ID it can be ignored as we will get it when we create the live stream.

Creating the live stream

After you have configured the script, you must create a new live feed on Facebook. Go to a facebook page, click the «Publishing tools»And then click«Videos«. Press the "Live" button and wait for the popup to load. free facebook settings

Next you should see the field «Server or streaming URL«. Copy this URL and paste it at the end of the file fblive.sh. You must place it inside the quotes "..."

ffmpeg \
-re -y \
-loop 1 \
-f image2 \
-i images/stream.jpg \
-i data/audio-loop.mp3 \
-acodec libfdk_aac \
-ac 1 \
-ar 44100 \
-b:a 128k \
-vcodec libx264 \
-pix_fmt yuv420p \
-vf scale=640:480 \
-r 30 \
-g 60 \
-f flv \
"rtmp://rtmp-api.facebook.com:80/rtmp/1343774358979842?ds=1&s_l=1&a=AaaWtwcn05wdmMCp"

Open a new terminal, navigate to the root directory, and run the following commands:

cd ~ chmod + x fblive.sh ./fblive.sh

This will start the transmission. Press the button "siguiente»And wait for Facebook to recognize the live broadcast.

By default, a blank image will be played. You won't see the reactions or shoutouts yet. This is because we have not started the other script to update the image yet.

Once the stream is loaded in the preview, press "Cast". Another popup should appear containing video statistics. On this page there is a link «see permanent link». Click and it will take you to the Facebook post containing the live feed.

In the URL there is a unique ID consisting of a bunch of numbers. Copy this ID and paste it in settings.php, in the field corresponding to 'POST_ID':

'POST_ID' => '90823402348502302894',

With this everything is almost finished.

Updating reactions and shoutouts

Open another terminal, go to the root directory and run the following command:

php fblive.php

This will run silently. Don't stop the process! Every 5 seconds it counts the reactions and updates the live broadcast. It will also take the last comment that contains the word «share»And will give a random shoutout to that user.

Everything ready, the transmission should be in saw. Leave a reaction, or write the word «shared»In the comment and wait for the video to update. live-desdelinux

How to modify the default Shoutouts?

Something that we can modify is the shoutouts that comes by default and that are shown in the image as if the fanpage wrote it. To do this, simply modify the file  settings.php try to use short sentences, so that it can be shown correctly in the image.

Following all these steps, we will be able to transmit an image with background audio, where the reactions of the video will be reflected. It is a quick and easy process that can have many uses.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.