#include <limits.h>
#include <stdint.h>
-//#define MOV_EXPORT_ALL_METADATA
-
#include "libavutil/attributes.h"
#include "libavutil/channel_layout.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/time_internal.h"
#include "libavutil/avstring.h"
#include "libavutil/dict.h"
+#include "libavutil/opt.h"
#include "libavcodec/ac3tab.h"
#include "avformat.h"
#include "internal.h"
static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
-#ifdef MOV_EXPORT_ALL_METADATA
char tmp_key[5];
-#endif
- char str[1024], key2[16], language[4] = {0};
+ char *str, key2[32], language[4] = {0};
const char *key = NULL;
uint16_t langcode = 0;
- uint32_t data_type = 0, str_size;
+ uint32_t data_type = 0, str_size, str_size_alloc;
int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL;
+ int raw = 0;
switch (atom.type) {
- case MKTAG(0xa9,'n','a','m'): key = "title"; break;
- case MKTAG(0xa9,'a','u','t'):
- case MKTAG(0xa9,'A','R','T'): key = "artist"; break;
+ case MKTAG( '@','P','R','M'): key = "premiere_version"; raw = 1; break;
+ case MKTAG( '@','P','R','Q'): key = "quicktime_version"; raw = 1; break;
+ case MKTAG( 'X','M','P','_'):
+ if (c->export_xmp) { key = "xmp"; raw = 1; } break;
case MKTAG( 'a','A','R','T'): key = "album_artist"; break;
- case MKTAG(0xa9,'w','r','t'): key = "composer"; break;
- case MKTAG( 'c','p','r','t'):
- case MKTAG(0xa9,'c','p','y'): key = "copyright"; break;
- case MKTAG(0xa9,'c','m','t'):
- case MKTAG(0xa9,'i','n','f'): key = "comment"; break;
- case MKTAG(0xa9,'a','l','b'): key = "album"; break;
- case MKTAG(0xa9,'d','a','y'): key = "date"; break;
- case MKTAG(0xa9,'g','e','n'): key = "genre"; break;
+ case MKTAG( 'a','k','I','D'): key = "account_type";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'a','p','I','D'): key = "account_id"; break;
+ case MKTAG( 'c','a','t','g'): key = "category"; break;
+ case MKTAG( 'c','p','i','l'): key = "compilation";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'c','p','r','t'): key = "copyright"; break;
+ case MKTAG( 'd','e','s','c'): key = "description"; break;
+ case MKTAG( 'd','i','s','k'): key = "disc";
+ parse = mov_metadata_track_or_disc_number; break;
+ case MKTAG( 'e','g','i','d'): key = "episode_uid";
+ parse = mov_metadata_int8_no_padding; break;
case MKTAG( 'g','n','r','e'): key = "genre";
parse = mov_metadata_gnre; break;
- case MKTAG(0xa9,'t','o','o'):
- case MKTAG(0xa9,'s','w','r'): key = "encoder"; break;
- case MKTAG(0xa9,'e','n','c'): key = "encoder"; break;
- case MKTAG(0xa9,'x','y','z'): key = "location"; break;
- case MKTAG( 'd','e','s','c'): key = "description";break;
+ case MKTAG( 'h','d','v','d'): key = "hd_video";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'k','e','y','w'): key = "keywords"; break;
case MKTAG( 'l','d','e','s'): key = "synopsis"; break;
- case MKTAG( 't','v','s','h'): key = "show"; break;
- case MKTAG( 't','v','e','n'): key = "episode_id";break;
- case MKTAG( 't','v','n','n'): key = "network"; break;
+ case MKTAG( 'l','o','c','i'):
+ return mov_metadata_loci(c, pb, atom.size);
+ case MKTAG( 'p','c','s','t'): key = "podcast";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'p','g','a','p'): key = "gapless_playback";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 'p','u','r','d'): key = "purchase_date"; break;
+ case MKTAG( 'r','t','n','g'): key = "rating";
+ parse = mov_metadata_int8_no_padding; break;
+ case MKTAG( 's','o','a','a'): key = "sort_album_artist"; break;
+ case MKTAG( 's','o','a','l'): key = "sort_album"; break;
+ case MKTAG( 's','o','a','r'): key = "sort_artist"; break;
+ case MKTAG( 's','o','c','o'): key = "sort_composer"; break;
+ case MKTAG( 's','o','n','m'): key = "sort_name"; break;
+ case MKTAG( 's','o','s','n'): key = "sort_show"; break;
+ case MKTAG( 's','t','i','k'): key = "media_type";
+ parse = mov_metadata_int8_no_padding; break;
case MKTAG( 't','r','k','n'): key = "track";
parse = mov_metadata_track_or_disc_number; break;
- case MKTAG( 'd','i','s','k'): key = "disc";
- parse = mov_metadata_track_or_disc_number; break;
+ case MKTAG( 't','v','e','n'): key = "episode_id"; break;
case MKTAG( 't','v','e','s'): key = "episode_sort";
parse = mov_metadata_int8_bypass_padding; break;
+ case MKTAG( 't','v','n','n'): key = "network"; break;
+ case MKTAG( 't','v','s','h'): key = "show"; break;
case MKTAG( 't','v','s','n'): key = "season_number";
parse = mov_metadata_int8_bypass_padding; break;
- case MKTAG( 's','t','i','k'): key = "media_type";
- parse = mov_metadata_int8_no_padding; break;
- case MKTAG( 'h','d','v','d'): key = "hd_video";
- parse = mov_metadata_int8_no_padding; break;
- case MKTAG( 'p','g','a','p'): key = "gapless_playback";
- parse = mov_metadata_int8_no_padding; break;
- case MKTAG( 'l','o','c','i'):
- return mov_metadata_loci(c, pb, atom.size);
+ case MKTAG(0xa9,'A','R','T'): key = "artist"; break;
+ case MKTAG(0xa9,'P','R','D'): key = "producer"; break;
+ case MKTAG(0xa9,'a','l','b'): key = "album"; break;
+ case MKTAG(0xa9,'a','u','t'): key = "artist"; break;
+ case MKTAG(0xa9,'c','h','p'): key = "chapter"; break;
+ case MKTAG(0xa9,'c','m','t'): key = "comment"; break;
+ case MKTAG(0xa9,'c','o','m'): key = "composer"; break;
+ case MKTAG(0xa9,'c','p','y'): key = "copyright"; break;
+ case MKTAG(0xa9,'d','a','y'): key = "date"; break;
+ case MKTAG(0xa9,'d','i','r'): key = "director"; break;
+ case MKTAG(0xa9,'d','i','s'): key = "disclaimer"; break;
+ case MKTAG(0xa9,'e','d','1'): key = "edit_date"; break;
+ case MKTAG(0xa9,'e','n','c'): key = "encoder"; break;
+ case MKTAG(0xa9,'f','m','t'): key = "original_format"; break;
+ case MKTAG(0xa9,'g','e','n'): key = "genre"; break;
+ case MKTAG(0xa9,'g','r','p'): key = "grouping"; break;
+ case MKTAG(0xa9,'h','s','t'): key = "host_computer"; break;
+ case MKTAG(0xa9,'i','n','f'): key = "comment"; break;
+ case MKTAG(0xa9,'l','y','r'): key = "lyrics"; break;
+ case MKTAG(0xa9,'m','a','k'): key = "make"; break;
+ case MKTAG(0xa9,'m','o','d'): key = "model"; break;
+ case MKTAG(0xa9,'n','a','m'): key = "title"; break;
+ case MKTAG(0xa9,'o','p','e'): key = "original_artist"; break;
+ case MKTAG(0xa9,'p','r','d'): key = "producer"; break;
+ case MKTAG(0xa9,'p','r','f'): key = "performers"; break;
+ case MKTAG(0xa9,'r','e','q'): key = "playback_requirements"; break;
+ case MKTAG(0xa9,'s','r','c'): key = "original_source"; break;
+ case MKTAG(0xa9,'s','t','3'): key = "subtitle"; break;
+ case MKTAG(0xa9,'s','w','r'): key = "encoder"; break;
+ case MKTAG(0xa9,'t','o','o'): key = "encoder"; break;
+ case MKTAG(0xa9,'t','r','k'): key = "track"; break;
+ case MKTAG(0xa9,'u','r','l'): key = "URL"; break;
+ case MKTAG(0xa9,'w','r','n'): key = "warning"; break;
+ case MKTAG(0xa9,'w','r','t'): key = "composer"; break;
+ case MKTAG(0xa9,'x','y','z'): key = "location"; break;
}
if (c->itunes_metadata && atom.size > 8) {
}
}
} else return 0;
- } else if (atom.size > 4 && key && !c->itunes_metadata) {
+ } else if (atom.size > 4 && key && !c->itunes_metadata && !raw) {
str_size = avio_rb16(pb); // string length
langcode = avio_rb16(pb);
ff_mov_lang_to_iso639(langcode, language);
} else
str_size = atom.size;
-#ifdef MOV_EXPORT_ALL_METADATA
- if (!key) {
+ if (c->export_all && !key) {
snprintf(tmp_key, 5, "%.4s", (char*)&atom.type);
key = tmp_key;
}
-#endif
if (!key)
return 0;
if (atom.size < 0)
return AVERROR_INVALIDDATA;
- str_size = FFMIN3(sizeof(str)-1, str_size, atom.size);
+ // allocate twice as much as worst-case
+ str_size_alloc = (raw ? str_size : str_size * 2) + 1;
+ str = av_malloc(str_size_alloc);
+ if (!str)
+ return AVERROR(ENOMEM);
if (parse)
parse(c, pb, str_size, key);
else {
- if (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff))) { // MAC Encoded
- mov_read_mac_string(c, pb, str_size, str, sizeof(str));
+ if (!raw && (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff)))) { // MAC Encoded
+ mov_read_mac_string(c, pb, str_size, str, str_size_alloc);
} else {
avio_read(pb, str, str_size);
str[str_size] = 0;
}
av_dlog(c->fc, "lang \"%3s\" ", language);
av_dlog(c->fc, "tag \"%s\" value \"%s\" atom \"%.4s\" %d %"PRId64"\n",
- key, str, (char*)&atom.type, str_size, atom.size);
+ key, str, (char*)&atom.type, str_size_alloc, atom.size);
+ av_freep(&str);
return 0;
}
if (atom.size < 16)
return 0;
+ /* skip version and flags */
+ avio_skip(pb, 4);
+
ff_mov_read_chan(c->fc, pb, st, atom.size - 4);
return 0;
return 0;
st = c->fc->streams[c->fc->nb_streams-1];
- ff_get_wav_header(pb, st->codec, atom.size);
-
- return 0;
+ return ff_get_wav_header(pb, st->codec, atom.size);
}
static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0;
}
+#define OFFSET(x) offsetof(MOVContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
+static const AVOption mov_options[] = {
+ { "export_all", "Export unrecognized metadata entries", OFFSET(export_all),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS },
+ { "export_xmp", "Export full XMP metadata", OFFSET(export_xmp),
+ AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, .flags = FLAGS },
+ { NULL },
+};
+
+static const AVClass mov_class = {
+ .class_name = "mov,mp4,m4a,3gp,3g2,mj2",
+ .item_name = av_default_item_name,
+ .option = mov_options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVInputFormat ff_mov_demuxer = {
.name = "mov,mp4,m4a,3gp,3g2,mj2",
.long_name = NULL_IF_CONFIG_SMALL("QuickTime / MOV"),
+ .priv_class = &mov_class,
.priv_data_size = sizeof(MOVContext),
.extensions = "mov,mp4,m4a,3gp,3g2,mj2",
.read_probe = mov_probe,