From e3f64d5656f478cc679bc2f6bcbda5c66bd077e7 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 12 Apr 2024 13:37:52 +0200 Subject: [PATCH] vcompress/lavc: report delayed frames Can indicate a problem, eg. currently SVT HEVC when doesn't manage to compress real-time. It can also indicate eg. B-frames presence which may be desired (requested by user parameters) but we can at least point it out. --- src/video_compress/libavcodec.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index e9e4a241f..94d2e2773 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -39,7 +39,9 @@ #include #include +#include #include +#include #include #include #include @@ -289,7 +291,8 @@ struct state_video_compress_libav { double mov_avg_comp_duration = 0; long mov_avg_frames = 0; - time_ns_t duration_warn_last_print; + time_ns_t duration_warn_last_print = 0; + int64_t max_pts_diff_reported = 0; map metadata_storage; }; @@ -1395,6 +1398,7 @@ static shared_ptr libavcodec_compress_tile(struct module *mod, shar return {}; } int ret = avcodec_receive_packet(s->codec_ctx, s->pkt); + const int64_t pkt_pts = s->pkt->pts; shared_ptr out{}; if (ret == 0) { out = out_vf_from_pkt(s, s->pkt); @@ -1409,6 +1413,17 @@ static shared_ptr libavcodec_compress_tile(struct module *mod, shar " s, compression " << (t3 - t2) / (double) NS_IN_SEC << " s\n"; check_duration(s, t1 - t0, t3 - t0); + if (!out) { + return {}; + } + + const int64_t pts_diff = s->cur_pts - pkt_pts - 1; + if (pts_diff > s->max_pts_diff_reported) { + MSG(WARNING, "Frame delayed %" PRId64 " frames by the compression!\n", + pts_diff); + s->max_pts_diff_reported = pts_diff; + } + if (s->store_orig_format) { write_orig_format(out.get(), tx->color_spec); }