diff options
author | Matthieu Bouron <matthieu.bouron@stupeflix.com> | 2016-06-23 22:02:31 +0200 |
---|---|---|
committer | Matthieu Bouron <matthieu.bouron@stupeflix.com> | 2016-06-23 22:02:31 +0200 |
commit | b1e1da52fe2e7320363fdaa0cdd276847e25bf53 (patch) | |
tree | 626b8c306915e23a0daefb3e39f64beccd70675a /libavformat/movenc.c | |
parent | 388f0957660027418ef931adaf21346e19ec2b67 (diff) | |
parent | e1eb0fc960163402bbb4e630185790488f7d28ed (diff) |
Merge commit 'e1eb0fc960163402bbb4e630185790488f7d28ed'
* commit 'e1eb0fc960163402bbb4e630185790488f7d28ed':
movenc: Use packets in interleaving queues for the duration at the end of fragments
Merged-by: Matthieu Bouron <matthieu.bouron@stupeflix.com>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r-- | libavformat/movenc.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 4e5f65f24b..0a7983658e 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -4241,6 +4241,25 @@ static int mov_flush_fragment(AVFormatContext *s, int force) if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) return 0; + // Try to fill in the duration of the last packet in each stream + // from queued packets in the interleave queues. If the flushing + // of fragments was triggered automatically by an AVPacket, we + // already have reliable info for the end of that track, but other + // tracks may need to be filled in. + for (i = 0; i < s->nb_streams; i++) { + MOVTrack *track = &mov->tracks[i]; + if (!track->end_reliable) { + AVPacket *next = ff_interleaved_peek(s, i); + if (next) { + track->track_duration = next->dts - track->start_dts; + if (next->pts != AV_NOPTS_VALUE) + track->end_pts = next->pts; + else + track->end_pts = next->dts; + } + } + } + for (i = 0; i < mov->nb_streams; i++) { MOVTrack *track = &mov->tracks[i]; if (track->entry <= 1) @@ -4316,6 +4335,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force) mov->tracks[i].track_duration - mov->tracks[i].cluster[0].dts; mov->tracks[i].entry = 0; + mov->tracks[i].end_reliable = 0; } avio_flush(s->pb); return 0; @@ -4395,6 +4415,7 @@ static int mov_flush_fragment(AVFormatContext *s, int force) track->frag_start += duration; track->entry = 0; track->entries_flushed = 0; + track->end_reliable = 0; if (!mov->frag_interleave) { if (!track->mdat_buf) continue; @@ -4760,6 +4781,7 @@ static int mov_write_single_packet(AVFormatContext *s, AVPacket *pkt) trk->end_pts = pkt->pts; else trk->end_pts = pkt->dts; + trk->end_reliable = 1; mov_auto_flush_fragment(s, 0); } } |