[libav-api] libav and encryption

Ronald S. Bultje rsbultje at gmail.com
Wed Aug 10 22:12:12 CEST 2011


Hi,

On Mon, Aug 8, 2011 at 10:31 AM, Vadim Gusev <ubuntolog at gmail.com> wrote:
> Hi there. I'm wondering if it's possible to find solution for situation i'm
> in right now. I need to modify existing app, that uses ffmpeg to
> decode/encode video so it will work with encrypted files.
> Basically i have encrypted video file, that i need to process, transcode and
> encrypt output stream. The goal is to not to store decrypted file but
> decrypt, transcode and encrypt on the fly.
> File is encrypted with twofish cipher. The main problem i see is: packets
> size differs so i can not know how much should i decrypt and supply to libav
> on each iteraton.
> So the question is how to deal with situation where input file is not
> actually a video file that can be supplied directly to libav, but should be
> pre-processed (decrypted in my case) and it can't be pre-processed at once
> entirely.
> In other words, can I create sort of pipe which looks like: "read input file
> | decrypt | decode | process | encode | write output file".
>
> Thanks in advance.

If you intend to do the decrypting outside libav, you can look into
using an AVIOContext. This is a structure that basically wraps our
read/write/seek routines, you can basically make the read callback do
the decryting on the fly and block while that's in progress. Supply it
as AVFormatContext->pb while opening the media
(av_open_input_stream()) and it'll work as you expect.

Output encrypting is easy so I guess I won't go into that.

Ronald


More information about the libav-api mailing list