summaryrefslogtreecommitdiff
path: root/libavformat/movenc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-09-29 06:33:32 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-10-07 06:04:40 +0200
commit537ef8bebf8a35aab448db6ec876e275a10f0f15 (patch)
tree9c291f6a92041073d9e444c998b66aee6e2ebab2 /libavformat/movenc.c
parentd067e2543752fd80f10d1197952523c650ea5c44 (diff)
movenc: support an alternative to edit lists to handle the first DTS != 0 case.
Some software does not support edit lists at all, the adobe flash player seems to be one of these. Which results in AV sync errors when edit lists are used to adjust AV sync. 2nd try on implementing this, the first try had various issues Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/movenc.c')
-rw-r--r--libavformat/movenc.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 8ab1db8c5b..0e675855a0 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -61,6 +61,7 @@ static const AVOption options[] = {
{ "min_frag_duration", "Minimum fragment duration", offsetof(MOVMuxContext, min_fragment_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ "frag_size", "Maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
{ "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+ { "use_editlist", "use edit list", offsetof(MOVMuxContext, use_editlist), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
{ NULL },
};
@@ -83,6 +84,12 @@ static int64_t update_size(AVIOContext *pb, int64_t pos)
return curpos - pos;
}
+static int supports_edts(MOVMuxContext *mov)
+{
+ // EDTS with fragments is tricky as we dont know the duration when its written
+ return (mov->use_editlist<0 && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) || mov->use_editlist>0;
+}
+
static int is_co64_required(const MOVTrack *track)
{
int i;
@@ -1766,7 +1773,7 @@ static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov,
avio_wb32(pb, 0); /* size */
ffio_wfourcc(pb, "trak");
mov_write_tkhd_tag(pb, track, st);
- if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) // EDTS with fragments is tricky as we dont know the duration when its written
+ if (supports_edts(mov))
mov_write_edts_tag(pb, track); // PSP Movies and several other cases require edts box
if (track->tref_tag)
mov_write_tref_tag(pb, track);
@@ -3151,6 +3158,9 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt)
* of this packet to be what the previous packets duration implies. */
trk->cluster[trk->entry].dts = trk->start_dts + trk->track_duration;
}
+ if (!trk->entry && trk->start_dts == AV_NOPTS_VALUE && !supports_edts(mov)) {
+ trk->cluster[trk->entry].dts = trk->start_dts = 0;
+ }
if (trk->start_dts == AV_NOPTS_VALUE)
trk->start_dts = pkt->dts;
trk->track_duration = pkt->dts - trk->start_dts + pkt->duration;
@@ -3434,6 +3444,10 @@ static int mov_write_header(AVFormatContext *s)
mov->reserved_moov_size = -1;
}
+ if (!supports_edts(mov) && s->avoid_negative_ts < 0) {
+ s->avoid_negative_ts = 1;
+ }
+
/* Non-seekable output is ok if using fragmentation. If ism_lookahead
* is enabled, we don't support non-seekable output at all. */
if (!s->pb->seekable &&