mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-18 22:55:12 +08:00
fftools/ffmpeg: set AVFrame.time_base after filtering
Makes it easier to track what timebase are the frame timestamps in and allows to stop accessing filters in code that shouldn't deal with filtering.
This commit is contained in:
@@ -678,17 +678,14 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
|
|||||||
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
|
double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision
|
||||||
AVCodecContext *enc = ost->enc_ctx;
|
AVCodecContext *enc = ost->enc_ctx;
|
||||||
AVRational filter_tb = (AVRational){ -1, -1 };
|
AVRational filter_tb = (AVRational){ -1, -1 };
|
||||||
if (!frame || frame->pts == AV_NOPTS_VALUE ||
|
if (!frame || frame->pts == AV_NOPTS_VALUE || !enc)
|
||||||
!enc || !ost->filter || !ost->filter->graph->graph)
|
|
||||||
goto early_exit;
|
goto early_exit;
|
||||||
|
|
||||||
{
|
{
|
||||||
AVFilterContext *filter = ost->filter->filter;
|
|
||||||
|
|
||||||
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
|
int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time;
|
||||||
AVRational tb = enc->time_base;
|
AVRational tb = enc->time_base;
|
||||||
int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
|
int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16);
|
||||||
filter_tb = av_buffersink_get_time_base(filter);
|
filter_tb = frame->time_base;
|
||||||
|
|
||||||
tb.den <<= extra_bits;
|
tb.den <<= extra_bits;
|
||||||
float_pts =
|
float_pts =
|
||||||
@@ -701,6 +698,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost,
|
|||||||
frame->pts =
|
frame->pts =
|
||||||
av_rescale_q(frame->pts, filter_tb, enc->time_base) -
|
av_rescale_q(frame->pts, filter_tb, enc->time_base) -
|
||||||
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
|
av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base);
|
||||||
|
frame->time_base = enc->time_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
early_exit:
|
early_exit:
|
||||||
@@ -1295,6 +1293,7 @@ static int reap_filters(int flush)
|
|||||||
AVRational tb = av_buffersink_get_time_base(filter);
|
AVRational tb = av_buffersink_get_time_base(filter);
|
||||||
ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb,
|
ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb,
|
||||||
AV_TIME_BASE_Q);
|
AV_TIME_BASE_Q);
|
||||||
|
filtered_frame->time_base = tb;
|
||||||
|
|
||||||
if (debug_ts)
|
if (debug_ts)
|
||||||
av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
|
av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n",
|
||||||
|
Reference in New Issue
Block a user