One of the most common questions from our customers about vidyo.io is how to record video conference calls. The answer is simple: Record with the media bridge. In this article I’ll walk you through deploying and using the media bridge.
If you haven’t heard of Docker, check out “What Is Docker?” and “Building Applications with Dockerfiles.” In a nutshell, Docker is a container platform that allows developers to package an application and deploy it identically across multiple platforms or even cloud services such as Amazon AWS. No more “But it works on my machine!” problems. Docker lets the developer package the application along with everything it needs, like libraries, scripts, environment variables, and all its dependencies together in one stand-alone container. This guarantees the correct running environment for each deployment.The vidyo.io media bridge is a Docker image that is deployed with ease on your application’s server.
Using the media bridge, you’ll be able to:
- Record audio and video from a video conference call
- Stream or broadcast a call to an RTMP server
- Provide interconnectivity for SIP-enabled systems
You’ll continue to use vidyo.io SDK to add group video chat to your web/mobile/desktop application — no changes required there. However, if you want to take advantage of recording, broadcast, or interoperability, you can incorporate the media bridge into your application. As the name suggests, the media bridge allows you to build a bridge from your vidyo.io video conference to other destinations.
Adding Docker to your application back end and running the media bridge is straightforward. Follow the steps in the documentation and you’ll be good to go. We also recently conducted a webinar on this topic; you can check out the recording below.
Step 1. Set Up AWS EC2 to Run the Media Bridge
Docker is in no way, shape, or form limited to AWS, and you can deploy it on any Linux, Windows, or other popular cloud server service. I picked AWS because it’s one of the most popular cloud services, it offers a free tier so you can try the setup at no cost, and it provides first-class Docker support via the EC2 Container Service (ECS), which can be easily scaled to meet your demands.
From the list of Amazon machine instances, select the Amazon Linux machine, which is eligible for the free tier. You’ll see in the description that it already includes some useful command line tools and the Docker repository.
Next, for the instance type, choose t2.micro, which is also eligible for the free tier.
We won’t be changing anything in the default options for Instance Details, Storage, or Tags, so you can click “Next” until you get to the “Configure Security Group” section.
For our media bridge to connect to a video conference call and receive media packets we’ll enable all the ports for TCP and UDP. Let’s create a new security group, give it a name, and add all TCP and UDP traffic. Click the blue “Review and Launch” button.
From the “Review Instance Launch” page, click the blue “Launch” button. You’ll get a dialog box asking you to pick a key pair. Using this key pair we’ll be able to connect to our EC2 instance over SSH. Select “Create a new key pair” from the drop-down, give the key pair a name like vidyoMB-ec2-key-pair, and click “Download Key Pair.” Save this .pem on your drive, because once you close this dialog box you won’t be able to access it. After you download the key pair, the blue “Launch Instance” button will become active.
Click on the blue “View Instances” button to check the status of your instance.
If everything looks good, you’re now ready to connect to your cloud server to deploy the media bridge instance.
Step 2. Deploying the Media Bridge
To deploy the media bridge on our EC2 instance, we’ll first connect to our instance using SSH. Open a terminal and go to the folder where you saved your key pair. Set read-only access to the key pair file using chmod:
Note your instance’s public IP address from your AWS console (Public DVS IPv4 field in your instance description). Then SSH to it using the following command:
If everything goes well you’ll see something like this:
__| __|_ )
_| ( / Amazon Linux AMI
To install Docker, run the following command:
[ec2-user]$ sudo yum install -y docker
[ec2-user]$ sudo service docker start
Once Docker is installed, you can pull the latest media bridge version and run a container with the following commands:
[ec2-user]$ sudo docker run -d --name my_mediabridge vidyo/mediabridge
And there you go. You now have a media bridge instance ready to connect to your video call!
Step 3. Create a Simple Web Service
Now you have the media bridge instance deployed and you’re almost ready to connect to a call.
Before it can connect it needs three things:
- A valid token
- The name of the resourceId to connect to
- A destination, whether it is going to record, stream, or connect to a SIP gateway
All of this information, along with some other parameters, needs to be set in the config file of the media bridge and saved under /opt/vidyo within the container. You can find sample config files at https://developer.vidyo.io/documentation/4-1-19-7/getting-started.
In our case we’re going to set our media bridge to record a video conference. Instead of statically setting the parameters in the config file, we’re going to create a web service that will have a method called “record” that will take in the conference room name to join. We’re going to create a web service using python and web.py. Note that we need to install the dependencies inside the my_mediabridge container that we created in the previous step. To do that you can run bash to get to the container shell:
Now that you’re in your container, install web-py to this Docker image:
$ apt-get install -y python python-webpy
Within the container, create a new python script:
$ vi /home/webapp/app.py
from datetime import datetime
import calendar, time
urls = (
app = web.application(urls, globals())
# Developer specific parameters copy it from your vidyo.io dashboard
VIDYO_IO_DEVELOPER_KEY = XXXXX
VIDYO_IO_APPLICATION_ID = YYYYY
TOKEN_VALID_DURATION_SECS = 600
EPOCH_SECONDS = 62167219200
type = 'provision'
key = VIDYO_IO_DEVELOPER_KEY
jid = "recorder@" + VIDYO_IO_APPLICATION_ID
expires = TOKEN_VALID_DURATION_SECS + EPOCH_SECONDS + int(time.mktime(datetime.now().timetuple()))
vCard = ""
sep = b"\0" # Separator is a NULL character
body = to_bytes(type) + sep + to_bytes(jid) + sep + to_bytes(expires) + sep + to_bytes(vCard)
mac = hmac.new(bytearray(key, 'utf8'), msg=body, digestmod=hashlib.sha384).digest()
## Combine the body with the hex version of the mac
serialized = body + sep + binascii.hexlify(mac)
b64 = base64.b64encode(serialized)
token = b64.encode("utf8")
encoded_token = urllib2.quote(token)
def GET(self, roomId):
encoded_token = getVidyoIOToken()
os.system ("cp /home/webapp/config /opt/vidyo")
with open("/opt/vidyo/config", "a") as myfile:
myfile.write("resourceId="%s"\n" % (roomId))
myfile.write("token="%s"\n" % (encoded_token))
os.system ("/opt/vidyo/connect &")
if __name__ == '__main__' :
app = web.application(urls, globals())
Create a sample config file in the webapp folder:
presentationAllowed=1 #0 - ignore presentations 1 - replace main video with presentation
#vidyo.io connection info
Note that we did not set the token or resourceId parameter in our template config file, since our web service will set it in the record method.
Now that we have everything set up in our container, let’s go back to the EC2 instance:
We’ll create a new image from the Docker container we just modified and name it “simple_record_ws”:
You can confirm that the image was created by calling Docker images:
REPOSITORY TAG IMAGE ID CREATED SIZE
Simple_record_ws 0.1 6a9cbe31b862 2 minutes ago 5.54GB
vidyo/mediabridge latest afa973ff5c05 2 months ago 5.51GB
Finally, start your web service by calling:
The -p 80:5000 flag in the run command above tells Docker to link port 5000 on the Docker container to port 80 on the EC instance.
Step 4. Testing Your New Web App
We have now successfully deployed the media bridge on the cloud, and it’s just waiting for someone to call it with the record command so that it can start recording a video conference. Let’s test it out.
Go to https://developer.vidyo.io/demo and launch an instance. Note that you should be signed in to the same account you used to copy the developer key and app Id values.
By default the demo sample on the demo page joins the room named demoRoom. Try signing in from different machines so you have multiple participants on the call.
Copy your EC2 instance public IP address, open a browser, and enter the following:
A page will open with the text “demoRoom,” but, more importantly, you’ll notice on your video conference a message that Recorder/Streamer has joined.
Your recorder is working. Once every participant leaves the call, the recorder will automatically stop. You can copy the recording:
Open another terminal in the same folder where your key pair is and copy the recording from your EC2 instance to your local computer using the following command:
There you go. You’ve built a simple web service that will record your vidyo.io conferences on command. One of the cool things about using the EC2 service from Amazon is that you can easily scale your service to deploy multiple containers on demand to record or stream a number of conferences in parallel. In our example we deployed one container to record one conference, but you can use Amazon’s cluster service ECS Console to manage your containers.
If you have any questions, comments, or suggestions on topics we should cover on our how-to blogs, feel free to reach out to me at email@example.com.