diff options
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r-- | libavformat/movenc.c | 112 |
1 files changed, 86 insertions, 26 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 1b61706da3..ebfcacb107 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -32,10 +32,27 @@ #include "libavcodec/put_bits.h" #include "internal.h" #include "libavutil/avstring.h" +#include "libavutil/opt.h" +#include "libavutil/dict.h" +#include "rtpenc.h" #undef NDEBUG #include <assert.h> +static const AVOption options[] = { + { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), FF_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + { "rtphint", "Add RTP hint tracks", 0, FF_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags), + { NULL }, +}; + +static const AVClass mov_muxer_class = { + .class_name = "MOV/3GP/MP4/3G2 muxer", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + //FIXME support 64 bit variant with wide placeholders static int64_t updateSize(AVIOContext *pb, int64_t pos) { @@ -1274,20 +1291,49 @@ static int mov_write_tapt_tag(AVIOContext *pb, MOVTrack *track) // This box seems important for the psp playback ... without it the movie seems to hang static int mov_write_edts_tag(AVIOContext *pb, MOVTrack *track) { - avio_wb32(pb, 0x24); /* size */ + int64_t duration = av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, + track->timescale, AV_ROUND_UP); + int version = duration < INT32_MAX ? 0 : 1; + int entry_size, entry_count, size; + int64_t delay, start_ct = track->cluster[0].cts; + delay = av_rescale_rnd(track->cluster[0].dts + start_ct, MOV_TIMESCALE, + track->timescale, AV_ROUND_DOWN); + version |= delay < INT32_MAX ? 0 : 1; + + entry_size = (version == 1) ? 20 : 12; + entry_count = 1 + (delay > 0); + size = 24 + entry_count * entry_size; + + /* write the atom data */ + avio_wb32(pb, size); ffio_wfourcc(pb, "edts"); - avio_wb32(pb, 0x1c); /* size */ + avio_wb32(pb, size - 8); ffio_wfourcc(pb, "elst"); - avio_wb32(pb, 0x0); - avio_wb32(pb, 0x1); + avio_w8(pb, version); + avio_wb24(pb, 0); /* flags */ - /* duration ... doesn't seem to effect psp */ - avio_wb32(pb, av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, - track->timescale, AV_ROUND_UP)); + avio_wb32(pb, entry_count); + if (delay > 0) { /* add an empty edit to delay presentation */ + if (version == 1) { + avio_wb64(pb, delay); + avio_wb64(pb, -1); + } else { + avio_wb32(pb, delay); + avio_wb32(pb, -1); + } + avio_wb32(pb, 0x00010000); + } - avio_wb32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */ + /* duration */ + if (version == 1) { + avio_wb64(pb, duration); + avio_wb64(pb, start_ct); + } else { + avio_wb32(pb, duration); + avio_wb32(pb, start_ct); + } avio_wb32(pb, 0x00010000); - return 0x24; + return size; } static int mov_write_tref_tag(AVIOContext *pb, MOVTrack *track) @@ -1319,12 +1365,12 @@ static int mov_write_uuid_tag_psp(AVIOContext *pb, MOVTrack *mov) return 0x34; } -static int mov_write_udta_sdp(AVIOContext *pb, AVCodecContext *ctx, int index) +static int mov_write_udta_sdp(AVIOContext *pb, AVFormatContext *ctx, int index) { char buf[1000] = ""; int len; - ff_sdp_write_media(buf, sizeof(buf), ctx, NULL, NULL, 0, 0); + ff_sdp_write_media(buf, sizeof(buf), ctx->streams[0]->codec, NULL, NULL, 0, 0, ctx); av_strlcatf(buf, sizeof(buf), "a=control:streamid=%d\r\n", index); len = strlen(buf); @@ -1344,7 +1390,7 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVTrack *track, AVStream *st) avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "trak"); mov_write_tkhd_tag(pb, track, st); - if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS) + if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS || track->cluster[0].dts) mov_write_edts_tag(pb, track); // PSP Movies require edts box if (track->tref_tag) mov_write_tref_tag(pb, track); @@ -1352,7 +1398,7 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVTrack *track, AVStream *st) if (track->mode == MODE_PSP) mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box if (track->tag == MKTAG('r','t','p',' ')) - mov_write_udta_sdp(pb, track->rtp_ctx->streams[0]->codec, track->trackID); + mov_write_udta_sdp(pb, track->rtp_ctx, track->trackID); if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && track->mode == MODE_MOV) { double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); if (0.0 != sample_aspect_ratio && 1.0 != sample_aspect_ratio) @@ -1491,15 +1537,15 @@ static int mov_write_string_metadata(AVFormatContext *s, AVIOContext *pb, int long_style) { int l, lang = 0, len, len2; - AVMetadataTag *t, *t2 = NULL; + AVDictionaryEntry *t, *t2 = NULL; char tag2[16]; - if (!(t = av_metadata_get(s->metadata, tag, NULL, 0))) + if (!(t = av_dict_get(s->metadata, tag, NULL, 0))) return 0; len = strlen(t->key); snprintf(tag2, sizeof(tag2), "%s-", tag); - while ((t2 = av_metadata_get(s->metadata, tag2, t2, AV_METADATA_IGNORE_SUFFIX))) { + while ((t2 = av_dict_get(s->metadata, tag2, t2, AV_DICT_IGNORE_SUFFIX))) { len2 = strlen(t2->key); if (len2 == len+4 && !strcmp(t->value, t2->value) && (l=ff_mov_iso639_to_lang(&t2->key[len2-3], 1)) >= 0) { @@ -1514,7 +1560,7 @@ static int mov_write_string_metadata(AVFormatContext *s, AVIOContext *pb, static int mov_write_trkn_tag(AVIOContext *pb, MOVMuxContext *mov, AVFormatContext *s) { - AVMetadataTag *t = av_metadata_get(s->metadata, "track", NULL, 0); + AVDictionaryEntry *t = av_dict_get(s->metadata, "track", NULL, 0); int size = 0, track = t ? atoi(t->value) : 0; if (track) { avio_wb32(pb, 32); /* size */ @@ -1606,7 +1652,7 @@ static int mov_write_3gp_udta_tag(AVIOContext *pb, AVFormatContext *s, const char *tag, const char *str) { int64_t pos = avio_tell(pb); - AVMetadataTag *t = av_metadata_get(s->metadata, str, NULL, 0); + AVDictionaryEntry *t = av_dict_get(s->metadata, str, NULL, 0); if (!t || !utf8len(t->value)) return 0; avio_wb32(pb, 0); /* size */ @@ -1618,7 +1664,7 @@ static int mov_write_3gp_udta_tag(AVIOContext *pb, AVFormatContext *s, avio_wb16(pb, language_code("eng")); /* language */ avio_write(pb, t->value, strlen(t->value)+1); /* UTF8 string value */ if (!strcmp(tag, "albm") && - (t = av_metadata_get(s->metadata, "track", NULL, 0))) + (t = av_dict_get(s->metadata, "track", NULL, 0))) avio_w8(pb, atoi(t->value)); } return updateSize(pb, pos); @@ -1637,10 +1683,10 @@ static int mov_write_chpl_tag(AVIOContext *pb, AVFormatContext *s) for (i = 0; i < nb_chapters; i++) { AVChapter *c = s->chapters[i]; - AVMetadataTag *t; + AVDictionaryEntry *t; avio_wb64(pb, av_rescale_q(c->start, c->time_base, (AVRational){1,10000000})); - if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { + if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { int len = FFMIN(strlen(t->value), 255); avio_w8(pb, len); avio_write(pb, t->value, len); @@ -1718,7 +1764,7 @@ static void mov_write_psp_udta_tag(AVIOContext *pb, static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s) { - AVMetadataTag *title = av_metadata_get(s->metadata, "title", NULL, 0); + AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0); int64_t pos, pos2; if (title) { @@ -2072,13 +2118,13 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum) for (i = 0; i < s->nb_chapters; i++) { AVChapter *c = s->chapters[i]; - AVMetadataTag *t; + AVDictionaryEntry *t; int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE}); pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); pkt.duration = end - pkt.dts; - if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { + if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { len = strlen(t->value); pkt.size = len+2; pkt.data = av_malloc(pkt.size); @@ -2125,7 +2171,15 @@ static int mov_write_header(AVFormatContext *s) if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters) mov->chapter_track = mov->nb_streams++; +#if FF_API_FLAG_RTP_HINT if (s->flags & AVFMT_FLAG_RTP_HINT) { + av_log(s, AV_LOG_WARNING, "The RTP_HINT flag is deprecated, enable it " + "via the -movflags rtphint muxer option " + "instead.\n"); + mov->flags |= FF_MOV_FLAG_RTP_HINT; + } +#endif + if (mov->flags & FF_MOV_FLAG_RTP_HINT) { /* Add hint tracks for each audio and video stream */ hint_track = mov->nb_streams; for (i = 0; i < s->nb_streams; i++) { @@ -2144,7 +2198,7 @@ static int mov_write_header(AVFormatContext *s) for(i=0; i<s->nb_streams; i++){ AVStream *st= s->streams[i]; MOVTrack *track= &mov->tracks[i]; - AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0); + AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); track->enc = st->codec; track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); @@ -2221,7 +2275,7 @@ static int mov_write_header(AVFormatContext *s) if (mov->chapter_track) mov_create_chapter_track(s, mov->chapter_track); - if (s->flags & AVFMT_FLAG_RTP_HINT) { + if (mov->flags & FF_MOV_FLAG_RTP_HINT) { /* Initialize the hint tracks for each audio and video stream */ for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; @@ -2298,6 +2352,7 @@ AVOutputFormat ff_mov_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_TGP_MUXER @@ -2314,6 +2369,7 @@ AVOutputFormat ff_tgp_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_MP4_MUXER @@ -2330,6 +2386,7 @@ AVOutputFormat ff_mp4_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_PSP_MUXER @@ -2346,6 +2403,7 @@ AVOutputFormat ff_psp_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_TG2_MUXER @@ -2362,6 +2420,7 @@ AVOutputFormat ff_tg2_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif #if CONFIG_IPOD_MUXER @@ -2378,5 +2437,6 @@ AVOutputFormat ff_ipod_muxer = { mov_write_trailer, .flags = AVFMT_GLOBALHEADER, .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0}, + .priv_class = &mov_muxer_class, }; #endif |