AWS的Cloudfront流与签约的网址 [英] AWS Cloudfront Streaming with signed URLs

查看:126
本文介绍了AWS的Cloudfront流与签约的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装下载和流分布的CloudFront的实例。我两个都设为私有有符号的URL。我能得到的样品code工作为图像下载发布与签约的网址。我现在试图让流分布JW播放器使用的是标识的URL,但我有问题。

下面是我签的URL格式:     rtmp://s1iq2cbtodqqky.cloudfront.net/2012-08-31_13-24-01_534.mp4?Expires=1359648770&Signature=Oi8RwL4Nf338NldW2uIsqFIv3zHnJkxXYbXIiVQh~J0Iq4kb00Ly5MLTgJw~87KmlUOmilmdRHy7p~UxeGYQxgkewPI11r27se0b~hTvpxq9y9Z5C-B-A58ZnngaCi9G2SHAujMzvss7ynLLEqUV3M6MVZl1qCxyfJbLdxCIEMY_&Key-Pair-Id=

下面是我的JW播放器code:

 <脚本类型=文/ JavaScript的SRC =jwplayer / jwplayer.js>< / SCRIPT>
< D​​IV ID =容器>正在载入播放器...< / DIV>
<脚本类型=文/ JavaScript的>
jwplayer(容器)。设置({
'版本的Adobe Flash:jwplayer / jwplayer.flash.swf',
'文件':'?< = $ canned_policy_stream_name>',
'宽度':'480','高度':'270',
提供者:RTMP,
流光:RTMP://s1iq2cbtodqqky.cloudfront.net/cfx/st/

});
< / SCRIPT>
 

任何人都知道这里有什么问题?我如何能单独测试的网址是什么?现在它是很难说,如果问题是URL或$ C $下JW播放器集成。

-J

解决方案

还有很多疑难杂症的是在这里。我花了一段时间来工作,通过他们,当我坐进它。这里有一些步骤,我认为可能会帮助很多人。

首先这里是技术堆栈我就跟着:

  • 的Rails 3.x中
  • 在禅codeR编码
  • 回形针文件上传
  • 的Jquery Uload上传
  • JWPlayer

如果这不是你的平台,你可以填补一些空白,但很多学习的仍然是对你有用。

有一堆关于如何上传内容到S3的用户,所以我会跳过这部分的文章,那得到的有趣的部分是当你开始编码过程,这是真的,其中的问题开始变得方面签署,流媒体内容在jwplayer或flowplayer玩。

