1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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>
This commit is contained in:
Michael Niedermayer 2012-09-29 06:33:32 +02:00
parent d067e25437
commit 537ef8bebf
2 changed files with 17 additions and 1 deletions

View File

@ -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 &&

View File

@ -165,6 +165,8 @@ typedef struct MOVMuxContext {
int max_fragment_size;
int ism_lookahead;
AVIOContext *mdat_buf;
int use_editlist;
} MOVMuxContext;
#define FF_MOV_FLAG_RTP_HINT 1