如何解密hls视频内容

时间:2019-05-16 10:00:37

标签: android encryption ffmpeg hls exoplayer

我的要求是从hls的本地存储中播放加密的android视频文件。我已经使用NanoHTTPD创建和运行本地服务器。从那里开始服务.ts.m3u8文件。要播放此视频ExoPlayer,需要一个密钥来解密文件,因此,我创建了一个网址:http://localhost:4990/dataKey

这是我的本地服务器类:

import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;

import fi.iki.elonen.NanoHTTPD;

public class LocalStreamingServer extends NanoHTTPD{
    public LocalStreamingServer(int port){
        super(port);

    }

    @Override
    public Response serve(IHTTPSession session){
        Log.e("req", session.getUri());

        if(session.getUri().equalsIgnoreCase("/dataKey")){

            return newFixedLengthResponse(Response.Status.OK, "txt", "what is the key?");
        }

        if(session.getUri().contains("m3u8")){
            String path = Environment.getExternalStorageDirectory().toString() + "/s3" + session.getUri();

            FileInputStream fis = null;
            File f = new File(path);
            try {
                fis = new FileInputStream(f);
            } catch (FileNotFoundException e) {
            }
            return newFixedLengthResponse(Response.Status.OK, "m3u8", fis, f.length());
        }

        if(session.getUri().endsWith("ts")){
            String path = Environment.getExternalStorageDirectory().toString() + "/s3" + session.getUri();

            FileInputStream fis = null;
            File f = new File(path);
            try {
                fis = new FileInputStream(f);
            } catch (FileNotFoundException e) {

            }
            return newFixedLengthResponse(Response.Status.OK, "ts", fis, f.length());
        }

        String path = Environment.getExternalStorageDirectory().toString() + "/s3/master.m3u8";

        FileInputStream fis = null;
        File f = new File(path);
        try {
            fis = new FileInputStream(f);
        } catch (FileNotFoundException e) {
        }
        return newFixedLengthResponse(Response.Status.OK, "m3u8", fis, f.length());
    }
}

我已使用ffmpeg对视频进行了转码。我需要知道调用dataKey url时需要返回哪些数据或密钥。我已使用以下密钥对视频进行了加密:

key=617D8A125A284DF48E3C6B1866348A3F
IV=5ff82ce11c7e73dcdf7e73cacd0ef98

我无法理解需要从datakey url返回其中的哪些。他们两个都不工作。 Exoplayer正在发送错误消息:java.security.InvalidKeyException: Unsupported key size

有人可以帮我吗?

0 个答案:

没有答案