[FFmpeg-devel] [PATCH 2/3] avformat/movenc: add mov_write_int_metadata()
Moritz Barsnick
barsnick at gmx.net
Wed Sep 19 16:58:31 EEST 2018
Converted from mov_write_int8_metadata(), allowing to also write
16-bit and 32-bit integer atoms, at up to 32-bit total size.
Converted mov_write_int8_metadata() into a macro specifying a
truncation of one byte length.
Signed-off-by: Moritz Barsnick <barsnick at gmx.net>
---
libavformat/movenc.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7c326faa49..0bb66e5fd1 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3453,20 +3453,25 @@ static int mov_write_trkn_tag(AVIOContext *pb, MOVMuxContext *mov,
return size;
}
-static int mov_write_int8_metadata(AVFormatContext *s, AVIOContext *pb,
- const char *name, const char *tag,
- int len)
+#define mov_write_int8_metadata(a, b, c, d, e) mov_write_int_metadata(a, b, c, d, e, 1)
+static int mov_write_int_metadata(AVFormatContext *s, AVIOContext *pb,
+ const char *name, const char *tag,
+ int len, int truncate)
{
AVDictionaryEntry *t = NULL;
- uint8_t num;
+ uint32_t num;
int size = 24 + len;
if (len != 1 && len != 2 && len != 4)
return -1;
+ if (truncate > len)
+ return -1;
+ if (truncate != 1 && truncate != 2 && truncate != 4)
+ return -1;
if (!(t = av_dict_get(s->metadata, tag, NULL, 0)))
return 0;
- num = atoi(t->value);
+ num = (uint32_t)strtoull(t->value, NULL, 10);
avio_wb32(pb, size);
ffio_wfourcc(pb, name);
@@ -3475,9 +3480,10 @@ static int mov_write_int8_metadata(AVFormatContext *s, AVIOContext *pb,
avio_wb32(pb, 0x15); // type specifier
avio_wb32(pb, 0);
// data:
- if (len == 4) avio_wb32(pb, num);
- else if (len == 2) avio_wb16(pb, num);
- else avio_w8 (pb, num);
+ num &= (1U << (truncate*8)) - 1; // mask out the lower "truncate" number of bytes
+ if (len == 4) avio_wb32(pb, num);
+ else if (len == 2) avio_wb16(pb, (uint16_t)num);
+ else avio_w8 (pb, (uint8_t) num);
return size;
}
--
2.14.4
More information about the ffmpeg-devel
mailing list