0

I have a url for a m3u8 file which has the list of ts files.All those files are encrypted by AES-128 method.Along with ts files m3u8 file also contains URI for keys.

First I want to download the ts files & then decrypt them.After decryption I want to play those files.

Url for my m3u8 file is like https://example.com/myxml/myclips/250/prog_index.m3u8

My m3u8 file looks like this.

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:2
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10, 
#EXT-X-KEY:METHOD=AES-128,URI="https://my.server.com/myxml/myclips/keys/250/crypt_480x272_250_0.key",IV=0x8da4a2d80b88785f7931874bf1e0914b
fileSequence0.ts
#EXTINF:10, 
fileSequence1.ts
#EXTINF:10, 
fileSequence2.ts
#EXTINF:10, 
fileSequence3.ts
#EXTINF:10, 
fileSequence4.ts
#EXTINF:10, 
fileSequence5.ts
#EXTINF:10, 
fileSequence6.ts
#EXTINF:10, 
fileSequence7.ts
#EXTINF:10, 
fileSequence8.ts
#EXTINF:10, 
fileSequence9.ts
#EXTINF:10, 
fileSequence10.ts
#EXTINF:10, 
fileSequence11.ts
#EXTINF:10, 
#EXT-X-KEY:METHOD=AES-128,URI="https://my.server.com/myxml/myclips/keys/250/crypt_480x272_250_1.key",IV=0x8e2d35559338d21f2586e79d6cd5c606
fileSequence12.ts
#EXTINF:10, 
fileSequence13.ts
#EXTINF:10, 
fileSequence14.ts
#EXTINF:10, 
fileSequence15.ts
#EXTINF:10, 
fileSequence16.ts
#EXTINF:10, 
fileSequence17.ts
#EXTINF:10, 
fileSequence18.ts
#EXTINF:10, 
fileSequence19.ts
#EXTINF:2,  
fileSequence20.ts
#EXT-X-ENDLIST

I am not getting any clue how can I do this.Please help.

4

2 回答 2

1

正如我在评论中提到的,AES-128 解密是由媒体框架在 Android 3.x 和 4.x 设备上自动完成的。

但是,您的 m3u8 中有错误。请颠倒#EXTINF 和#EXT-X-KEY 的顺序。#EXTINF 要求在下一行中包含 TS URI。

下面是HLS 草案的引述

EXTINF 是一个记录标记,用于描述由其后面的 URI 标识的媒体文件。每个媒体文件 URI 必须以一个 EXTINF 标记开头。

于 2013-01-09T12:47:13.090 回答
0

不久前我也做了几乎一样的事情。我在这里写过: https ://andreasvolkmann.github.io//m3u8-and-ts-segments/

基本上采用带有加密 ts 段的 m3u8 播放列表并将其转换为一个 mp3 文件。

但是我不在Android上。以下代码对我有用(Kotlin):

fun getCipher(data: EncryptionData): Cipher {
    val bytes = URL(data.uri).readBytes()
    val chainmode = "CBC"
    val method = when (data.method) {
        EncryptionMethod.AES -> "AES/$chainmode/NoPadding"
        else -> data.method.name
    }
    val keySpec = SecretKeySpec(bytes, data.method.name)
    logger.trace("Decrypting using method ${data.method} ($method)")
    return Cipher
        .getInstance(method)
        .apply { init(Cipher.DECRYPT_MODE, keySpec, IvParameterSpec(ByteArray(16))) }
}
于 2018-06-07T15:46:17.490 回答