You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
fftools/ffmpeg: use a separate variable for discontinuity offset
This will allow to move normal offset handling to demuxer thread, since discontinuities currently have to be processed in the main thread, as the code uses some decoder-produced values.
This commit is contained in:
@@ -3694,7 +3694,7 @@ static void decode_flush(InputFile *ifile)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
|
static void ts_discontinuity_detect(InputFile *ifile, InputStream *ist,
|
||||||
AVPacket *pkt)
|
AVPacket *pkt)
|
||||||
{
|
{
|
||||||
const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
|
const int fmt_is_discont = ifile->ctx->iformat->flags & AVFMT_TS_DISCONT;
|
||||||
@@ -3716,13 +3716,13 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
|
|||||||
if (fmt_is_discont) {
|
if (fmt_is_discont) {
|
||||||
if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
|
if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE ||
|
||||||
pkt_dts + AV_TIME_BASE/10 < FFMAX(ist->pts, ist->dts)) {
|
pkt_dts + AV_TIME_BASE/10 < FFMAX(ist->pts, ist->dts)) {
|
||||||
ifile->ts_offset -= delta;
|
ifile->ts_offset_discont -= delta;
|
||||||
av_log(NULL, AV_LOG_DEBUG,
|
av_log(NULL, AV_LOG_DEBUG,
|
||||||
"timestamp discontinuity for stream #%d:%d "
|
"timestamp discontinuity for stream #%d:%d "
|
||||||
"(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
|
"(id=%d, type=%s): %"PRId64", new offset= %"PRId64"\n",
|
||||||
ist->file_index, ist->st->index, ist->st->id,
|
ist->file_index, ist->st->index, ist->st->id,
|
||||||
av_get_media_type_string(ist->st->codecpar->codec_type),
|
av_get_media_type_string(ist->st->codecpar->codec_type),
|
||||||
delta, ifile->ts_offset);
|
delta, ifile->ts_offset_discont);
|
||||||
pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
||||||
if (pkt->pts != AV_NOPTS_VALUE)
|
if (pkt->pts != AV_NOPTS_VALUE)
|
||||||
pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
||||||
@@ -3745,10 +3745,10 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
|
|||||||
fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
|
fmt_is_discont && ifile->last_ts != AV_NOPTS_VALUE) {
|
||||||
int64_t delta = pkt_dts - ifile->last_ts;
|
int64_t delta = pkt_dts - ifile->last_ts;
|
||||||
if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
|
if (FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE) {
|
||||||
ifile->ts_offset -= delta;
|
ifile->ts_offset_discont -= delta;
|
||||||
av_log(NULL, AV_LOG_DEBUG,
|
av_log(NULL, AV_LOG_DEBUG,
|
||||||
"Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
|
"Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
|
||||||
delta, ifile->ts_offset);
|
delta, ifile->ts_offset_discont);
|
||||||
pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
pkt->dts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
||||||
if (pkt->pts != AV_NOPTS_VALUE)
|
if (pkt->pts != AV_NOPTS_VALUE)
|
||||||
pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
pkt->pts -= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base);
|
||||||
@@ -3758,6 +3758,26 @@ static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
|
|||||||
ifile->last_ts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
|
ifile->last_ts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ts_discontinuity_process(InputFile *ifile, InputStream *ist,
|
||||||
|
AVPacket *pkt)
|
||||||
|
{
|
||||||
|
int64_t offset = av_rescale_q(ifile->ts_offset_discont, AV_TIME_BASE_Q,
|
||||||
|
ist->st->time_base);
|
||||||
|
|
||||||
|
// apply previously-detected timestamp-discontinuity offset
|
||||||
|
// (to all streams, not just audio/video)
|
||||||
|
if (pkt->dts != AV_NOPTS_VALUE)
|
||||||
|
pkt->dts += offset;
|
||||||
|
if (pkt->pts != AV_NOPTS_VALUE)
|
||||||
|
pkt->pts += offset;
|
||||||
|
|
||||||
|
// detect timestamp discontinuities for audio/video
|
||||||
|
if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
|
||||||
|
ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) &&
|
||||||
|
pkt->dts != AV_NOPTS_VALUE)
|
||||||
|
ts_discontinuity_detect(ifile, ist, pkt);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return
|
* Return
|
||||||
* - 0 -- one packet was read and processed
|
* - 0 -- one packet was read and processed
|
||||||
@@ -3898,10 +3918,7 @@ static int process_input(int file_index)
|
|||||||
if (pkt->dts != AV_NOPTS_VALUE)
|
if (pkt->dts != AV_NOPTS_VALUE)
|
||||||
pkt->dts += duration;
|
pkt->dts += duration;
|
||||||
|
|
||||||
// detect and correct timestamp discontinuities for audio/video
|
// detect and try to correct for timestamp discontinuities
|
||||||
if ((ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
|
|
||||||
ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) &&
|
|
||||||
pkt->dts != AV_NOPTS_VALUE)
|
|
||||||
ts_discontinuity_process(ifile, ist, pkt);
|
ts_discontinuity_process(ifile, ist, pkt);
|
||||||
|
|
||||||
if (debug_ts) {
|
if (debug_ts) {
|
||||||
|
@@ -427,6 +427,10 @@ typedef struct InputFile {
|
|||||||
int input_sync_ref;
|
int input_sync_ref;
|
||||||
|
|
||||||
int64_t ts_offset;
|
int64_t ts_offset;
|
||||||
|
/**
|
||||||
|
* Extra timestamp offset added by discontinuity handling.
|
||||||
|
*/
|
||||||
|
int64_t ts_offset_discont;
|
||||||
int64_t last_ts;
|
int64_t last_ts;
|
||||||
int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
|
int64_t start_time; /* user-specified start time in AV_TIME_BASE or AV_NOPTS_VALUE */
|
||||||
int64_t recording_time;
|
int64_t recording_time;
|
||||||
|
Reference in New Issue
Block a user