FFMPEG加密 [英] FFMPEG Encryption

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

问题描述

我正在做一个加密
视频的项目,我有一些问题的程序。



我使用命令转码 mp4 HLS ts 段持续时间约10秒。 p>

首先,我需要使用数据库中的密钥加密这些视频。但是,
我不知道加密是否使用ffmpeg。



其次,如果加密可以在没有ffmpeg的情况下工作,那么我该怎么办?我在谷歌搜索包括像openssl / aes但
没有一个详细的步骤,我跟随,甚至ffmpeg链接:
http://www.ffmpeg.org/ffmpeg-all.html#srtp



<有人可以给我一只手,教我如何加密视频?感谢你。

解决方案

是的,你可以用 ffmpeg 。你需要将密钥从数据库写入一个文件,我们假设 video.key



你需要一个第二个文件,我们命名为 key_info 哪个是关键信息文件。它具有以下格式:

 键URI 
密钥文件路径
IV(可选)

例如:

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

你告诉 ffmpeg 使用它来加密您的细分,使用 hls_key_info 参数:

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

这将使用CBC模式的AES-128加密您的细分,并将相关标签添加到播放列表中:

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

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

 #!/ 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
为$(seq -f%01g0 $ 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


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

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

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.

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.

解决方案

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

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)

Eg:

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

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

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"

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天全站免登陆