On Thu, 31 Jul 2014, John Stebbins wrote:
---
libavformat/movenc.c | 77 ++++++++++++++++++++++++++++++++++++++++++++--------
libavformat/movenc.h | 1 +
2 files changed, 67 insertions(+), 11 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index f16e851..b384f4d 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -77,6 +77,17 @@ static const AVClass flavor ## _muxer_class = {\
.version = LIBAVUTIL_VERSION_INT,\
};
+static int utf8len(const uint8_t *b)
+{
+ int len = 0;
+ int val;
+ while (*b) {
+ GET_UTF8(val, *b++, return -1;)
+ len++;
+ }
+ return len;
+}
+
//FIXME support 64 bit variant with wide placeholders
static int64_t update_size(AVIOContext *pb, int64_t pos)
{
@@ -1352,6 +1363,16 @@ static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack
*track)
"Unknown hldr_type for %s / 0x%04X, writing dummy values\n",
tag_buf, track->enc->codec_tag);
}
+ if (track->st) {
+ // hdlr.name is used by some players to identify the content title
+ // of the track. So if an alternate handler description is
+ // specified, use it.
+ AVDictionaryEntry *t;
+ t = av_dict_get(track->st->metadata, "handler", NULL, 0);
+ if (t && utf8len(t->value)) {
+ descr = t->value;
+ }
+ }
}
avio_wb32(pb, 0); /* size */
@@ -1671,6 +1692,48 @@ static int mov_write_udta_sdp(AVIOContext *pb, MOVTrack
*track)
return len + 24;
}
+static int mov_write_track_metadata(AVIOContext *pb, AVStream *st,
+ const char *tag, const char *str)
+{
+ int64_t pos = avio_tell(pb);
+ AVDictionaryEntry *t = av_dict_get(st->metadata, str, NULL, 0);
+ if (!t || !utf8len(t->value))
+ return 0;
+
+ avio_wb32(pb, 0); /* size */
+ ffio_wfourcc(pb, tag); /* type */
+ avio_write(pb, t->value, strlen(t->value)); /* UTF8 string value */
+ return update_size(pb, pos);
+}
+
+static int mov_write_track_udta_tag(AVIOContext *pb, MOVMuxContext *mov,
+ AVStream *st)
+{
+ AVIOContext *pb_buf;
+ int ret, size;
+ uint8_t *buf;
+
+ if (st == NULL || mov->fc->flags & AVFMT_FLAG_BITEXACT)
+ return 0;
Hmm, why not write this if wanting bitexact output? Writing some metadata
fields is bitexact, no? We normally only discard e.g. lavf version
identifiers and other things which change often or are nondeterministic. I
guess that the fate checksum changes if you remove this - but in that case
just update the fate checksum instead.
+
+ ret = avio_open_dyn_buf(&pb_buf);
+ if (ret < 0)
+ return ret;
+
+ if (mov->mode & MODE_MP4) {
+ mov_write_track_metadata(pb_buf, st, "name", "title");
Umm, this literally just writes "title" here - but where is the title
written then? Or is there something that I'm missing? Is this related to
writing the metadata "handler" key above, or is that a separate thing in
the same patch?
+ }
If mode isn't MODE_MP4, we just write an empty udta atom - that doesn't
feel too useful - shouldn't we just skip writing it altogether in that
case?
+
+ if ((size = avio_close_dyn_buf(pb_buf, &buf)) > 0) {
Why the indirection via the separate AVIOContext? You can write multiple
nested atoms without any indirection, just do:
int64_t pos = avio_tell(pb);
avio_wb32(pb, 0);
ffio_wfourcc(pb, "udta");
mov_write_track_metadata();
update_size(pb, pos1);
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel