[FFmpeg-devel] [PATCH v2 1/2] avformat/framehash: add extradata checksum
James Almer
jamrial at gmail.com
Wed Apr 13 06:54:25 CEST 2016
Signed-off-by: James Almer <jamrial at gmail.com>
---
I'm keeping the version code for the time being, unless people disagree.
Removing it if needed is trivial.
libavformat/hashenc.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c
index 614c815..e471789 100644
--- a/libavformat/hashenc.c
+++ b/libavformat/hashenc.c
@@ -149,6 +149,33 @@ AVOutputFormat ff_md5_muxer = {
#endif
#if CONFIG_FRAMEHASH_MUXER || CONFIG_FRAMEMD5_MUXER
+static void framehash_print_extradata(struct AVFormatContext *s)
+{
+ int i, header_printed = 0;
+
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *st = s->streams[i];
+ AVCodecParameters *par = st->codecpar;
+ if (par->extradata) {
+ struct HashContext *c = s->priv_data;
+ char buf[AV_HASH_MAX_SIZE*2+128];
+ int len;
+
+ if (!header_printed) {
+ avio_printf(s->pb, "#extradata#, size, hash\n");
+ header_printed = 1;
+ }
+ av_hash_init(c->hash);
+ av_hash_update(c->hash, par->extradata, par->extradata_size);
+ snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), "%d, %42d, ", i, par->extradata_size);
+ len = strlen(buf);
+ av_hash_final_hex(c->hash, buf + len, sizeof(buf) - len);
+ av_strlcatf(buf, sizeof(buf), "\n");
+ avio_write(s->pb, buf, strlen(buf));
+ }
+ }
+}
+
static int framehash_write_header(struct AVFormatContext *s)
{
struct HashContext *c = s->priv_data;
@@ -159,6 +186,9 @@ static int framehash_write_header(struct AVFormatContext *s)
avio_printf(s->pb, "#version: %d\n", c->format_version);
avio_printf(s->pb, "#hash: %s\n", av_hash_get_name(c->hash));
ff_framehash_write_header(s, c->format_version);
+ if (c->format_version > 1)
+ framehash_print_extradata(s);
+
avio_printf(s->pb, "#stream#, dts, pts, duration, size, hash\n");
return 0;
}
--
2.8.0
More information about the ffmpeg-devel
mailing list