mnd
mnd

Reputation: 2789

How to sign an RTMP url for Amazon CloudFront

I'm trying to create signed urls for an RTMP distribution in Amazon's CloudFront. I have the following working:

Main question - now that I'm trying to get a signed url for RTMP, it never seems to be playable.

Part of the confusion is based on the format of the url (similar to this question). So I don't know if it matters which part of the url I sign - if I sign the whole thing (like my http urls), or if I only sign a portion, and if I include the mp4: prefix in the path.

There seem to be a lot of pseudo-similar questions on Stackoverflow, but they seem to be related to slightly different issues, and not about actually creating a signed url for RTMP.

Upvotes: 0

Views: 702

Answers (2)

Florentin
Florentin

Reputation: 671

With Python/boto3, I've managed to sign media files with the rsa_signer

http://boto3.readthedocs.io/en/latest/reference/services/cloudfront.html#generate-a-signed-url-for-amazon-cloudfront

by signing only the path to the media file.

Let's say you want to stream an S3 bucket media file located at 'videos/test.mp4' Following the boto3 example from the link above, here's what you can do to serve the file with flowplayer:

signed_url = cloudfront_signer.generate_presigned_url(
    'videos/test.mp4', date_less_than=expire_date)

Then in the flowplayer code (Django template syntax):

<div class="flowplayer fp-slim" data-rtmp="rtmp://{{cloudfront_domain_prefix}}.cloudfront.net:1935/cfx/st">
   <video>
     <source type="video/flash" src="mp4:{{signed_src}}">
   </video>
</div>

Upvotes: 0

mnd
mnd

Reputation: 2789

Unfortunately there are many variations to how a RTMP url can be created, which caused a large portion of the confusion. The following is the way that I was able to get this to work with Amazon CloudFront. To be clear, this was to be used in a *.SMIL file, so it might be different if you only need a single url.

  1. The S3ObjectSummary object has a key for the file, which might be something like folder1/folder2/video.mp4.
  2. Use the above key, and remove the .mp4 extension.
  3. Sign the url as normal (I used CloudFrontService.signUrlCanned().
  4. In the *.smil file that is generated, set the base reference to rtmp://<CloudFront RTMP Distribution Domain>/cfx/st
  5. In the video element, set the height and width, and in the src attribute, prepend mp4: to the signed url portion.

Here is an example SMIL file.

<smil data-livestyle-extension="available">
    <head>
        <meta base="rtmp://some-cloud-front-domain.net/cfx/st"/>
    </head>
    <body>
        <switch>
            <video height="720" width="1280" src="mp4:<signed portion of video path>" />
            <video height="480" width="853" src="mp4:<signed portion of video path>" />
        </switch>
    </body>
</smil>

Upvotes: 1

Related Questions