Signed-off-by: Nicolas George <geo...@nsup.org> --- fftools/ffmpeg.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2e9448ea2b..3919f2ab62 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1404,6 +1404,32 @@ static void finish_output_stream(OutputStream *ost) } } +static double compute_encoder_pts_from_filter_pts(AVFilterContext *filter, OutputFile *of, + AVCodecContext *enc, int64_t *filtered_frame_pts) +{ + double float_pts = AV_NOPTS_VALUE; + + if (*filtered_frame_pts != AV_NOPTS_VALUE) { + int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; + AVRational filter_tb = av_buffersink_get_time_base(filter); + AVRational tb = enc->time_base; + int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); + + tb.den <<= extra_bits; + float_pts = + av_rescale_q(*filtered_frame_pts, filter_tb, tb) - + av_rescale_q(start_time, AV_TIME_BASE_Q, tb); + float_pts /= 1 << extra_bits; + // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers + float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); + + *filtered_frame_pts = + av_rescale_q(*filtered_frame_pts, filter_tb, enc->time_base) - + av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); + } + return float_pts; +} + /** * Get and encode new output from any of the filtergraphs, without causing * activity. @@ -1460,24 +1486,7 @@ static int reap_filters(int flush) av_frame_unref(filtered_frame); continue; } - if (filtered_frame->pts != AV_NOPTS_VALUE) { - int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; - AVRational filter_tb = av_buffersink_get_time_base(filter); - AVRational tb = enc->time_base; - int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); - - tb.den <<= extra_bits; - float_pts = - av_rescale_q(filtered_frame->pts, filter_tb, tb) - - av_rescale_q(start_time, AV_TIME_BASE_Q, tb); - float_pts /= 1 << extra_bits; - // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers - float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); - - filtered_frame->pts = - av_rescale_q(filtered_frame->pts, filter_tb, enc->time_base) - - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); - } + float_pts = compute_encoder_pts_from_filter_pts(filter, of, enc, &filtered_frame->pts); switch (av_buffersink_get_type(filter)) { case AVMEDIA_TYPE_VIDEO: -- 2.27.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".