diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2013-01-01 14:14:43 +0100 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2013-01-01 19:43:21 +0100 |
commit | 8dbbaf568ed9b9c76af596fc7daecbe1b971a7ce (patch) | |
tree | d69274bd1d79a564d5bae8bbbe5063bc674ec5a9 | |
parent | 5bab99baea4fa0ceee31d8bed8a3f22e4726d036 (diff) | |
download | ffmpeg-8dbbaf568ed9b9c76af596fc7daecbe1b971a7ce.tar.gz |
lavf/matroskaenc: respect bitexact for attachments.
Use the first 64 bits of the SHA1 of the content as file UID
instead of a random number if the bitexact flag is set.
-rw-r--r-- | libavformat/matroskaenc.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index c0c0a2d03e..1840f90b22 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -28,6 +28,7 @@ #include "flacenc.h" #include "avlanguage.h" #include "libavutil/samplefmt.h" +#include "libavutil/sha.h" #include "libavutil/intreadwrite.h" #include "libavutil/intfloat.h" #include "libavutil/mathematics.h" @@ -856,6 +857,7 @@ static int mkv_write_attachments(AVFormatContext *s) ebml_master attached_file; AVDictionaryEntry *t; const char *mimetype = NULL; + uint64_t fileuid; if (st->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) continue; @@ -885,9 +887,25 @@ static int mkv_write_attachments(AVFormatContext *s) return AVERROR(EINVAL); } + if (st->codec->flags & CODEC_FLAG_BITEXACT) { + struct AVSHA *sha = av_sha_alloc(); + uint8_t digest[20]; + if (!sha) + return AVERROR(ENOMEM); + av_sha_init(sha, 160); + av_sha_update(sha, st->codec->extradata, st->codec->extradata_size); + av_sha_final(sha, digest); + av_free(sha); + fileuid = AV_RL64(digest); + } else { + fileuid = av_lfg_get(&c); + } + av_log(s, AV_LOG_VERBOSE, "Using %.16"PRIx64" for attachment %d\n", + fileuid, i); + put_ebml_string(pb, MATROSKA_ID_FILEMIMETYPE, mimetype); put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codec->extradata, st->codec->extradata_size); - put_ebml_uint(pb, MATROSKA_ID_FILEUID, av_lfg_get(&c)); + put_ebml_uint(pb, MATROSKA_ID_FILEUID, fileuid); end_ebml_master(pb, attached_file); } end_ebml_master(pb, attachments); |