FFmpeg:如何制作 MP4 CENC(通用加密)视频 [英] FFmpeg: how to produce MP4 CENC (Common Encryption) videos

查看:45
本文介绍了FFmpeg:如何制作 MP4 CENC(通用加密)视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ffmpeg 进行 CENC 加密的正确语法是什么?

ffmpeg 3.0 发行说明包括通用加密 (CENC) MP4 编码和解码支持",文件 libavformat/movenccenc.h 和 libavformat/movenccenc.c 似乎包括根据通用加密加密 MP4 文件所需的一切标准.

但是,我在 ffmpeg 手册页中找不到关于此主题的任何文档.

问候

解决方案

Mulvya 的回答涵盖了 ffmpeg-options.

我只是添加了一个具体的例子,也谈谈回放,因为我昨天(独立)做了一些实验.

加密示例

<预> <代码>的ffmpeg -i SampleVideo_1280x720_1mb.mp4 -vcodec复制-acodec拷贝-encryption_scheme CENC-AES-CTR -encryption_key 76a6c65c5ea762046bd749a2e632ccbb -encryption_kid a7e61c373e219033c21091fa607bf3b8 SampleVideo_1280x720_1mb_encrypted.mp4

(当然,您的情况可能会有所不同;我只是重新混合了视频和音频)

播放/解码

ffplay

ffplay SampleVideo_1280x720_1mb_encrypted.mp4 -decryption_key 76a6c65c5ea762046bd749a2e632ccbb

但由于这或多或少是原型播放器,人们可能想要使用更强大的东西.

mpv

mpv --demuxer-lavf-o=decryption_key=76a6c65c5ea762046bd749a2e632ccbb SampleVideo_1280x720_1mb_encrypted.mp4

有一些讨论这里,因为我的第一个预期命令行没有表现得符合预期!

尝试解决 Reino 的问题

encryption_key 只是 128 位 = 16 字节编码为十六进制(遵循 使用 AES-128-CTR).所以 random.org 配置为 16 字节和 hex.encoding 将是一个有效的密钥(但我不建议一般信任外部资源).我使用了 python 的 secrets 模块 归结为:secrets.token_hex(16).解码需要此 encryption_key.

encryption_kid 密钥 ID 只是此密钥的标识符,可能需要更复杂的使用模式(我猜!你可以这样做:嘿视频...我需要你的 1000 个密钥中的哪一个?).我想必须通过它,但解码不需要它(如果您知道对哪个视频使用哪个密钥).

官方参考是:

  • 标准
  • ffmpeg 实现:文档(可通过命令行获取)或简短的 提取

What is the correct syntax to do CENC encryption with ffmpeg?

The ffmpeg 3.0 release notes include "Common Encryption (CENC) MP4 encoding and decoding support", and the files libavformat/movenccenc.h and libavformat/movenccenc.c seem to include everything needed to encrypt MP4 files according to the Common Encryption standard.

However, I can't find any documentation on this topic in the ffmpeg manual pages.

Regards

解决方案

Mulvya's answer covered the ffmpeg-options.

I'm just adding a concrete example and talk about playback too, as i did some experiments yesterday (independently).

Encryption example

ffmpeg -i SampleVideo_1280x720_1mb.mp4 -vcodec copy -acodec copy -encryption_scheme cenc-aes-ctr -encryption_key 76a6c65c5ea762046bd749a2e632ccbb -encryption_kid a7e61c373e219033c21091fa607bf3b8 SampleVideo_1280x720_1mb_encrypted.mp4

(of course usage might be different for your case; i just remuxed video and audio)

Playback / Decoding

ffplay

ffplay SampleVideo_1280x720_1mb_encrypted.mp4 -decryption_key 76a6c65c5ea762046bd749a2e632ccbb

But as this is more or less a prototype-player, one might want to use something more powerful.

mpv

mpv --demuxer-lavf-o=decryption_key=76a6c65c5ea762046bd749a2e632ccbb SampleVideo_1280x720_1mb_encrypted.mp4

There is some discussion here as my first expected command-line did not behave as expected!

Edit: trying to address Reino's questions

The encryption_key is just 128 bit = 16 bytes encoded as Hex (following the usage of AES-128-CTR). So random.org with a configuration of 16 bytes and hex.encoding would be a valid key (but i'm not recommending to trust external resources in general). I used python's secrets module which boils down to: secrets.token_hex(16). This encryption_key will be needed for decoding.

The encryption_kid Key ID is just an identifier for this key, probably needed for more complex usage-patterns (i'm !guessing! you could do something like: hey video... which of my 1000 keys do i need for you?). I suppose it's mandatory to pass it, but it's not required for decoding (if you know which key to use for which video).

The official references would be:

  • Standard
  • ffmpeg implementation: docs (available through command-line) or a short extraction

这篇关于FFmpeg:如何制作 MP4 CENC(通用加密)视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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