From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 3/3] fftools/ffmpeg_mux: print latency information in -debug_ts muxing output Date: Tue, 12 Dec 2023 13:09:58 +0100 Message-ID: <20231212120958.21313-3-anton@khirnov.net> (raw) In-Reply-To: <20231212120958.21313-1-anton@khirnov.net> --- fftools/ffmpeg_mux.c | 87 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 62925be8d0..ca1996622d 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -25,10 +25,12 @@ #include "ffmpeg_utils.h" #include "sync_queue.h" +#include "libavutil/avstring.h" #include "libavutil/fifo.h" #include "libavutil/intreadwrite.h" #include "libavutil/log.h" #include "libavutil/mem.h" +#include "libavutil/time.h" #include "libavutil/timestamp.h" #include "libavcodec/packet.h" @@ -59,6 +61,79 @@ static int64_t filesize(AVIOContext *pb) return ret; } +static void mux_log_debug_ts(OutputStream *ost, const AVPacket *pkt) +{ + static const char *desc[] = { + [LATENCY_PROBE_DEMUX] = "demux", + [LATENCY_PROBE_DEC_PRE] = "decode", + [LATENCY_PROBE_DEC_POST] = "decode", + [LATENCY_PROBE_FILTER_PRE] = "filter", + [LATENCY_PROBE_FILTER_POST] = "filter", + [LATENCY_PROBE_ENC_PRE] = "encode", + [LATENCY_PROBE_ENC_POST] = "encode", + [LATENCY_PROBE_NB] = "mux", + }; + + char latency[512] = { 0 }; + + if (pkt->opaque_ref) { + const FrameData *fd = (FrameData*)pkt->opaque_ref->data; + int64_t now = av_gettime_relative(); + int64_t total = INT64_MIN; + + int next; + + for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i = next) { + int64_t val = fd->wallclock[i]; + + next = i + 1; + + if (val == INT64_MIN) + continue; + + if (total == INT64_MIN) { + total = now - val; + snprintf(latency, sizeof(latency), "total:%gms", total / 1e3); + } + + // find the next valid entry + for (; next <= FF_ARRAY_ELEMS(fd->wallclock); next++) { + int64_t val_next = (next == FF_ARRAY_ELEMS(fd->wallclock)) ? + now : fd->wallclock[next]; + int64_t diff; + + if (val_next == INT64_MIN) + continue; + diff = val_next - val; + + // print those stages that take at least 5% of total + if (100. * diff > 5. * total) { + av_strlcat(latency, ", ", sizeof(latency)); + + if (!strcmp(desc[i], desc[next])) + av_strlcat(latency, desc[i], sizeof(latency)); + else + av_strlcatf(latency, sizeof(latency), "%s-%s:", + desc[i], desc[next]); + + av_strlcatf(latency, sizeof(latency), " %gms/%d%%", + diff / 1e3, (int)(100. * diff / total)); + } + + break; + } + + } + } + + av_log(ost, AV_LOG_INFO, "muxer <- pts:%s pts_time:%s dts:%s dts_time:%s " + "duration:%s duration_time:%s size:%d latency(%s)\n", + av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), + av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), + av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->st->time_base), + pkt->size, *latency ? latency : "N/A"); +} + static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) { MuxStream *ms = ms_from_ost(ost); @@ -140,16 +215,8 @@ static int write_packet(Muxer *mux, OutputStream *ost, AVPacket *pkt) pkt->stream_index = ost->index; - if (debug_ts) { - av_log(ost, AV_LOG_INFO, "muxer <- type:%s " - "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s duration:%s duration_time:%s size:%d\n", - av_get_media_type_string(ost->type), - av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &ost->st->time_base), - av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &ost->st->time_base), - av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &ost->st->time_base), - pkt->size - ); - } + if (debug_ts) + mux_log_debug_ts(ost, pkt); if (ms->stats.io) enc_stats_write(ost, &ms->stats, NULL, pkt, frame_num); -- 2.42.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-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2023-12-12 12:10 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-12 12:09 [FFmpeg-devel] [PATCH 1/3] fftools/ffmpeg: merge DemuxPktData into FrameData Anton Khirnov 2023-12-12 12:09 ` [FFmpeg-devel] [PATCH 2/3] fftools/ffmpeg: attach wallclock timing information to packets and frames Anton Khirnov 2023-12-12 12:09 ` Anton Khirnov [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231212120958.21313-3-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git