hls二次加密 m3u8,AVPlayer在播放HLS / AES加密视频之前发出无关的http请求

We're using AVPlayer on iOS 8.4 to play HLS, AES-encrypted video.

Our .m3u8 files include the url of the license server, e.g.:

EXT-X-KEY:METHOD=AES-128,URI="https://...."

In our iOS application, we're using AVAssetResourceLoaderDelegate method

resourceLoader:shouldWaitForLoadingOfRequestedResource:

to intercept the request that gets sent by the AVPlayer (or some object within AVFoundation) to the license server. Within that method, we add a token (required by the license server) to the request's queryString.

The license server receives the request with the token, returns the encryption key, and playback begins.

In other words, everything works as expected.

However, we're noticing (using the "Charles" http monitor) that following the creation of the AVPlayerItem and prior to the invocation of the resourceLoader: method, AVFoundation sends an initial request to the license server url; a request that's not "routed" through method resourceLoader:. This request is rejected at the server as our iOS code never has a chance to append the token before the request goes out.

Summary of events:

• AVPlayerItem/AVAsset is created and initialized with the url of the .m3u8 index file.

• Something within the AVFoundation framwork makes a request to the license server specified in the .m3u8 file. This initial request is NOT intercepted by method  recourceLoader:shouldWaitForLoadingOfRequestedResource: and the unmodified request hits the license server.  Because the request doesn't contain a required token in the queryString, it fails and no encrypton key is returned.

• A second request is made by AVFoundation to the licesnse server. This request IS caught by recourceLoader:...and modified appropriately. The license server returns an encryption key and playback begins.

This behavior can be replicated using Apple's AVARLDelegateDemo app.

Questions:

Is the initial http request sent by AVFoundation normal?

If so, why is it necessary and why isn't it getting "routed" through the resourceLoader: method?

Is it possible to suppress the initial request or modify it before it's sent?

Thank you!

解决方案

The simple answer to this issue is that the AVAssetResourceLoaderDelegate will only handle requests for URLs which cannot be processed in the normal way.

In your case, the URL for your key is a normal https:// URL, so the AVPlayer will try to process this request itself. Without the token though, this request is rejected by your server. Therefore, the AVAssetResourceLoaderDelegate will then pass the request to your delegate to handle it.

To avoid the 'extraneous' request, modify your playlist so that the encryption key URL has an invalid scheme. Use something like crypt://... instead of https://....

That way, you will receive the resource loader call on the first try, and you can replace the crypt:// scheme with https:// and add your token before making the request yourself in the normal way.

It's just how AVAssetResourceLoaderDelegate works, I'm afraid.

Check out Apple's sample app here for more details:

https://developer.apple.com/library/ios/samplecode/sc1791/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HLS(HTTP Live Streaming)是苹果公司提出的一种流媒体传输协议,而M3U8则是HLS流媒体的播放列表文件格式。在HLS中,媒体数据被分段传输,并通过M3U8文件来描述这些媒体段的详细信息。M3U8文件中包含了媒体段的URL地址,可以从服务器获取这些媒体段进行播放。 Sample-AES(Sample-based AES encryption)是HLS中对媒体段进行加密的一种方式。它使用AES(Advanced Encryption Standard)算法对每个媒体段进行加密,然后在M3U8文件中使用URI方式引用加密的密钥。这样,只有具有正确密钥的用户才能解密和播放这些加密的媒体段。 要实现HLS/M3U8的Sample-AES解密及软件开发,需要考虑以下几个步骤: 1. 解析M3U8文件:通过解析M3U8文件,获取媒体段的URL地址和加密键信息。可以使用Python等编程语言来实现M3U8文件的解析。 2. 下载媒体段:根据M3U8文件中的URL地址,从服务器上下载加密的媒体段。可以使用HTTP请求库(如requests库)来发送HTTP请求并下载媒体段。 3. 获取密钥:从M3U8文件中的加密键信息中获取加密用的密钥。密钥通常以URI的形式给出,可以根据URI的规则找到对应的密钥。 4. 解密媒体段:使用AES算法和获取的密钥对下载的媒体段进行解密。可以使用AES加密库来实现解密算法。 5. 播放媒体:将解密后的媒体段进行播放。可以使用FFmpeg等多媒体处理库来实现播放功能。 总之,实现HLS/M3U8的Sample-AES解密及软件开发,涉及到M3U8文件的解析、媒体段的下载、密钥的获取、媒体的解密和播放等步骤。通过合理选择编程语言和相关库,可以实现这一功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值