FFmpeg:如何制作 MP4 CENC(通用加密)视频

FFmpeg: how to produce MP4 CENC (Common Encryption) videos

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

ffmpeg 3.0 发行说明包括 "Common Encryption (CENC) MP4 encoding and decoding support",文件 libavformat/movenccenc.h 和 libavformat/movenccenc.c 似乎包含根据通用加密标准加密 MP4 文件所需的一切.

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

此致

运行 ffmpeg -h muxer=mp4 将为 MP4 muxer 生成所有可用选项,其中有

-encryption_scheme <string>     E....... Configures the encryption scheme, allowed values are none, cenc-aes-ctr
-encryption_key    <binary>     E....... The media encryption key (hex)
-encryption_kid    <binary>     E....... The media encryption key identifier (hex)

这些选项及其值应放在所有输入之后和输出文件名之前。

Mu​​lvya 的回答涵盖了 ffmpeg 选项。

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

加密示例

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

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

回放/解码

ffplay

ffplay SampleVideo_1280x720_1mb_encrypted.mp4 -decryption_key 76a6c65c5ea762046bd749a2e632ccbb

但由于这或多或少是原型播放器,因此可能需要使用更强大的东西。

mpv

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

有一些讨论 here 因为我的第一个预期命令行没有按预期运行!

编辑: 试图解决 Reino 的问题

encryption_key 只是 128 位 = 16 字节编码为十六进制(在 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 之后归结为:secrets.token_hex(16)。这个 encryption_key 将需要解码。

encryption_kid Key ID 只是这个键的标识符,可能需要更复杂的使用模式(我猜!你可以这样做:嘿视频...我需要我的 1000 把钥匙中的哪一把?)。我想它是强制性的,但它不是解码所必需的(如果你知道哪个密钥用于哪个视频)。

官方参考资料是: