From: Stefano Sabatini <stefasab@gmail.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Stefano Sabatini <stefasab@gmail.com> Subject: [FFmpeg-devel] [PATCH 07/11] doc/examples/transcode: introduce timestamp logging Date: Sat, 2 Sep 2023 17:19:17 +0200 Message-ID: <20230902151921.1712373-8-stefasab@gmail.com> (raw) In-Reply-To: <20230902151921.1712373-1-stefasab@gmail.com> Aid timestamp debugging. --- doc/examples/transcode.c | 43 +++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/doc/examples/transcode.c b/doc/examples/transcode.c index 21ea14b614..5671c6664b 100644 --- a/doc/examples/transcode.c +++ b/doc/examples/transcode.c @@ -37,6 +37,7 @@ #include <libavutil/channel_layout.h> #include <libavutil/opt.h> #include <libavutil/pixdesc.h> +#include <libavutil/timestamp.h> static AVFormatContext *ifmt_ctx; static AVFormatContext *ofmt_ctx; @@ -435,6 +436,26 @@ static int init_filters(void) return 0; } +static void log_packet(AVPacket *pkt, const AVFormatContext *fmt_ctx, const char *tag) +{ + AVRational *time_base = &fmt_ctx->streams[pkt->stream_index]->time_base; + + av_log(NULL, AV_LOG_INFO, + "%s [pkt] stream:%d tb:%d/%d pts_time:%s\n", + tag, pkt->stream_index, time_base->num, time_base->den, + av_ts2timestr(pkt->pts, time_base)); +} + +static void log_frame(AVFrame *frame, int stream_index, const char *tag) +{ + AVRational *time_base = &frame->time_base; + + av_log(NULL, AV_LOG_INFO, + "%s [frame] stream:%d tb:%d/%d pts_time:%s\n", + tag, stream_index, time_base->num, time_base->den, + av_ts2timestr(frame->pts, time_base)); +} + static int encode_write_frame(unsigned int stream_index, int flush) { StreamContext *stream = &stream_ctx[stream_index]; @@ -443,16 +464,16 @@ static int encode_write_frame(unsigned int stream_index, int flush) AVPacket *enc_pkt = filter->enc_pkt; int ret; - av_log(NULL, AV_LOG_INFO, "Encoding frame\n"); /* encode filtered frame */ av_packet_unref(enc_pkt); - if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) + if (filt_frame && filt_frame->pts != AV_NOPTS_VALUE) { filt_frame->pts = av_rescale_q(filt_frame->pts, filt_frame->time_base, stream->enc_ctx->time_base); + log_frame(filt_frame, stream_index, "encoder <-"); + } ret = avcodec_send_frame(stream->enc_ctx, filt_frame); - if (ret < 0) return ret; @@ -468,8 +489,8 @@ static int encode_write_frame(unsigned int stream_index, int flush) stream->enc_ctx->time_base, ofmt_ctx->streams[stream_index]->time_base); - av_log(NULL, AV_LOG_DEBUG, "Muxing frame\n"); /* mux encoded frame */ + log_packet(enc_pkt, ofmt_ctx, "muxer <-"); ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt); } @@ -481,8 +502,11 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) FilteringContext *filter = &filter_ctx[stream_index]; int ret; - av_log(NULL, AV_LOG_INFO, "Pushing decoded frame to filters\n"); /* push the decoded frame into the filtergraph */ + if (frame) { + log_frame(frame, stream_index, "filters <-"); + } + ret = av_buffersrc_add_frame(filter->buffersrc_ctx, frame); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n"); @@ -491,7 +515,6 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) /* pull filtered frames from the filtergraph */ while (1) { - av_log(NULL, AV_LOG_INFO, "Pulling filtered frame from filters\n"); ret = av_buffersink_get_frame(filter->buffersink_ctx, filter->filtered_frame); if (ret < 0) { /* if no more frames for output - returns AVERROR(EAGAIN) @@ -505,6 +528,8 @@ static int filter_encode_write_frame(AVFrame *frame, unsigned int stream_index) filter->filtered_frame->time_base = av_buffersink_get_time_base(filter->buffersink_ctx); filter->filtered_frame->pict_type = AV_PICTURE_TYPE_NONE; + + log_frame(filter->filtered_frame, stream_index, "filters ->"); ret = encode_write_frame(stream_index, 0); av_frame_unref(filter->filtered_frame); if (ret < 0) @@ -549,13 +574,11 @@ int main(int argc, char **argv) if ((ret = av_read_frame(ifmt_ctx, packet)) < 0) break; stream_index = packet->stream_index; - av_log(NULL, AV_LOG_DEBUG, "Demuxer gave frame of stream_index %u\n", stream_index); + log_packet(packet, ifmt_ctx, "demuxer ->"); if (filter_ctx[stream_index].filter_graph) { StreamContext *stream = &stream_ctx[stream_index]; - av_log(NULL, AV_LOG_DEBUG, "Going to reencode&filter the frame\n"); - ret = avcodec_send_packet(stream->dec_ctx, packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Decoding failed\n"); @@ -569,6 +592,7 @@ int main(int argc, char **argv) else if (ret < 0) goto end; + log_frame(stream->dec_frame, stream_index, "decoder ->"); stream->dec_frame->pts = stream->dec_frame->best_effort_timestamp; ret = filter_encode_write_frame(stream->dec_frame, stream_index); if (ret < 0) @@ -580,6 +604,7 @@ int main(int argc, char **argv) ifmt_ctx->streams[stream_index]->time_base, ofmt_ctx->streams[stream_index]->time_base); + log_packet(packet, ofmt_ctx, "muxer <-"); ret = av_interleaved_write_frame(ofmt_ctx, packet); if (ret < 0) goto end; -- 2.34.1 _______________________________________________ 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".
next prev parent reply other threads:[~2023-09-02 15:21 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-09-02 15:19 [FFmpeg-devel] Review and fix doc/examples/transcode.c - version 2 Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 01/11] lavc/avcodec.h: fix typos in AVCodecContext.pkt_timebase description Stefano Sabatini 2023-09-03 7:37 ` Paul B Mahol 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 02/11] lavfi/aresample: show time_base information during setup Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 03/11] doc/examples/transcode: apply style fixes Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 04/11] doc/examples/transcode: factorize codec_type definition Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 05/11] doc/examples/transcode: improve reporting when the encoder is not found Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 06/11] doc/examples/transcode: use av_buffersrc_add_frame() Stefano Sabatini 2023-09-03 7:39 ` Paul B Mahol 2023-09-05 23:18 ` Stefano Sabatini 2023-09-02 15:19 ` Stefano Sabatini [this message] 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 08/11] doc/examples/transcode: use more meaningful labels for filtergraph sinks and sources Stefano Sabatini 2023-09-03 7:38 ` Paul B Mahol 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 09/11] doc/examples/transcode: fix timestamps scaling Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 10/11] doc/examples/transcode: simplify selection of pix_fmt Stefano Sabatini 2023-09-02 15:19 ` [FFmpeg-devel] [PATCH 11/11] doc/examples/transcode: fix selection of sample format if not set in encoder Stefano Sabatini 2023-09-03 7:41 ` Paul B Mahol 2023-09-05 23:48 ` Stefano Sabatini 2023-09-05 23:49 ` Stefano Sabatini 2023-09-06 0:37 ` Paul B Mahol
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=20230902151921.1712373-8-stefasab@gmail.com \ --to=stefasab@gmail.com \ --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