FFMpeg HLS

FFMpeg is a complete, cross-platform solution to record, convert, and stream audio and video.

FFMpeg is one of the best and most popular open-source software choices for server-side video processing.

This documentation section will show you how to save your HLS stream to the Tebi Cloud directly from the FFMpeg. We will use this sample video file stored in Tebi Storage to create an HLS stream and save it to the Tebi Cloud storage.

The produced HLS stream will have a latency of around 30 seconds.

Prepare Your Tebi Account

Create a bucket to store our HLS video stream. FFMpeg will write HLS stream directly into this bucket. Let’s name it ffmpeg-hls-test.

For simplicity, let’s configure our bucket default permission (ACL) to Public. This will make all files that FFMpeg will put into the bucket publicly accessible without a signature. Open bucket preferences, then open the Access Control tab. Select Public for the DataStream Default ACL option and save the form by clicking the Update button.

Allow FFMpeg to write to the bucket without authentication. Open bucket preferences and select the Bucket Policy tab. Check the Enable checkbox to enable Policy for this bucket and put the following JSON policy into the JSON field:

 1{
 2  "Version": "2012-10-17",
 3  "Id": "FFMpeg",
 4  "Statement": [
 5    {
 6      "Sid": "DSAllow",
 7      "Effect": "Allow",
 8      "Action": [
 9        "ds:PutObject", "ds:DeleteObject"
10      ],
11      "Resource": "*",
12      "Condition": {}
13    }
14  ]
15}

Save the form. Now, we have a bucket that is ready to receive data from FFMpeg and distribute it to clients for unrestricted playback. This is a very simple Bucket Policy example. For the production deployment, we suggest you limit this policy by IP address so that only you can upload and delete data in the bucket. You can read more about Bucket Policy here.

If you plan to play your stream in the web player from a different domain, enable Cross-Origin Resource Sharing (CORS) to allow your web-browser JavaScript code to access resources located in your bucket. To do this, open bucket preferences and select the CORS tab. Check the Enable checkbox to enable CORS for all domains and leave the XML textbox blank. Save the form to apply changes. You can read more about Bucket CORS here.

FFMpeg Command Line Parameters

This is a very simple FFMpeg command that will take a sample video from our storage and remux (convert) it to an HLS stream without transcoding. This is done very quickly, and you do not need a powerful CPU to do it.

ffmpeg -re -i https://s3.tebi.io/test/examples/bbb_1080p_30fps.mp4 \
-c:v copy -c:a copy -method PUT -http_persistent 1 \
-hls_time 6 -hls_flags delete_segments \
-f hls https://ffmpeg-hls-test.datastream.tebi.io/test.m3u8
  • -re: Used to process the source video at the native frame rate to simulate a video stream.

  • -i https://s3.tebi.io/test/examples/bbb_1080p_30fps.mp4: Specifies the location of the video to be processed.

  • -c:v copy -c:a copy: Copy video and audio stream without transcoding.

  • -method PUT: Use HTTP PUT method to upload data to the server.

  • -http_persistent 1: Use persistent HTTP connections.

  • -hls_time 6: Set segment length to 6.

  • -hls_flags delete_segments: Delete segment files that are no longer part of the playlist.

  • -f hls: Set video output format to HLS.

  • https://ffmpeg-hls-test.datastream.tebi.io/test.m3u8: Target URL where to upload the data.

After FFMpeg is started, give it a minute to prepare and upload a couple of video segments to the storage. You can watch your stream using your favorite HLS player here: https://ffmpeg-hls-test.s3.tebi.io/test.m3u8.

Note

This documentation section section is designed to be as simple as possible to quickly get you started with FFMpeg and Tebi Cloud. There are many more FFMpeg command line parameters available to cover all possible use-cases. Please, contact our support team if you need any additional help.

See Also