diff options
author | Martin Storsjö <martin@martin.st> | 2014-11-23 23:23:43 +0200 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2014-12-18 23:14:27 +0200 |
commit | 59f0275dd0a42a7f90271a83a78e9ca5e69ff5b0 (patch) | |
tree | d44cef3e693df8726c54bdef3b29673876be87b3 | |
parent | 8a70ef94b9c377293b3dfa7d92cdc81a4fe1543a (diff) | |
download | ffmpeg-59f0275dd0a42a7f90271a83a78e9ca5e69ff5b0.tar.gz |
movenc: Adjust the pts of new fragments similarly to what is done for dts
The pts and the corresponding duration is written in sidx
atoms, thus make sure these match up correctly.
Signed-off-by: Martin Storsjö <martin@martin.st>
-rw-r--r-- | libavformat/movenc.c | 9 | ||||
-rw-r--r-- | libavformat/movenc.h | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f6109e6b63..a809c36e59 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -3290,6 +3290,11 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) * which might not exactly match our dts. Therefore adjust the dts * of this packet to be what the previous packets duration implies. */ trk->cluster[trk->entry].dts = trk->start_dts + trk->track_duration; + /* We also may have written the pts and the corresponding duration + * in sidx tags; make sure the sidx pts and duration match up with + * the next fragment. This means the cts of the first sample must + * be the same in all fragments. */ + pkt->pts = pkt->dts + trk->start_cts; } else { /* New fragment, but discontinuous from previous fragments. * Pretend the duration sum of the earlier fragments is @@ -3331,6 +3336,9 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) trk->flags |= MOV_TRACK_CTTS; trk->cluster[trk->entry].cts = pkt->pts - pkt->dts; trk->cluster[trk->entry].flags = 0; + if (trk->start_cts == AV_NOPTS_VALUE) + trk->start_cts = pkt->pts - pkt->dts; + if (enc->codec_id == AV_CODEC_ID_VC1) { mov_parse_vc1_frame(pkt, trk, mov->fragments); } else if (pkt->flags & AV_PKT_FLAG_KEY) { @@ -3708,6 +3716,7 @@ static int mov_write_header(AVFormatContext *s) * this is updated. */ track->hint_track = -1; track->start_dts = AV_NOPTS_VALUE; + track->start_cts = AV_NOPTS_VALUE; if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || diff --git a/libavformat/movenc.h b/libavformat/movenc.h index c13a834c7d..97c05831f2 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -104,6 +104,7 @@ typedef struct MOVTrack { uint32_t tref_tag; int tref_id; ///< trackID of the referenced track int64_t start_dts; + int64_t start_cts; int hint_track; ///< the track that hints this track, -1 if no hint track is set int src_track; ///< the track that this hint track describes |