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 51A3B4C00B for ; Wed, 5 Feb 2025 07:08:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 542DC68B407; Wed, 5 Feb 2025 09:08:48 +0200 (EET) Received: from xmbghk7.mail.qq.com (xmbghk7.mail.qq.com [43.163.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F211A680A4F for ; Wed, 5 Feb 2025 09:08:21 +0200 (EET) Received: from smtpclient.apple ([62.192.175.158]) by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP id 20B1405A; Wed, 05 Feb 2025 15:08:11 +0800 X-QQ-mid: xmsmtpt1738739291tv4ozi33m Message-ID: X-QQ-XMAILINFO: NB2Y38G+/V2Y0KXy+D+fbWlcI/N0yPVRhb7Fu4JryoxCxxc/VLoOG8R8lRldXl KAVoPeR2qGTT2LDXKVZEmETgpGkqj5CyVEyHm52gUDepIxClq8A71bX4mfyzahUr4XAGowbqJ0Wi cJetKpTxP4EqG7Gv441mCzVPYtpCgBzj79Xv7cR9+TgoalxrKrc3nsjyGVqegqKEqYCdMq9tcCtL 9WPzrWAefB6sH9467JJa/W9D0jKvlCuBRVplVe5qBuMKstNam2lyAYQF83LzlrIxnPEJsmR3IvKF WylMJ8GMpo5+iOC1Sq2y5l7m91exU9/1Z3erYVvAzgt+pR6CqvYiD6g3QfihFsQuPG1U+m7UdnkR U47yvdMmhvq3Bnmqe+PQSIK+wdjy8uEMyU6Kru44gfa8rAJRfzYPMABuU0UlF90meFlzm7/bIiF0 rFCYLEsuC1eFTy8m/XNJCBYM2w2s/AMAPZx9nTJsTQFy0kwxgpivSRANjGR9S0mKZKPJn/85z6dJ alpQXgBVsiFmZp0uNxvnV986TTMGd5WgV9ayGyA7JWvVYLMlc9F3yX24JDPZ4/5akmdCM/uxAM6e y1CIAEpN44rH1ezSxKdG3+tVdfLn09E6lcjeKTAyxH8MT3TffQHCg7pnk6D9qpDT9yMF8HEprtqu 4nt1LElp8QeXE1ZLhS8b44P5VWB3uiZb8vEDnNjttmzcr52v9CYUJ+9FzzkDOBRJMclpkxzX42IK VNf9FnMMB5+FLpwfVIe+5wYFNNY95nk5WMJU3ZXLjgim9l3gxxdDdz3U88/9n0edUpJC6urfEcgc 32UNmxe3l9l52TLkr63BCEALqUBLLwFC1ihe+bB8rCMbbIGXOuqAyi3Ct0q0csc3OUU5GV9h/80W zTIWmwuWpYMHs76LLV7elcjBUfdvLbk7+pFPhdZkrgu3mOM/GyD8DJAplWhUvy34Bl2BMYvGo2PN GymprGefI= X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= Content-Type: multipart/mixed; boundary="Apple-Mail=_2ED02250-3D13-4C7A-B6E7-95A0E8AE6E35" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.1\)) X-OQ-MSGID: <494E0230-57D2-42A4-8985-1676FEBB578F@qq.com> Date: Wed, 5 Feb 2025 15:08:00 +0800 To: FFmpeg development discussions and patches X-Mailer: Apple Mail (2.3776.700.51.11.1) Subject: [FFmpeg-devel] [PATCH v2] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --Apple-Mail=_2ED02250-3D13-4C7A-B6E7-95A0E8AE6E35 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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. --Apple-Mail=_2ED02250-3D13-4C7A-B6E7-95A0E8AE6E35 Content-Disposition: attachment; filename=0001-examples-transcoding-Fix-time_base-handling.eml Content-Type: message/rfc822; x-unix-mode=0644; name="0001-examples-transcoding-Fix-time_base-handling.eml" Content-Transfer-Encoding: quoted-printable =46rom=206a02fbaf6c6068040640ff105ad70115fb81b5d2=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Jack=20Lau=20=0ADate:=20= Tue,=204=20Feb=202025=2021:39:20=20+0800=0ASubject:=20[PATCH]=20= examples/transcoding:=20Fix=20time_base=20handling=0AX-Unsent:=201=0ATo:=20= ffmpeg-devel@ffmpeg.org=0A=0AThe=20`dec_ctx->time_base`=20was=20= incorrectly=20default=20set=20by=20avcodec_open2(),=20while=20= `enc_ctx->time_base`=20was=20derived=20from=20`dec_ctx->framerate`.=20= This=20mismatch=20could=20cause=20incorrect=20video=20duration=20in=20= the=20output.=0A=0AThis=20patch=20corrects=20the=20issue=20by=20= adjusting=20the=20`enc_ctx->time_base`=20calculation=20to=20account=20= for=20`ticks_per_frame`,=20ensuring=20that=20the=20time=20base=20is=20= consistent=20between=20the=20decoder=20and=20encoder=20contexts.=0A=0A= Signed-off-by:=20Jack=20Lau=20=0A---=0A=20= doc/examples/transcoding.c=20|=204=20++--=0A=201=20file=20changed,=202=20= insertions(+),=202=20deletions(-)=0A=0Adiff=20--git=20= a/doc/examples/transcoding.c=20b/doc/examples/transcoding.c=0Aindex=20= 013f89fc7d..8cc1991267=20100644=0A---=20a/doc/examples/transcoding.c=0A= +++=20b/doc/examples/transcoding.c=0A@@=20-172,7=20+172,7=20@@=20static=20= int=20open_output_file(const=20char=20*filename)=0A=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20else=0A=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20enc_ctx->pix_fmt=20=3D=20dec_ctx->pix_fmt;=0A=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20/*=20video=20time_base=20= can=20be=20set=20to=20whatever=20is=20handy=20and=20supported=20by=20= encoder=20*/=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= enc_ctx->time_base=20=3D=20av_inv_q(dec_ctx->framerate);=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20enc_ctx->time_base=20=3D=20= av_inv_q(av_mul_q(dec_ctx->framerate,=20= (AVRational){dec_ctx->ticks_per_frame,=201}));=0A=20=20=20=20=20=20=20=20= =20=20=20=20=20}=20else=20{=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20enc_ctx->sample_rate=20=3D=20dec_ctx->sample_rate;=0A=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20ret=20=3D=20= av_channel_layout_copy(&enc_ctx->ch_layout,=20&dec_ctx->ch_layout);=0A@@=20= -180,7=20+180,7=20@@=20static=20int=20open_output_file(const=20char=20= *filename)=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20return=20ret;=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20/*=20= take=20first=20format=20from=20list=20of=20supported=20formats=20*/=0A=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20enc_ctx->sample_fmt=20=3D=20= encoder->sample_fmts[0];=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20enc_ctx->time_base=20=3D=20(AVRational){1,=20enc_ctx->sample_rate};=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20enc_ctx->time_base=20=3D=20= (AVRational){1,dec_ctx->sample_rate};=0A=20=20=20=20=20=20=20=20=20=20=20= =20=20}=0A=20=0A=20=20=20=20=20=20=20=20=20=20=20=20=20if=20= (ofmt_ctx->oformat->flags=20&=20AVFMT_GLOBALHEADER)=0A--=20=0A2.48.1=0A=0A= --Apple-Mail=_2ED02250-3D13-4C7A-B6E7-95A0E8AE6E35 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --Apple-Mail=_2ED02250-3D13-4C7A-B6E7-95A0E8AE6E35--