Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
sullvanindy
Visitor

How to use AWS S3 hosted videos in feed

So, I am setting up a channel for someone who is hosting all videos on AWS S3. Can someone explain how to authenticate the video urls?

I have tried this which I grabbed from using chrome S3 plugin after clicking download:

<streamUrl>http://s3.amazonaws.com/bucket/path/video1.mp4?AWSAccessKeyId=accesskey&Expires=1426102991&Signature=jM3oDgkK8LdJiSVrpfhyWv6oLks%3D</streamUrl>

But the & seems to cause a parse error in the XML feed, I then tried just the key:
<streamUrl>http://s3.amazonaws.com/bucket/path/video1.mp4?AWSAccessKeyId=accesskey</streamUrl>

Which works, but only if I have use my chrome plugin to request a download of the file..

What is the proper way to stream S3 hosted videos?

Thanks..
0 Kudos
7 REPLIES 7
TheEndless
Channel Surfer

Re: How to use AWS S3 hosted videos in feed

& is a reserved character in XML. You need to XML encode it as &amp;
<streamUrl>http://s3.amazonaws.com/bucket/path/video1.mp4?AWSAccessKeyId=accesskey&amp;Expires=1426102991&amp;Signature=jM3oDgkK8LdJiSVrpfhyWv6oLks%3D</streamUrl>
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
sullvanindy
Visitor

Re: How to use AWS S3 hosted videos in feed

Thanks, so do I need to programmatically create the expires date/time and insert it in the feed somehow, or is there a way to authenticate globally in the beginning and not worry about it down the feed?
0 Kudos
TheEndless
Channel Surfer

Re: How to use AWS S3 hosted videos in feed

I'm afraid I don't know the answer to that one. S3 probably has some documentation on it somewhere.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
rarebrds
Channel Surfer

Re: How to use AWS S3 hosted videos in feed

As a side note, S3 is meant for storage mostly, it is not a CDN and not designed for sustained throughput (although it definitely can). You should look into setting up AWS CloudFront with your S3 bucket as the origin.
0 Kudos
sullvanindy
Visitor

Re: How to use AWS S3 hosted videos in feed

Ok, no answers so I gave up with the brightscript bit, couldn't figure out how to do the base64_encode part in brightscript. So I hosted my XML feeds on a linux host and created a PHP page that produces the category feed and runs a function that creates the signed AWS S3 expiring links based upon work by Tournas Dimitrios https://tournasdimitrios1.wordpress.com/2012/12/04/how-to-create-expiring-links-for-amazons-s3-with-.... Only a few tweaks to the function to switch the organization of the URL and use &amp; instead of &'s for the XML. The result turned out nicely, just fill in the variables with your specific info and Video files and point the categories feed to the php page.

Category1.php

<?php

// Set header content type for XML for proper browser render
header('Content-Type: text/xml');

// ** EDIT VARIABLES BELOW **

// Set Variables
$genre = "Documentary";
$type = "Video";
$bucketName = "Your S3 Bucket" ;
$awsAccessKey = "Your AWS Access Key" ;
$awsSecretKey = "Your AWS Secret Key" ;

//Build Array of Video Items
$xmlContent = array (
array ( "title" => "Title 1",
"desc" => "Description 1",
"sdImg" => "http://Image1.url",
"vidFile" => "/path/videofile1.mp4"),
array ( "title" => "Title 2",
"desc" => "Description 2",
"sdImg" => "http://Image2.url",
"vidFile" => "/path/videofile3.mp4"),
array ( "title" => "Title 3",
"desc" => "Description 3",
"sdImg" => "http://Image3.url",
"vidFile" => "/path/videofile3.mp4")
);

// ** FINISHED EDITING VARIABLES**


// Echo initial part or XML document
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<feed>';

// Loop through the rest of the XML document filling in variables
$count = 1;
foreach ($xmlContent as $video) {

// Call function to produce expiring signed AWS S3 URL
$objectPath = $video[vidFile] ;
$s3URL = s3TempLink("$awsAccessKey" , "$awsSecretKey", "$bucketName", "$objectPath") ;

echo ' <item sdImg="'. $video[sdImg] .'" hdImg="'. $video[sdImg] .'">';
echo ' <title>'. $video[title] .'</title>';
echo ' <contentType>'. $type .'</contentType>';
echo ' <contentId>'. $count .'</contentId>';
echo ' <media>';
echo ' <streamFormat>mp4</streamFormat>';
echo ' <streamQuality>SD</streamQuality>';
echo ' <streamUrl>'. $s3URL .'</streamUrl>';
echo ' </media>';
echo ' <media>';
echo ' <streamFormat>mp4</streamFormat>';
echo ' <streamQuality>HD</streamQuality>';
echo ' <streamUrl>'. $s3URL .'</streamUrl>';
echo ' </media>';
echo ' <synopsis>'. $video[desc] .'</synopsis>';
echo ' <genres>'. $genre .'</genres>';
echo ' </item>';
$count++;
}

// Echo last part of XML document
echo '</feed>';

// Function to create signed expiring AWS S3 link Original by Tournas Dimitrios
//Reference Link: https://tournasdimitrios1.wordpress.com/2012/12/04/how-to-create-expiring-links-for-amazons-s3-with-php/

function s3TempLink($awsAccessKey, $awsSecretKey, $bucketName , $objectPath , $expires = 5) {
// Calculating expiry time
$expires = time() + ($expires * 60) ;
$objectPath = ltrim($objectPath, '/') ;
$signature = "GET\n\n\n$expires\n".'/'.$bucketName.'/'.$objectPath ;
// Calculating HMAC-sha1
$hashedSignature = base64_encode(hash_hmac('sha1' ,$signature , $awsSecretKey , true )) ;
// Constructing the URL
$url = sprintf('http://s3.amazonaws.com/%s/%s', $bucketName , $objectPath);
// Constructing the query String
$queryString = http_build_query( array(
'AWSAccessKeyId' => $awsAccessKey ,
'Expires' => $expires ,
'Signature' => $hashedSignature
), '', '&amp;');
// Apending query string to URL
return $url.'?'.$queryString ;
}

?>


Cheers!

Mark-
0 Kudos
bmbudai
Visitor

Re: How to use AWS S3 hosted videos in feed

Well, I know it's been over 4 years since the last post in this thread, but... I'm having similar problems. After lots of looking for solutions, I figured doing things a different way might be a good idea. My question is, if you have a server that creates your signed URLs, how do you control access to that server? It seems to me that if you don't somehow control access to that server, then anyone in the world could access the server and get signed URLs to your content in S3. I'm sure the answer is obvious (at least I hope it is  🙂 ) but I'm pretty new to security procedures.
0 Kudos
RehDogg
Streaming Star

Re: How to use AWS S3 hosted videos in feed

I have tried cloudfront with my S3 but its not working.

0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.