Live Transcoding with Open Source Cloud

As live streaming continues to grow in popularity across various platforms, building a scalable, resilient, and cost-effective architecture is essential for broadcasters and content providers. Whether you’re streaming live sports, news, or entertainment, ensuring that your content reaches audiences globally with minimal latency and interruptions is critical.

With Open Source Cloud, you can build a live streaming architecture that leverages open-source components to offer scalability, resilience, and customization — all at a lower cost.

Live Transcoding and CDN pull stream

In this scenario the CDN pulls the stream from the encoder instance in Open Source Cloud. We strongly recommend to place a CDN origin shield between the CDN distribution nodes and the encoder instance acting as origin.

This tutorial walks you through how to setup live transcoding using Open Source Cloud.

Prerequisites

  • If you have not already done so, sign up for an OSC account.
  • Be on a paid subscription plan.

For best guaranteed performance we recommend purchasing a reservation for at least 1 single premium node (200 EUR per month) but not required to getting started.

Step 1: Setup secrets

Go to the web user interface and navigate to the service called Eyevinn Live Encoding. Click on the tab Service Secrets and the button New Secret.

Create a secret called streamkeya containing mysecretkey. This will be the stream key the live production software will need to be able to push the stream to the encoder.

Step 2: Create encoder instance

In the web user interface click on the button “Create encoder +” and enter the following in the instance creation dialog.

  • Name: guide
  • HlsOnly: true
  • StreamKey: {{secrets.streamkeya}}

You will create one encoder instance for each live stream you want to distribute.

Step 3: Start encoder

Once the instance is up and running you can use the provided web user interface to start and stop the encoder.

Click on the instance card to open the web user interface and for automation and integration with API you find the live API documentation by clicking on the menu item Open API Docs.There you are presented with a web based REST API client ready to use.

To start the encoder click on the button START ENCODER. When the encoder is in status “starting” it is ready to receive the stream.

On the service card you find an IP and port in the format IP:PORT and these values are used when configuring your live production software (for example OBS). For example you enter rtmp://IP:PORT/live/mysecretkey as the stream destination in OBS.

As soon as the stream is being received by the encoder you will find a video playing the encoded stream.

Step 4: Watch the stream

You can play the HLS stream directly from the origin by opening an HLS capable video player to the address returned by the OSC tool. In this example it was https://demo-guide.eyevinn-live-encoding.auto.prod.osaas.io/origin/hls/index.m3u8.

Step 5: Stop the stream

When the live event has been completed you stop the stream in the live production software and when that is stopped you can stop the encoder by clicking on the button STOP ENCODER.

Step 6: Configure CDN

Configure your CDN and CDN origin shield to fetch the stream from the URL that you tested with your video player as a media origin.

Contact form and CAPTCHA backend in Open Source Cloud

With an open source backend service for form collection and CAPTCHA handling you can implement a contact form with spam protection without developing your own backend services for this. These backend services are also available in Open Source Cloud so you don’t have to host these backend services yourself either.

In this blog I will describe how you can quickly get a contact form where the message is sent to a Slack channel.

Create a Slack Bot

The Slack Bot will be the one posting the message to the channel in Slack. Visit https://api.slack.com/apps/ and create a new app with the permissions to post to the desired Slack channel.

Save the Slack Bot token as this will be used later in this tutorial.

Create form backend service in Open Source Cloud

Login to or signup for an account at Open Source Cloud.

Navigate to the Contact Form Service and click on the tab Service Secrets. Click on New Secret and add a secret that contains the Slack Bot token obtained earlier.

Image description

Create a contact form service by pressing the Create service button.

Image description

Give the service a name and select slack in the transport dropdown. Provide the service secret holding the token and enter the ID of the channel where the message should be posted.

Image description

When the service is up and running you can copy and save the URL to the contact form service.

Contact form example in React

Develop your contact form in your frontend application which in React could look something like this. Replace BACKEND-SERVICE-URL with the URL acquired above.



'use client';
import { Input, Textarea } from '@nextui-org/react';

export default function Page() {
  const handleSubmit = (formData: any) => {
    fetch(new URL('BACKEND-SERVICE-URL/contact'), {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: new URLSearchParams(formData).toString()
    });
  };

  return (
    <form action={handleSubmit}>
      <Input name="firstname" placeholder="First name" />
      <Input name="lastname" placeholder="Last name" />
      <Input name="email" placeholder="Your email" />
      <Textarea
        name="message"
        minRows={8}
        placeholder="Tell us a bit about what you want our help with"
      />
      <Input type="submit" value="Send" />
    </form>
  )
}
When the form is submitted you should now get a message in your Slack channel. To prevent spam-bots to misuse this form we need to add a CAPTCHA. CAPTCHA is an acronym that stands for "Completely Automated Public Turing test to tell Computers and Humans Apart."

To provide this functionality we will use an open source CAPTCHA backend service to generate and verify CAPTCHA. How it works is that you generate a CAPTCHA image that displays a text. Then you ask the user (human) to provide the text that he or she sees and the backend will verify that this was the text shown in the image.

Create CAPTCHA backend service in Open Source Cloud

Navigate to the CAPTCHA Service and click on the button Create service.

Image description

Give the service a name and once the service has started copy the URL to the service. Replace CAPTCHA-SVC-URL below with this URL.

Add CAPTCHA verification to your form

Extend the form we created above with the following code.



'use client';
import { Input, Textarea } from '@nextui-org/react'; 

export default function Page() {
  const [captchaSvg, setCaptchaSvg] = useState<string | null>(null);
  const [captchaId, setCaptchaId] = useState('');
  const [captcha, setCaptcha] = useState('');
  const [invalidCaptcha, setInvalidCaptcha] = useState(true);

  useEffect(() => {
    fetch(new URL('/captcha', 'CAPTCHA-SVC-URL'))
      .then((response) => response.json())
      .then((data) => {
        setCaptchaSvg(data.svg);
        setCaptchaId(data.id);
      });
  }, []);

  const onCaptchaChange = (value: string) => {
    setCaptcha(value);
    fetch(new URL('CAPTCHA-SVC-URL/verify/' + captchaId + '/' + value))
      .then((response) => {
        setInvalidCaptcha(!response.ok);
      })
      .catch(() => {
        setInvalidCaptcha(true);
      });
  };

  const handleSubmit = (formData: any) => {
    fetch(new URL('BACKEND-SERVICE-URL/contact'), {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: new URLSearchParams(formData).toString()
    });
  };

  return (
    <form action={handleSubmit}>
      <Input name="firstname" placeholder="First name" />
      <Input name="lastname" placeholder="Last name" />
      <Input name="email" placeholder="Your email" />
      <Textarea
        name="message"
        minRows={8}
        placeholder="Tell us a bit about what you want our help with"
      />

      {captchaSvg && (
        <Image src={captchaSvg} className="bg-white" alt="Captcha" />
      )}

      <Input
        name="captcha"
        placeholder="Enter the text from the image"
        description="This is used to prevent automated submissions."
        required
        maxLength={4}
        value={captcha}
        onValueChange={onCaptchaChange}
      />
      <Input type="submit" value="Send" isDisabled={invalidCaptcha} />
    </form>
  )
}


Conclusion

This was an example on how you can add to your web application a contact form with CAPTCHA verification that posts to a Slack channel without having to build or host your own backend services for it.

What is Open Source Cloud?

Open Source Cloud reduces the barrier to get started using open source and reduces the barrier for creators to make their software available as a service. Read more about why we developed it in this post.