From 00c67fe1d0bc7c2ce49daac9c80ea39d5a663b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st> Date: Wed, 29 Oct 2014 22:51:29 +0200 Subject: [PATCH] movenc: Write a 0 duration in mdhd and tkhd for an empty initial moov MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISO/IEC 14496-12:2012/Cor 1:2013 is explicit about how this should be handled. All zeros doesn't mean that the full file has got a zero duration, only that the track samples described within the initial moov have got zero duration. An all ones duration means an indeterminate duration. Keep writing a duration consisting of all ones for the ISM mode - older windows media player versions won't play a file if this is zero. (Newer windows media player versions play either version fine.) Signed-off-by: Martin Storsjö <martin@martin.st> --- libavformat/movenc.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 39d294697da..6184101eee9 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -1434,7 +1434,8 @@ static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track) return update_size(pb, pos); } -static int mov_write_mdhd_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_mdhd_tag(AVIOContext *pb, MOVMuxContext *mov, + MOVTrack *track) { int version = track->track_duration < INT32_MAX ? 0 : 1; @@ -1453,8 +1454,10 @@ static int mov_write_mdhd_tag(AVIOContext *pb, MOVTrack *track) avio_wb32(pb, track->time); /* modification time */ } avio_wb32(pb, track->timescale); /* time scale (sample rate for audio) */ - if (!track->entry) + if (!track->entry && mov->mode == MODE_ISM) (version == 1) ? avio_wb64(pb, UINT64_C(0xffffffffffffffff)) : avio_wb32(pb, 0xffffffff); + else if (!track->entry) + (version == 1) ? avio_wb64(pb, 0) : avio_wb32(pb, 0); else (version == 1) ? avio_wb64(pb, track->track_duration) : avio_wb32(pb, track->track_duration); /* duration */ avio_wb16(pb, track->language); /* language */ @@ -1470,12 +1473,13 @@ static int mov_write_mdhd_tag(AVIOContext *pb, MOVTrack *track) return 32; } -static int mov_write_mdia_tag(AVIOContext *pb, MOVTrack *track) +static int mov_write_mdia_tag(AVIOContext *pb, MOVMuxContext *mov, + MOVTrack *track) { int64_t pos = avio_tell(pb); avio_wb32(pb, 0); /* size */ ffio_wfourcc(pb, "mdia"); - mov_write_mdhd_tag(pb, track); + mov_write_mdhd_tag(pb, mov, track); mov_write_hdlr_tag(pb, track); mov_write_minf_tag(pb, track); return update_size(pb, pos); @@ -1517,8 +1521,10 @@ static int mov_write_tkhd_tag(AVIOContext *pb, MOVMuxContext *mov, } avio_wb32(pb, track->track_id); /* track-id */ avio_wb32(pb, 0); /* reserved */ - if (!track->entry) + if (!track->entry && mov->mode == MODE_ISM) (version == 1) ? avio_wb64(pb, UINT64_C(0xffffffffffffffff)) : avio_wb32(pb, 0xffffffff); + else if (!track->entry) + (version == 1) ? avio_wb64(pb, 0) : avio_wb32(pb, 0); else (version == 1) ? avio_wb64(pb, duration) : avio_wb32(pb, duration); @@ -1771,7 +1777,7 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, } if (track->tref_tag) mov_write_tref_tag(pb, track); - mov_write_mdia_tag(pb, track); + mov_write_mdia_tag(pb, mov, track); 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',' ')) -- GitLab