|
|
|
@ -135,20 +135,9 @@ static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt) |
|
|
|
|
pkt->size, *latency ? latency : "N/A"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) |
|
|
|
|
static int mux_fixup_ts(Muxer *mux, MuxStream *ms, AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
MuxStream *ms = ms_from_ost(ost); |
|
|
|
|
AVFormatContext *s = mux->fc; |
|
|
|
|
int64_t fs; |
|
|
|
|
uint64_t frame_num; |
|
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
fs = filesize(s->pb); |
|
|
|
|
atomic_store(&mux->last_filesize, fs); |
|
|
|
|
if (fs >= mux->limit_filesize) { |
|
|
|
|
ret = AVERROR_EOF; |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
OutputStream *ost = &ms->ost; |
|
|
|
|
|
|
|
|
|
#if FFMPEG_OPT_VSYNC_DROP |
|
|
|
|
if (ost->type == AVMEDIA_TYPE_VIDEO && ost->vsync_method == VSYNC_DROP) |
|
|
|
@ -174,7 +163,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) |
|
|
|
|
av_packet_rescale_ts(pkt, pkt->time_base, ost->st->time_base); |
|
|
|
|
pkt->time_base = ost->st->time_base; |
|
|
|
|
|
|
|
|
|
if (!(s->oformat->flags & AVFMT_NOTIMESTAMPS)) { |
|
|
|
|
if (!(mux->fc->oformat->flags & AVFMT_NOTIMESTAMPS)) { |
|
|
|
|
if (pkt->dts != AV_NOPTS_VALUE && |
|
|
|
|
pkt->pts != AV_NOPTS_VALUE && |
|
|
|
|
pkt->dts > pkt->pts) { |
|
|
|
@ -188,7 +177,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) |
|
|
|
|
if ((ost->type == AVMEDIA_TYPE_AUDIO || ost->type == AVMEDIA_TYPE_VIDEO || ost->type == AVMEDIA_TYPE_SUBTITLE) && |
|
|
|
|
pkt->dts != AV_NOPTS_VALUE && |
|
|
|
|
ms->last_mux_dts != AV_NOPTS_VALUE) { |
|
|
|
|
int64_t max = ms->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT); |
|
|
|
|
int64_t max = ms->last_mux_dts + !(mux->fc->oformat->flags & AVFMT_TS_NONSTRICT); |
|
|
|
|
if (pkt->dts < max) { |
|
|
|
|
int loglevel = max - pkt->dts > 2 || ost->type == AVMEDIA_TYPE_VIDEO ? AV_LOG_WARNING : AV_LOG_DEBUG; |
|
|
|
|
if (exit_on_error) |
|
|
|
@ -197,8 +186,7 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) |
|
|
|
|
"previous: %"PRId64", current: %"PRId64"; ", |
|
|
|
|
ms->last_mux_dts, pkt->dts); |
|
|
|
|
if (exit_on_error) { |
|
|
|
|
ret = AVERROR(EINVAL); |
|
|
|
|
goto fail; |
|
|
|
|
return AVERROR(EINVAL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
av_log(ost, loglevel, "changing to %"PRId64". This may result " |
|
|
|
@ -212,14 +200,36 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) |
|
|
|
|
} |
|
|
|
|
ms->last_mux_dts = pkt->dts; |
|
|
|
|
|
|
|
|
|
if (debug_ts) |
|
|
|
|
mux_log_debug_ts(ost, pkt); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
MuxStream *ms = ms_from_ost(ost); |
|
|
|
|
AVFormatContext *s = mux->fc; |
|
|
|
|
int64_t fs; |
|
|
|
|
uint64_t frame_num; |
|
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
fs = filesize(s->pb); |
|
|
|
|
atomic_store(&mux->last_filesize, fs); |
|
|
|
|
if (fs >= mux->limit_filesize) { |
|
|
|
|
ret = AVERROR_EOF; |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ret = mux_fixup_ts(mux, ms, pkt); |
|
|
|
|
if (ret < 0) |
|
|
|
|
goto fail; |
|
|
|
|
|
|
|
|
|
ms->data_size_mux += pkt->size; |
|
|
|
|
frame_num = atomic_fetch_add(&ost->packets_written, 1); |
|
|
|
|
|
|
|
|
|
pkt->stream_index = ost->index; |
|
|
|
|
|
|
|
|
|
if (debug_ts) |
|
|
|
|
mux_log_debug_ts(ost, pkt); |
|
|
|
|
|
|
|
|
|
if (ms->stats.io) |
|
|
|
|
enc_stats_write(ost, &ms->stats, NULL, pkt, frame_num); |
|
|
|
|
|
|
|
|
|