Amazon Cloudfront Private Streaming Example

Update August 2012:
With Amazon servers it is possible to stream videos for Flash and HTML5 video players. So you can view private protected videos on all browsers, mobile phones, ipads and other tablets.
More information: Private Protected Video with Amazon Servers

 

Amazon Cloudfront streaming servers with private URLs have just been online for a few weeks. Therefore there is not much information available nor are there many code examples.

Here are a few links to explaining websites and a working PHP code example.

I hope this helps some other developers 🙂

Amazon Documentation
Amazon Forum
Cloudberry HowTo
Bucket Explorer HowTo

>>> Download Code Example:
>>> cloudfront_private_streaming_example.zip

Tags: , , , , ,

  1. Flint sagt:

    I really appreciate the code that generates the signing but am I bit perplexed as to how this example then plays the content as theres not evident JS. Unfortunately that is where I’m still having problems. I was hoping to use it with Flowplayer but am about to abandon those efforts as it seems very buggy. What do you use as the player for those generated urls?

  2. admin sagt:

    I use the JW player from http://www.longtailvideo.com/
    They just released a version that accepts URLs for Amazon private streaming. I’m not sure that Flowplayer already has a version that works.

    I included the player in the ZIP file so you can download it again.

  3. Jared sagt:

    This is awesome! Really helped me get my videos working with private streaming!

    I switched the code from one server to another and it stopped working though…. is your code php5 only perhaps? (Got a „Stream not found“ error in the jw player.)

  4. admin sagt:

    @Jared:
    Good, that others think this is useful! It took me quite some time to find out.

    I didn’t test the code on PHP4 (it’s not supported anymore …). But I don’t think there is any special PHP5 code.

    Maybe OpenSSL is not included? But then you should get an error using the function openssl_get_privatekey.

    Did you check if $urlcloud looks OK?

  5. Jared sagt:

    Good tip! The signature part of the url was not getting generated. In PHP5 for openssl_sign(), the signature_alg (OPENSSL_ALGO_SHA1) parameter was added. I removed it and it works like a charm!

    You are right about there not being much out there…. I gratefully stumbled onto your blog post after a nearly all night search and digging through Amazon’s API reference to get a private streaming demo working. Thanks again!

  6. Eddie sagt:

    Thanks a lot ! if you have an update/extra features would be great!

  7. Checkmark sagt:

    Fantastic!! Your code is very well documented and fairly easy to follow. Thank you so much for providing this excellent help.

  8. Victor sagt:

    Hi,

    I used your code as a reference and all worked well except for getting the mp3 to play in a jwplayer.

    Here is an example of the player config I use, but it does not play. Any ideas?

    When I put the unsigned version of the same mp3 it does work. I am using the latest version of jwplayer – 5.2

  9. Victor sagt:

    The code in the embed is:

    type=’application/x-shockwave-flash‘
    id=’single2′
    name=’single2′
    src=’player.swf‘
    width=’470′
    height=’24‘
    bgcolor=’undefined‘
    allowscriptaccess=’always‘
    allowfullscreen=’true‘
    wmode=’transparent‘
    flashvars=’file=bunny.mp3%3FExpires%3D1278601480%26Signature%3DSWvtYfiYrKBgSMutFlh4dDA6m1CwWxAzShhnO0NTt56qmLHrO3JYtnEaznZA95xMlOEZdIUZIIqUT80gPEBu5GhodiZztCmbSVwtxKgoVb-F8fv4-3gLp2RscBYUhUOWFt6vkbv9w01B9AQd9X6UjI085fFoOMiBDYuHP1Gm4Zc_%26Key-Pair-Id%3DAPKAIXJUVQ5QFEOUJMDA&streamer=rtmp://s7u5y1j8ivhpl.cloudfront.net/cfx/st/‘

  10. Dipen sagt:

    Guys,

    I tried the example and also i removed the part
    $res = openssl_sign($policy_str, $signature, $pkeyid, OPENSSL_ALGO_SHA1);

    But signature is not generated. Can you please help me to sort it out.

    http://qwikinet.com/demo/chemsmart/new/cloudfront_private_streaming_example.php

  11. admin sagt:

    You remove one line of code and then you think it should still work? A very strange way of thinking. Of course you need this line of code.

  12. John sagt:

    Works wonderful, except that the expire time is not respected for some strange reason.
    When you set the expire time to 10 seconds and wait to click on the video until 10 seconds have passed, you normally get an access denied error.
    But not in this case. In fact, it takes a very long time before access is denied.

    I set this: strtotime(„+10 seconds“);
    I tried an alternative: time() + 10;
    Both give the same result, expiring time doesn’t seem to happen in the first hour or so. Perhaps there is a big difference between AWS:EpochTime and time in Europe? Is that perhaps the problem?
    Here is the url of my test page: http://test.raboo.com/streamprivate/test.php

    Any suggestions?
    Thanks beforehand.
    John

  13. John sagt:

    It’s OK, I found another solution to fix this. Thanks in any case.

  14. Sergey sagt:

    Thank you very much for sharing your solution – it works great!

  15. ExtremeBt sagt:

    Hi,

    Thanks for the example, but:

    I’ve tested the php code and video streaming can work with wrong parameters (keypairid, privatekeyfile). Any idea? I’m setting the timestamp +10 seconds for testing. The permission in S3 where CloudFront streams has to be: Authanticated Users?

    Please help!
    Thanks in advice

  16. admin sagt:

    @ExtremeBt : When you can access the files with wrong parameters then there is something wrong with the authentication rules in Cloudfront.
    You must set the ACL in S3 so that only Cloudfront may read your S3 files and Cloudfront must be private.

  17. Mario sagt:

    Your tutorial saved my life. But I do have to ask. Is this data still needed today? Dont get me wrong. I have played several days to the private video streaming to work and with your tutorial I found an answer. But it still looks very difficult – you have to do a lot of steps … So I was wondering is there a possibility to skip the whole EC2 part and just get it to work with cloudfront.

    I hope you are still in the business of video streaming.

    All he best from Austria – Mario

  18. Emile Schenk sagt:

    @Mario: There is no EC2 part so you cannot skip it. The solution is only based on cloudfront.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.