summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-03-19 11:24:00 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-03-19 12:09:51 +0100
commit76fef5cd27861ec3b574a06e8be6ea03bcdde7a5 (patch)
tree8836d8d9b2aa58e713b1e99f21c9adfd2854328e
parent4f8540ba40b79cacf14600c0ac2da5f5d5dc604f (diff)
parent2889c5e16711770437f380f1bead5f72c6a0b17a (diff)
downloadffmpeg-streaming-76fef5cd27861ec3b574a06e8be6ea03bcdde7a5.zip
ffmpeg-streaming-76fef5cd27861ec3b574a06e8be6ea03bcdde7a5.tar.gz
Merge commit '2889c5e16711770437f380f1bead5f72c6a0b17a'
* commit '2889c5e16711770437f380f1bead5f72c6a0b17a': movenc: Heuristically set the duration of the last sample in a fragment if not set Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/movenc.c26
-rw-r--r--libavformat/movenc.h1
-rw-r--r--tests/ref/fate/sub-movtextenc2
3 files changed, 28 insertions, 1 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 2f8539c..cf37c02 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -4093,6 +4093,32 @@ static int mov_flush_fragment(AVFormatContext *s)
if (!(mov->flags & FF_MOV_FLAG_FRAGMENT))
return 0;
+ for (i = 0; i < mov->nb_streams; i++) {
+ MOVTrack *track = &mov->tracks[i];
+ if (track->entry <= 1)
+ continue;
+ // Sample durations are calculated as the diff of dts values,
+ // but for the last sample in a fragment, we don't know the dts
+ // of the first sample in the next fragment, so we have to rely
+ // on what was set as duration in the AVPacket. Not all callers
+ // set this though, so we might want to replace it with an
+ // estimate if it currently is zero.
+ if (get_cluster_duration(track, track->entry - 1) != 0)
+ continue;
+ // Use the duration (i.e. dts diff) of the second last sample for
+ // the last one. This is a wild guess (and fatal if it turns out
+ // to be too long), but probably the best we can do - having a zero
+ // duration is bad as well.
+ track->track_duration += get_cluster_duration(track, track->entry - 2);
+ if (!mov->missing_duration_warned) {
+ av_log(s, AV_LOG_WARNING,
+ "Estimating the duration of the last packet in a "
+ "fragment, consider setting the duration field in "
+ "AVPacket instead.\n");
+ mov->missing_duration_warned = 1;
+ }
+ }
+
if (!mov->moov_written) {
int64_t pos = avio_tell(s->pb);
uint8_t *buf;
diff --git a/libavformat/movenc.h b/libavformat/movenc.h
index dfd4cc4..159e5f3 100644
--- a/libavformat/movenc.h
+++ b/libavformat/movenc.h
@@ -192,6 +192,7 @@ typedef struct MOVMuxContext {
float gamma;
int frag_interleave;
+ int missing_duration_warned;
} MOVMuxContext;
#define FF_MOV_FLAG_RTP_HINT (1 << 0)
diff --git a/tests/ref/fate/sub-movtextenc b/tests/ref/fate/sub-movtextenc
index 9b08b21..6efe2c0 100644
--- a/tests/ref/fate/sub-movtextenc
+++ b/tests/ref/fate/sub-movtextenc
@@ -1 +1 @@
-eacd7d65ec75c5520f5108b0a885a995
+ef264064c522389d0cf267c4d6235561
OpenPOWER on IntegriCloud