+ if (size == UINT_MAX)
+ return -1;
+ value = av_malloc(size+1);
+ if (!value)
+ return -1;
+ get_buffer(pb, value, size);
+ value[size]=0;
+
+ AV_WL32(key, tag);
+
+ return av_metadata_set2(st ? &st->metadata : &s->metadata, key, value,
+ AV_METADATA_DONT_STRDUP_VAL);
+}
+
+static void avi_read_info(AVFormatContext *s, uint64_t end)
+{
+ while (url_ftell(s->pb) < end) {
+ uint32_t tag = get_le32(s->pb);
+ uint32_t size = get_le32(s->pb);
+ avi_read_tag(s, NULL, tag, size);
+ }
+}
+
+static const char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
+static void avi_metadata_creation_time(AVMetadata **metadata, char *date)
+{
+ char month[4], time[9], buffer[64];
+ int i, day, year;
+ /* parse standard AVI date format (ie. "Mon Mar 10 15:04:43 2003") */
+ if (sscanf(date, "%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d",
+ month, &day, time, &year) == 4) {
+ for (i=0; i<12; i++)
+ if (!strcasecmp(month, months[i])) {
+ snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%.2d %s",
+ year, i+1, day, time);
+ av_metadata_set2(metadata, "creation_time", buffer, 0);
+ }
+ } else if (date[4] == '/' && date[7] == '/') {
+ date[4] = date[7] = '-';
+ av_metadata_set2(metadata, "creation_time", date, 0);
+ }
+}
+
+static void avi_read_nikon(AVFormatContext *s, uint64_t end)
+{
+ while (url_ftell(s->pb) < end) {
+ uint32_t tag = get_le32(s->pb);
+ uint32_t size = get_le32(s->pb);
+ switch (tag) {
+ case MKTAG('n', 'c', 't', 'g'): { /* Nikon Tags */
+ uint64_t tag_end = url_ftell(s->pb) + size;
+ while (url_ftell(s->pb) < tag_end) {
+ uint16_t tag = get_le16(s->pb);
+ uint16_t size = get_le16(s->pb);
+ const char *name = NULL;
+ char buffer[64] = {0};
+ size -= get_buffer(s->pb, buffer,
+ FFMIN(size, sizeof(buffer)-1));
+ switch (tag) {
+ case 0x03: name = "maker"; break;
+ case 0x04: name = "model"; break;
+ case 0x13: name = "creation_time";
+ if (buffer[4] == ':' && buffer[7] == ':')
+ buffer[4] = buffer[7] = '-';
+ break;
+ }
+ if (name)
+ av_metadata_set2(&s->metadata, name, buffer, 0);
+ url_fskip(s->pb, size);
+ }
+ break;
+ }
+ default:
+ url_fskip(s->pb, size);
+ break;
+ }
+ }