aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/movenc.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2015-11-03 22:16:21 +0200
committerMartin Storsjö <martin@martin.st>2015-11-11 22:53:31 +0200
commitbef3b1f59f036aba4a5fe599b2480f6bd9e6b280 (patch)
tree9bddf06ae485a5d8bd2398cd07100db5c29adb85 /libavformat/movenc.c
parent3eeb7edfc2a1157b7b0e0ce21ac2cd44d55d405b (diff)
downloadffmpeg-bef3b1f59f036aba4a5fe599b2480f6bd9e6b280.tar.gz
movenc: Allow setting start_dts/start_cts before writing actual packets
By writing a zero-sized packet, the caller can communicate the start_dts/start_cts for the stream without actually writing the first packet. This allows doing random-access writing of fragments when the start dts of the stream isn't zero, so that the edit list in the moov is written based on timestamps from the nominal start time signaled via the zero-sized packet, while the first proper packet written corresponds to a later fragment. To avoid potential unexpected behaviour, empty packets only set start_dts if the frag_discont flag is set. Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r--libavformat/movenc.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index ac452b19c5..9f7cca9570 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -3585,9 +3585,6 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
int64_t frag_duration = 0;
int size = pkt->size;
- if (!pkt->size)
- return 0; /* Discard 0 sized packets */
-
if (mov->flags & FF_MOV_FLAG_FRAG_DISCONT) {
int i;
for (i = 0; i < s->nb_streams; i++)
@@ -3595,6 +3592,18 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
mov->flags &= ~FF_MOV_FLAG_FRAG_DISCONT;
}
+ if (!pkt->size) {
+ if (trk->start_dts == AV_NOPTS_VALUE && trk->frag_discont) {
+ trk->start_dts = pkt->dts;
+ if (pkt->pts != AV_NOPTS_VALUE)
+ trk->start_cts = pkt->pts - pkt->dts;
+ else
+ trk->start_cts = 0;
+ }
+
+ return 0; /* Discard 0 sized packets */
+ }
+
if (trk->entry)
frag_duration = av_rescale_q(pkt->dts - trk->cluster[0].dts,
s->streams[pkt->stream_index]->time_base,