首先,文件格式 - 我发现,MP4和M4A是文件格式,我过的最成功。随着禅宗codeR,我能够使用开箱MP4和M4A输出格式,并得到这些产出玩就好了。

  1. 添加你禅宗codeR政策桶建立CloudFront的分布前。
  2. 如果您已配置CloudFront的,你应该小心你怎么加的禅宗codeR桶政策倒入桶中,并确保与任何有合并。的Cloudfront也使的东西在桶策略,同时需要这和禅宗codeR桶策略配置文件才能正常工作。

  3. 桶政策的仅适用于由斗式所有者所拥有的文件的,所以一定要与您的编码提供者,以确保他们使用您的访问键把文件CloudFront的。如果你没有用户做签名一样谁拥有在S3中该文件的用户将无法正常工作,你会花好几个小时不知道为什么

  4. 一旦你确信你有你的水桶设置正确,继续之前使用该工具来帮助验证您的文件,实际上流(开始时没有签署的网址,并允许CloudFront的流未流文件。如果that't不工作,你不会得到远)。

    <一个href="http://d1k5ny0m6d4zlj.cloudfront.net/diag/CFStreamingDiag.html">http://d1k5ny0m6d4zlj.cloudfront.net/diag/CFStreamingDiag.html

    要使用亚马逊的工具,如果你的RTMP网址是:

    RTMP://s3b78u0kbtx79q.cloudfront.net/cfx/st/content/myfile.png

    有关要进入流网址:

    s3b78u0kbtx79q.cloudfront.net

    有关你想进入视频文件名称:

    内容/ myfile.png(不带前导'/')

  5. 在你其实可以通过诊断工具流从亚马逊您的文件,现在去到以下任何步骤,你必须从flowplayer的jwplayer。

  6. 在设置JWPlayer(我有问题最少用它),而流媒体的注意事项 - 还安装了闪光的调试版本。现在在调试过程中,你可以右键点击闪光控制并改变记录到控制台。现在,您将得到的闪光控制出现在Firebug的任何加载错误 - 所以也许与Firefox首先测试。通常情况下,审查这些日志的时候,你不希望任何HTML控制字符转义,逃避通常会毁掉你的一天。

  7. 我想有很多人这样做会希望自己的内容安全和使用签名的网址(使可疑的人不只是撕裂你的RTMP路径,并直接嵌入到他们的网站上得到好处,而你付出带宽)。我不能强调这一点,开始沿着这条道路之前,请务必先取得你的RTMP流打在公开的媒体流文件出你的CloudFront的桶中,让你知道的机制工作。

  8. 如果你走到这一步,你是个好地方,但现在是,当所有的bug可以打你,如果你按照我的建议上面这将是一个更短的一天,而不是如果你错过的步骤之一(如确保你的水桶政策,包括您的CloudFront的原产地标识和您的供应商编码写入文件与规范ID作为所有者,而不是他们的)。

  9. 现在,你有你的内容流通过RTMP一名球员,接下来你将要得到它与签订的URL(工作了,所以其他网站不能只是复制你的RTMP路径,并通过回放自己自己的网站与jwplayer附后)。在轨至少生成标识的URL的最好方法是使用这种宝石:

    <一个href="https://github.com/58bits/cloudfront-signer">https://github.com/58bits/cloudfront-signer

    根据您如何嵌入URL,你需要使用转义的不同类型。如果您的网址无法播放,请尝试以下一些(不是很precise,但如果你在这里失去你的头发,你会尝试任何事情,如果你已经尝试过得到这个工作,你可能已经知道我的意思,并不会需要理发了一会儿):

 &LT;%= AWS :: CF :: Signer.sign_path路径/要/我的/内容,:过期=&GT; Time.now + 600%&GT;
&LT;%=原AWS :: CF :: Signer.sign_path路径/要/我的/内容,:过期=&GT; Time.now + 600%&GT;

&LT;%= AWS :: CF :: Signer.sign_path_safe路径/要/我的/内容,:过期=&GT; Time.now + 600%&GT;
&LT;%=原AWS :: CF :: Signer.sign_path_safe路径/要/我的/内容,:过期=&GT; Time.now + 600%&GT;
 

我大概拧绕了一个小时一次我才发现,使用原会解决所有的问题。

I've setup a cloudfront instance with download and streaming distributions. I set both to private with signed urls. I was able to get sample code working for the download distribution for images with signed urls. I'm now trying to get the streaming distribution working for JW Player with a signed URL but I'm having issues.

Here is my signed URL format: rtmp://s1iq2cbtodqqky.cloudfront.net/2012-08-31_13-24-01_534.mp4?Expires=1359648770&Signature=Oi8RwL4Nf338NldW2uIsqFIv3zHnJkxXYbXIiVQh~J0Iq4kb00Ly5MLTgJw~87KmlUOmilmdRHy7p~UxeGYQxgkewPI11r27se0b~hTvpxq9y9Z5C-B-A58ZnngaCi9G2SHAujMzvss7ynLLEqUV3M6MVZl1qCxyfJbLdxCIEMY_&Key-Pair-Id=

Here is my JW Player code:

<script type="text/javascript" src="jwplayer/jwplayer.js"></script>
<div id="container">Loading the player ...</div>
<script type="text/javascript">
jwplayer("container").setup({
'flashplayer': 'jwplayer/jwplayer.flash.swf',
'file': '<?= $canned_policy_stream_name ?>',
'width': '480','height': '270',
'provider': 'rtmp',
'streamer': 'rtmp://s1iq2cbtodqqky.cloudfront.net/cfx/st/'

});
</script>

Anyone know what is wrong here? How can I test the url alone? Right now it's hard to tell if the problem is the url or the code for JW Player integration.

-J

解决方案

There a lot of gotcha's here. Took me a while to work through them when I got into it. Here are some steps I think might help a lot of people.

First here was the technology stack I went with:

  • Rails 3.x
  • Zencoder for encoding
  • Paperclip for file upload
  • Jquery Uload for upload
  • JWPlayer

If that's not your platform you can fill in some of the blanks but a lot of the learning will still be useful to you.

There are a bunch of articles on how to upload content into S3 from a user so I will skip that part, the part that get's interesting is when you start the encoding process and that is really where the issues start in terms of getting signed, streamed content to play in jwplayer or flowplayer.

First, file formats - I found that MP4 and M4A were the file formats I had the most success with. With zencoder, I was able to use the out of the box mp4 and m4a export formats and get those outputs to play just fine.

  1. Add you zencoder policy to the bucket before setting up the cloudfront distribution.
  2. If you already have cloudfront configured, you should be careful in how you add your zencoder bucket policy into the bucket and make sure to merge it with whatever is there. Cloudfront also puts stuff in the bucket policy, you need both this and the zencoder bucket policy profile to work correctly.

  3. Bucket policies only apply to files owned by the bucket owner so be sure to talk to your encoding provider to make sure they use your access key to put the files in cloudfront. If you don't have the user doing the signing the same as the user who owns the file in S3 it won't work and you will spend hours wondering why

  4. Once you are sure you have your buckets setup correctly, before going further use this tool to help validate your files will actually stream (start out without signed urls and allowing cloudfront to stream files that aren't streamed. If that't not working you won't get far).

    http://d1k5ny0m6d4zlj.cloudfront.net/diag/CFStreamingDiag.html

    To use amazons tool, if your rtmp url was:

    "rtmp://s3b78u0kbtx79q.cloudfront.net/cfx/st/content/myfile.png"

    For the streaming url you want to enter:

    s3b78u0kbtx79q.cloudfront.net

    For the video file name you want to enter:

    content/myfile.png (without the leading '/')

  5. Once you can actually stream your file from amazon through the diagnostics tool, now go on to following whatever steps you have from jwplayer of flowplayer.

  6. A note on setting up JWPlayer (I had the fewest problems with it) while streaming - also install a debug version of flash. Now during debugging, you can right click on the flash control and change logging to 'console'. Now you will get any load errors from the flash control appearing in Firebug - so maybe test first with Firefox. Typically, when reviewing those logs, you don't want any html control characters to be escaped, escaping will typically ruin your day.

  7. I imagine a lot of people doing this will want their content secure and to use signed urls (so that dubious others don't just rip your rtmp path and embed it directly into their site getting the benefit while you pay the bandwidth).I can't stress this enough, before starting down that path, make sure you first get your RTMP stream playing on publicly streamed files out of your cloudfront bucket so you know the mechanism is working.

  8. If you got this far you are in a good place but now is when all the bugs can hit you, if you followed my advice above it will be a shorter day than if you missed one of the steps (like making sure your bucket policy includes your cloudfront origin id and your encoding provider writes the files with your canonical id as the owner rather than theirs).

  9. Now that you have you content streaming through RTMP to a player, next you will want to get it working with signed URL's (again, so other sites can't just copy your RTMP path and play it back through their own site with jwplayer attached). In rails at least, the best way to generate a signed url is to use this gem:

    https://github.com/58bits/cloudfront-signer

    Depending on how you embed the url, you will need to use different types of escaping. If your URL doesn't play, try some the following (not very precise but if you are here and losing your hair you will try anything, if you have already tried to get this working you probably already know what I mean and won't be needing a haircut for a while):

<%=  AWS::CF::Signer.sign_path 'path/to/my/content', :expires => Time.now + 600 %>
<%=raw AWS::CF::Signer.sign_path 'path/to/my/content', :expires => Time.now + 600 %>

<%=  AWS::CF::Signer.sign_path_safe 'path/to/my/content', :expires => Time.now + 600 %>
<%=raw AWS::CF::Signer.sign_path_safe 'path/to/my/content', :expires => Time.now + 600 %>

I probably screwed around for an hour one time before I found that using raw would fix all my problems.

这篇关于AWS的Cloudfront流与签约的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