This reduces the need for an edit list; streams that start with
e.g. dts=-1, pts=0 can be encoded as dts=0, pts=0 (which is valid
in mov/mp4) by shifting the dts values of all packets forward.
This avoids the need for edit lists for such streams (while they
still are needed for audio streams with encoder delay).
---
libavformat/movenc.c | 24 ++++++++++++++++++++----
libavformat/movenc.h | 2 ++
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 840190d..713c145 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -62,6 +62,7 @@ static const AVOption options[] = {
{ "delay_moov", "Delay writing the initial moov until the first
fragment is cut, or until the first fragment flush", 0, AV_OPT_TYPE_CONST,
{.i64 = FF_MOV_FLAG_DELAY_MOOV}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
{ "global_sidx", "Write a global sidx index at the start of the
file", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_GLOBAL_SIDX}, INT_MIN,
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
{ "skip_trailer", "Skip writing the mfra/tfra/mfro trailer for
fragmented files", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SKIP_TRAILER},
INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "negative_cts_offsets", "Use negative CTS offsets (reducing the
need for edit lists)", 0, AV_OPT_TYPE_CONST, {.i64 =
FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS}, INT_MIN, INT_MAX,
AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
{ "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext,
iods_skip), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
{ "iods_audio_profile", "iods audio profile atom.",
offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.i64 = -1},
-1, 255, AV_OPT_FLAG_ENCODING_PARAM},
@@ -1163,8 +1164,9 @@ static int mov_write_stsd_tag(AVFormatContext *s,
AVIOContext *pb, MOVTrack *tra
return update_size(pb, pos);
}
-static int mov_write_ctts_tag(AVIOContext *pb, MOVTrack *track)
+static int mov_write_ctts_tag(AVFormatContext *s, AVIOContext *pb,
MOVTrack *track)
{
+ MOVMuxContext *mov = s->priv_data;
MOVStts *ctts_entries;
uint32_t entries = 0;
uint32_t atom_size;
@@ -1188,7 +1190,11 @@ static int mov_write_ctts_tag(AVIOContext *pb,
MOVTrack *track)
atom_size = 16 + (entries * 8);
avio_wb32(pb, atom_size); /* size */
ffio_wfourcc(pb, "ctts");
- avio_wb32(pb, 0); /* version & flags */
+ if (mov->flags & FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS)
+ avio_w8(pb, 1); /* version */