From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E26F04C013 for ; Wed, 5 Feb 2025 08:37:57 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 05EE768B518; Wed, 5 Feb 2025 10:37:53 +0200 (EET) Received: from out162-62-57-87.mail.qq.com (out162-62-57-87.mail.qq.com [162.62.57.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7309468837C for ; Wed, 5 Feb 2025 10:37:45 +0200 (EET) Received: from localhost.localdomain ([123.11.80.244]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 96238C9C; Wed, 05 Feb 2025 16:37:34 +0800 X-QQ-mid: xmsmtpt1738744654tqmq2xnqi Message-ID: X-QQ-XMAILINFO: OUUXHEo9i1ukbbJLruni/FIiiTxSnBaC2mn9FZUbNlI1ppVg4HfCcE66Ym+XXq Vx5aIcYJL2EBmX8/gW2CwTUhN0kvUoQ5Rh3/vrpfbFoyWeFfreXMl5YS+kiuGCp1xVlgZzW2MR7r T64sVJt/PedMkVxUCRIcmUWOXC4A/C2lJ96IGRdilBlRFHBJ5asJp204ppk8JADypHa5iS8CU+rN 3lGX1qPLvbdLi4OjDgwRFSz0zGcRCKtWQ8dPJOQICpmdjPrgvYyPHvNXq8eb6OoKzmyBMp5BxFC3 9ftyNzRvC99hSt7DvKzQQkfykDouYjCZPxwM3C1j5CLLBDW7WaL9Ngv2PipAbkwRMwUSGpEmgkn+ oXCG271TNDSSVspLmckYhPdP8Kebfw8aNlERnsnbGVhfRYneDKX1bMZ+ps4+p+bcWbftb1xuVaCo GDJshGrj/3ZRDwqY1E59LHexEXFYLheN/It7fLUoz7urqDolbEnQKEn/PZ2a06DgqGrfCvfDA3Ze PtjuAya9iWqNRtofvM97RhZchvOGq4r8+aw2aZhcjZkF9NSJLPojSGJv/7dMoRiUPbIiNmWNXoWP 0K0xLL+RbOmH9+jbQvJUegpjWL+8n5qPXoDI3ioUIDD8/TWfh6JqlesfDVOubEh6FP7TwO7DeKvQ i3DvL5cLnKlUeJrhlbIiVsoa73gvMh9q8/zbcjfqaduBCyR3fyDea8ys7Adi4JaEDrkcR85JiI0H 9WOOziCYoQrpV90R5zUjHpIxrTrthhRc+Tt8yUuy+Ia9nsqoeCeeA4tmHtV5TTvZ1q1t2ky8y0kN Vp1CSKua7a33noC7F2AElWqxGrl2xqPk+9k6+N6YnBRGEAUO7c8rZYgtNVl3RB+TzCNpeMF4v4kD TULDgg8TUWuKKQVG+7ZMXR78im4VEQ+ZCU0kFj/7Vp6JmHxuornIc692ftyhlB/qwPNgsmaGlJ X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= To: ffmpeg-devel@ffmpeg.org Date: Wed, 5 Feb 2025 16:37:32 +0800 X-OQ-MSGID: <20250205083732.15836-1-jacklau1222@qq.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] examples/transcoding: Fix time_base handling X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jack Lau via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Jack Lau , Jack Lau Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Jack Lau 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".