diff options
author | Martin Storsjö <martin@martin.st> | 2015-03-09 11:47:54 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2015-03-19 10:27:07 +0200 |
commit | b81b0cc22b22413760423e239ea644c9afdbfa2d (patch) | |
tree | cb952185939cb654545aaafdaeffa9da265b0b7d /libavformat/movenc.c | |
parent | 3041183677bda0a431b36e96a2c76617abaa8183 (diff) | |
download | ffmpeg-b81b0cc22b22413760423e239ea644c9afdbfa2d.tar.gz |
movenc: Set the last packet duration based on the next packet when autoflushing
When automatically flushing fragments based on set conditions
(fragmentation on keyframes, after some interval or byte size),
we already have the next packet for one stream - use this for setting
the duration of the last packet in the flushed fragment correctly.
This avoids having to adjust the timestamp of the first packet in
the new fragment since the last duration was unknown.
Unfortunately, this only works for automatic flushing (not for
caller-triggered flushing, like in the dash muxer), and only for the
one single track that triggered the flushing. The duration of the
last sample in all other tracks still is dependent on AVPacket
duration (or heuristics).
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r-- | libavformat/movenc.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index d2d75619eb..b9e75f420f 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -3561,8 +3561,14 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME && enc->codec_type == AVMEDIA_TYPE_VIDEO && trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) { - if (frag_duration >= mov->min_fragment_duration) + if (frag_duration >= mov->min_fragment_duration) { + // Set the duration of this track to line up with the next + // sample in this track. This avoids relying on AVPacket + // duration, but only helps for this particular track, not + // for the other ones that are flushed at the same time. + trk->track_duration = pkt->dts - trk->start_dts; mov_auto_flush_fragment(s); + } } return ff_mov_write_packet(s, pkt); |