From: Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Jack Lau <jacklau1222@qq.com>, Jack Lau <jacklau1222gm@gmail.com>
Subject: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling
Date: Wed, 5 Feb 2025 16:37:32 +0800
Message-ID: <tencent_7ADFE69819D49D96FA8BC2C9E688CCEC2506@qq.com> (raw)
From: Jack Lau <jacklau1222gm@gmail.com>
The `dec_ctx->time_base` was incorrectly default set by avcodec_open2(), while `enc_ctx->time_base` was derived from `dec_ctx->framerate`. This mismatch could cause incorrect video duration in the output.
This patch corrects the issue by adjusting the `enc_ctx->time_base` calculation to account for `ticks_per_frame`, ensuring that the time base is consistent between the decoder and encoder contexts.
---
doc/examples/transcoding.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/doc/examples/transcoding.c b/doc/examples/transcoding.c
index 013f89fc7d..09c2ad4b62 100644
--- a/doc/examples/transcoding.c
+++ b/doc/examples/transcoding.c
@@ -172,7 +172,7 @@ static int open_output_file(const char *filename)
else
enc_ctx->pix_fmt = dec_ctx->pix_fmt;
/* video time_base can be set to whatever is handy and supported by encoder */
- enc_ctx->time_base = av_inv_q(dec_ctx->framerate);
+ enc_ctx->time_base = av_inv_q(av_mul_q(dec_ctx->framerate, (AVRational){dec_ctx->ticks_per_frame, 1}));
} else {
enc_ctx->sample_rate = dec_ctx->sample_rate;
ret = av_channel_layout_copy(&enc_ctx->ch_layout, &dec_ctx->ch_layout);
@@ -180,7 +180,7 @@ static int open_output_file(const char *filename)
return ret;
/* take first format from list of supported formats */
enc_ctx->sample_fmt = encoder->sample_fmts[0];
- enc_ctx->time_base = (AVRational){1, enc_ctx->sample_rate};
+ enc_ctx->time_base = (AVRational){1, dec_ctx->sample_rate};
}
if (ofmt_ctx->oformat->flags & AVFMT_GLOBALHEADER)
--
2.48.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 reply other threads:[~2025-02-05 8:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 8:37 Jack Lau via ffmpeg-devel [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-02-05 2:17 Jack Lau
2025-02-05 0:51 Jack Lau
2025-02-05 0:55 ` James Almer
2025-02-05 2:26 ` Jack Lau
2025-02-05 3:25 ` Jack Lau
2025-02-05 9:00 ` Jack Lau
2025-02-05 2:28 ` Jack Lau
2025-02-04 15:35 Jack Lau
2025-02-04 15:13 Jack Lau
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=tencent_7ADFE69819D49D96FA8BC2C9E688CCEC2506@qq.com \
--to=ffmpeg-devel@ffmpeg.org \
--cc=jacklau1222@qq.com \
--cc=jacklau1222gm@gmail.com \
/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