Integrating Amazon S3 and CloudFront for video streaming
2010-05-13 19:03
411 查看
http://www.featheast.com/en/wordpress/amazon/integrating-amazon-s3-and-cloudfront-for-video-streaming
Amazon is a key player in the competition of cloud computing, and the service it provides can always satisfy our requirements if you can just dig a little bit deeper. Here, I’d like to show how to integrate the S3 and CloudFront service to provide video streaming service.
First, let’s clarify some basic concepts of S3 and CloudFront. Amazon S3 is a storage provider which can store all kinds of data. But in order to deliver the content more rapidly for users globally, CloudFront uses its edge locations to obviously improve the responsive time. When people try to fetch a content via CloudFront, the server will automatically routes the user to the most closest location which host the replica of the data. However, CloudFront doesn’t provide storage service, which is complemented by S3. That’s why they always appear in the same place.
1. Distribute S3 bucket to CloudFront location
OK, so our first step is to link the S3 and CloudFront to allow distribution. It can be done with S3 Fox plugin of FireFox, or by programming. But we need to clarify another issue before we step forward. There are also two kinds of distribution existed in CloudFront, static file distribution and streaming distribution. Currently, the latest S3 Fox only supports the static distribution, which can be simply done by right clicking the bucket and ‘manage the distribution’. In order to streaming distribution our bucket, we kind of have the only choice to code. Here is a short snippet of Java code to implement this function by using Jets3t library.
StreamingDistribution newStreamingDistribution = null;
try {
newStreamingDistribution = cloudFrontService.createStreamingDistribution(bucket.getName(), “”+ System.currentTimeMillis(),
null, ”Test streaming distribution”, true );
} catch (CloudFrontServiceException e1) {
log.error(e1.getMessage());
}
log.info(”New Streaming Distribution: ” + newStreamingDistribution);
StreamingDistributionConfig streamingDistributionConfig;
try {
streamingDistributionConfig = cloudFrontService.getStreamingDistributionConfig(newStreamingDistribution.getId());
log.info(”Streaming Distribution Config: “+ streamingDistributionConfig);
} catch (CloudFrontServiceException e) {
log.error(e.getMessage());
}
2. After we enable the streaming distribution of the bucket, we will get a distribution URL. This is the base URL address that we will use throughout the whole process. Now we can use any methods to upload a multimedia file into the bucket we just created. Next we will use Flowplayer rtmp plugin to display the file into a browser.
Download the latest version of FlowPlayer as well as its rtmp plugin, and write a follow html page:
<html>
<head><title>Video</title><script src=”flowplayer/flowplayer-3.1.4.min.js”></script>
</head>
<body>
<a class=”rtmp” href=”50f9307fbcdcdcaae65c4bc58857ca19-LOW” style=”display:block;width:640px;height:360px;”></a>
<script type=”text/javascript”>$f(”a.rtmp”, “flowplayer/flowplayer-3.1.5.swf”,
{clip:{provider: ‘rtmp’,autoPlay: true,},plugins: {rtmp: {url: ‘flowplayer/flowplayer.rtmp-3.1.3.swf’,netConnectionUrl: ‘rtmp://s240vvr18v7md1.cloudfront.net/cfx/st’}}});</script>
</body></html>
Several places need to notice:
1) you must have the flowplayer.js, flowplayer.swf, and flowplayer.rtmp.swf ready to use and with the right path.
2) In the anchor tag, the href attribute is the file path/name of which you would like to play. Say for example, your file is XXX.mp3, and with the full path of http://AAA.s3.amazonaws.com/XXX.mp3, then you should place XXX in the href attribute. DON’T ADD THE EXTENSION!!!.
3) In the JavaScript section, the autoPlay indicate whether to run the file automatically, the netConnectionUrl must be set according to the distribution URL you retrieved from part 1. Remember, you must prefix “rtmp://” before the url and append “cfx/st” to the URL, and also you must not ignore the single quote around the whole URL.
Now, you can have your streaming video playing in your browser! Easy and Sweat!
Amazon is a key player in the competition of cloud computing, and the service it provides can always satisfy our requirements if you can just dig a little bit deeper. Here, I’d like to show how to integrate the S3 and CloudFront service to provide video streaming service.
First, let’s clarify some basic concepts of S3 and CloudFront. Amazon S3 is a storage provider which can store all kinds of data. But in order to deliver the content more rapidly for users globally, CloudFront uses its edge locations to obviously improve the responsive time. When people try to fetch a content via CloudFront, the server will automatically routes the user to the most closest location which host the replica of the data. However, CloudFront doesn’t provide storage service, which is complemented by S3. That’s why they always appear in the same place.
1. Distribute S3 bucket to CloudFront location
OK, so our first step is to link the S3 and CloudFront to allow distribution. It can be done with S3 Fox plugin of FireFox, or by programming. But we need to clarify another issue before we step forward. There are also two kinds of distribution existed in CloudFront, static file distribution and streaming distribution. Currently, the latest S3 Fox only supports the static distribution, which can be simply done by right clicking the bucket and ‘manage the distribution’. In order to streaming distribution our bucket, we kind of have the only choice to code. Here is a short snippet of Java code to implement this function by using Jets3t library.
StreamingDistribution newStreamingDistribution = null;
try {
newStreamingDistribution = cloudFrontService.createStreamingDistribution(bucket.getName(), “”+ System.currentTimeMillis(),
null, ”Test streaming distribution”, true );
} catch (CloudFrontServiceException e1) {
log.error(e1.getMessage());
}
log.info(”New Streaming Distribution: ” + newStreamingDistribution);
StreamingDistributionConfig streamingDistributionConfig;
try {
streamingDistributionConfig = cloudFrontService.getStreamingDistributionConfig(newStreamingDistribution.getId());
log.info(”Streaming Distribution Config: “+ streamingDistributionConfig);
} catch (CloudFrontServiceException e) {
log.error(e.getMessage());
}
2. After we enable the streaming distribution of the bucket, we will get a distribution URL. This is the base URL address that we will use throughout the whole process. Now we can use any methods to upload a multimedia file into the bucket we just created. Next we will use Flowplayer rtmp plugin to display the file into a browser.
Download the latest version of FlowPlayer as well as its rtmp plugin, and write a follow html page:
<html>
<head><title>Video</title><script src=”flowplayer/flowplayer-3.1.4.min.js”></script>
</head>
<body>
<a class=”rtmp” href=”50f9307fbcdcdcaae65c4bc58857ca19-LOW” style=”display:block;width:640px;height:360px;”></a>
<script type=”text/javascript”>$f(”a.rtmp”, “flowplayer/flowplayer-3.1.5.swf”,
{clip:{provider: ‘rtmp’,autoPlay: true,},plugins: {rtmp: {url: ‘flowplayer/flowplayer.rtmp-3.1.3.swf’,netConnectionUrl: ‘rtmp://s240vvr18v7md1.cloudfront.net/cfx/st’}}});</script>
</body></html>
Several places need to notice:
1) you must have the flowplayer.js, flowplayer.swf, and flowplayer.rtmp.swf ready to use and with the right path.
2) In the anchor tag, the href attribute is the file path/name of which you would like to play. Say for example, your file is XXX.mp3, and with the full path of http://AAA.s3.amazonaws.com/XXX.mp3, then you should place XXX in the href attribute. DON’T ADD THE EXTENSION!!!.
3) In the JavaScript section, the autoPlay indicate whether to run the file automatically, the netConnectionUrl must be set according to the distribution URL you retrieved from part 1. Remember, you must prefix “rtmp://” before the url and append “cfx/st” to the URL, and also you must not ignore the single quote around the whole URL.
Now, you can have your streaming video playing in your browser! Easy and Sweat!
相关文章推荐
- with ffmpeg to encode video for live streaming and for recording to files for on-demand playback
- 3 Possible Ways for Real-Time Video Streaming Between Camera and Android Device Read more at http://
- 【每周论文】Apollo: Scalable and Coordinated Scheduling for Cloud-Scale Computing
- Integrating Context and Occlusion for Car Detection by Hierarchical And-Or Model
- Note for video Machine Learning and Data Mining——The Learning Problem
- 读《RTP.Audio.And.Video.For.The.Internet》笔记
- Video Compression and Communications: From Basics to H.261, H.263, H.264, MPEG4 for DVB and HSDPA-St
- State of the "Art": A Taxonomy of Artistic Stylization Techniques for Images and Video(六)
- Virtual View Synthesis Method and Self Evaluation Metrics for Free Viewpoint Television and 3D Video
- Mark Graham - Cloud-based Detection Techniques for Botnets and Other Malware
- Procedure for installing and setting Sun JDK Java on Default Amazon Linux AMI
- OSWorkflow: A guide for Java developers and architects to integrating open-source Business Process M
- 看图写代码---看图写代码 阅读<<Audio/Video Connectivity Solutions for Virtex-II Pro and Virtex-4 FPGAs >>
- 2013.4.14 Modeling and Algorithms for QoS-Aware Service Composition in Virtualization-Based Cloud Computing
- Connecting Docker for Cloud Services using SDN and Network Virtualization
- (转)Integrating Intel® Media SDK with FFmpeg for mux/demuxing and audio encode/decode usages 1
- [ICME 2014, paperId 293]AN APPROACH FOR FAST AND PARALLEL VIDEO PROCESSING ON APACHE HADOOP CLUSTERS
- Note for video Machine Learning and Data Mining——training vs Testing