FFMPEG 加密 [英] FFMPEG Encryption

查看:70
本文介绍了FFMPEG 加密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个加密项目视频,我有几个关于程序的问题.

I am doing a project with encrypting video and I have a few questions for the procedure.

我使用一个命令将 mp4 转码为 HLSts 段持续时间约为 10 秒.

I used a command to transcode mp4 to HLS with a ts segment duration of ~10 seconds.

首先,我需要使用数据库中的密钥加密这些视频.然而,我不知道是否使用 ffmpeg 进行加密.

First, I need to encrypt those videos with a key from database. However, I have no idea for the encryption whether working with ffmpeg or not.

第二,如果不用ffmpeg也能加密,那我该怎么办?我在谷歌中搜索过,其中包括 openssl/aes 之类的东西,但是我没有详细的步骤可以遵循,即使是 ffmpeg 链接:http://www.ffmpeg.org/ffmpeg-all.html#srtp

Second, if the encryption can work without ffmpeg, so what should I do? I have searched in google which includes something like openssl / aes but there is no a detailed step for me to follow, even the ffmpeg link: http://www.ffmpeg.org/ffmpeg-all.html#srtp

谁能帮我教我如何加密视频?谢谢你.

Could anyone give me a hand, teaching me how to encrypt a video? Thanks to you.

推荐答案

是的,您可以使用 ffmpeg 来完成.您需要将数据库中的密钥写入文件,例如 video.key.

Yes, you can do it with ffmpeg. You need to write the key from the database to a file, let's say video.key.

您需要第二个文件,我们将其命名为 key_info,这是密钥信息文件.它具有以下格式:

You need a second file, let's name it key_info which is the key info file. It has the following format:

key URI
key file path
IV (optional)

例如:

http://example.com/video.key
video.key

您告诉 ffmpeg 使用它来加密带有 hls_key_info 参数的段:

You tell ffmpeg to use it to encrypt your segments with the hls_key_info argument:

ffmpeg -i input.mp4 -c copy -bsf:v h264_mp4toannexb -hls_time 10 -hls_key_info_file key_info playlist.m3u8

这将在 CBC 模式下使用 AES-128 加密您的片段并将相关标签添加到您的播放列表:

This will encrypt your segments with AES-128 in CBC mode and add the relevant tags to your playlist:

#EXT-X-KEY:METHOD=AES-128,URI="http://example.com/video.key"

如果需要,您也可以使用 openssl 手动加密段.这是一个示例脚本,其中每个 IV 等于段索引:

You can also manually encrypt the segments if you want with openssl. Here's an example script, where each IV is equal to the segment index:

#!/bin/bash
ts_dir=/path/to/ts/

key_file=video.key
openssl rand 16 > $key_file
enc_key=$(hexdump -v -e '16/1 "%02x"' $key_file)

pushd $ts_dir

ts_cnt=$(ls *.ts | wc -l)
((ts_cnt--))

i=0
for i in $(seq -f "%01g" 0 $ts_cnt); do
    iv=$(printf '%032x' $i)
    ts_file=segment-$i.ts

    echo [$i] $ts_file

    openssl aes-128-cbc -e -in $ts_file -out encrypted_${ts_file} -nosalt -iv $iv -K $enc_key
done

popd

这篇关于FFMPEG 加密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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