[FFmpeg-devel] support for reading / writing encrypted MP4 files
Eran Kornblau
eran.kornblau at kaltura.com
Tue Dec 22 22:13:31 CET 2015
> you are not subscribed (with this email address you used here at least
> it seems)
>
Right, apparently the subscription confirmation message went to the junk folder...
Anyway, glad this one is now resolved :-) and sorry for the trouble.
> > >
> > > > + id = mov_codec_id(st, format);
> > > > + st->codec->codec_id = id;
> > >
> > > doesnt this allow changing the codec id to anything from anything ?
> > > this seems potentially risky
> > >
> > I see options to address this:
> > 1. overwrite the codec_id only when it's AV_CODEC_ID_NONE
> > 2. (stricter) save the format 4cc (that is loaded in ff_mov_read_stsd_entries) to some member of
> > MOVStreamContext, and overwrite the codec id only when the format is 'encv' or 'enca'
> >
> > please let me know which one you prefer, and I will update the patch.
>
> i think the strcter variant sounds more robust
>
Fixed, updated patch attached.
Also added a warning in case the frma atom is ignored because of this.
Pasting here the diff between this new patch and the previous one (if it helps):
diff --git a/libavformat/isom.h b/libavformat/isom.h
index 3b0230a..a5ca21b 100644
--- a/libavformat/isom.h
+++ b/libavformat/isom.h
@@ -170,6 +170,7 @@ typedef struct MOVStreamContext {
int64_t duration_for_fps;
int32_t *display_matrix;
+ uint32_t format;
struct {
int use_subsamples;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 728d8b0..94005cb 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2227,6 +2227,7 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id;
sc->dref_id= dref_id;
+ sc->format = format;
id = mov_codec_id(st, format);
@@ -4011,15 +4012,30 @@ static int mov_read_free(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_frma(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
uint32_t format = avio_rl32(pb);
+ MOVStreamContext *sc;
enum AVCodecID id;
AVStream *st;
if (c->fc->nb_streams < 1)
return 0;
st = c->fc->streams[c->fc->nb_streams - 1];
+ sc = st->priv_data;
+
+ switch (sc->format)
+ {
+ case MKTAG('e','n','c','v'): // encrypted video
+ case MKTAG('e','n','c','a'): // encrypted audio
+ id = mov_codec_id(st, format);
+ st->codec->codec_id = id;
+ sc->format = format;
+ break;
- id = mov_codec_id(st, format);
- st->codec->codec_id = id;
+ default:
+ av_log(c->fc, AV_LOG_WARNING,
+ "ignoring 'frma' atom of '%.4s', stream format is '%.4s'\n",
+ (char*)&format, (char*)&sc->format);
+ break;
return 0;
}
Thanks
Eran
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-mov-support-cenc-common-encryption.patch
Type: application/octet-stream
Size: 9850 bytes
Desc: 0001-mov-support-cenc-common-encryption.patch
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151222/e1b64ee4/attachment.obj>
More information about the ffmpeg-devel
mailing list