From patchwork Sun May 7 13:32:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41520 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707556pzb; Sun, 7 May 2023 06:34:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4XGiTJn4rSUwARaZCr+imrroHoxcRRr/+2QMy0K4j/Gqqiy9z6UuVTowZj3jRGtd657Qq2 X-Received: by 2002:aa7:c7da:0:b0:50b:c693:70af with SMTP id o26-20020aa7c7da000000b0050bc69370afmr5429041eds.2.1683466454278; Sun, 07 May 2023 06:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466454; cv=none; d=google.com; s=arc-20160816; b=VxlAnVVbFRDh74mcyL7WOAS6JtEyRLx1OiejcKVS/zsQ6A46PWjreJFjTcyyegLuKk xWZFjZhnBsJ1RVe6q3sBgmOnxCIXGxA+QQdVS+KEW9gKC9ABe77SJT5Dlw7wvcKSntY2 3xjqOBR0SeawJv3DPMLbEEXhpl+XUHQ7BU/e6Ppecu9tzNUyMrWzfjDVh+P+po5fJmGY 8wnQI8SO4etLLakyN5R7pIAXYX+ote2J3kDVPlTmSQVPy//98ngPq4tcNCM4EzJBmFMp sBgrT4gI87r+W9R/ccrjxzhP+7s3yPyHYL9RMl5bOrM/v5sUiKbjObhebrKSyDKxUm05 XMIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=Z0zolSYmyf0V/c3jmicsN0mnbRqee6BVek6jrjNUEOo=; b=LPJLXsohFOY0MYldGtDIldhI0yvHUKKAzQuVh1THBEldxcyNYg/cm5a84mybknB2Gn LZ56WANMecYcED/KDJdch9xhyBqooe2ak9v+sDBKO6HccHojHFrUla7Tt6fqgG+2cqrO PMFWWQ9WXI7YioPD69OsQPOmSu5LohUPa6wEKu/kgsQhjW7uuNtEHF+IFLWq3kt+1Zo0 QIn4+Vtb9J+ZplRu5psliUrb/dlLVbsAimPRFAnCu2DPRlnvp6fjl2Cj1ZwgElKaoDb/ ceZ98DkUjnRYt8j0FL4NcJxhv9j4WOCD0bnKj761zQb1UtGJRfalDGpahmABM0ne+SFD LC/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i7-20020a50fc07000000b0050bcded050csi7216240edr.290.2023.05.07.06.34.13; Sun, 07 May 2023 06:34:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A0F3468C13C; Sun, 7 May 2023 16:33:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42CAF68C104 for ; Sun, 7 May 2023 16:33:23 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EA91E2404F5 for ; Sun, 7 May 2023 15:33:22 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id H35RnOpEv3M5 for ; Sun, 7 May 2023 15:33:21 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 494AA2406CD for ; Sun, 7 May 2023 15:33:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 329D33A031B for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:43 +0200 Message-Id: <20230507133255.20881-1-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: t7y0CIMxiRdZ --- libavutil/frame.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libavutil/frame.h b/libavutil/frame.h index f2b56beebb..ed3f199ce1 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -491,8 +491,22 @@ typedef struct AVFrame { void *opaque; /** - * When decoding, this signals how much the picture must be delayed. - * extra_delay = repeat_pict / (2*fps) + * Number of fields in this frame which should be repeated, i.e. the total + * duration of this frame should be repeat_pict + 2 normal field durations. + * + * For interlaced frames this field may be set to 1, which signals that this + * frame should be presented as 3 fields: beginning with the first field (as + * determined by AV_FRAME_FLAG_TOP_FIELD_FIRST being set or not), followed + * by the second field, and then the first field again. + * + * For progressive frames this field may be set to a multiple of 2, which + * signals that this frame's duration should be (repeat_pict + 2) / 2 + * normal frame durations. + * + * @note This field is computed from MPEG2 repeat_first_field flag and its + * associated flags, H.264 pic_struct from picture timing SEI, and + * their analogues in other codecs. Typically it should only be used when + * higher-layer timing information is not available. */ int repeat_pict; From patchwork Sun May 7 13:32:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41526 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1708098pzb; Sun, 7 May 2023 06:35:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Rd1P1gVpckouHzwnzDZwAvq3uryWn4IIqsxfYcAbqaTBAv2D8IbWwI36TbRJwnEcfpL2J X-Received: by 2002:a17:906:eecd:b0:965:8edf:8028 with SMTP id wu13-20020a170906eecd00b009658edf8028mr6390567ejb.42.1683466506735; Sun, 07 May 2023 06:35:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466506; cv=none; d=google.com; s=arc-20160816; b=C7jQmGetY/pki/IJarpCPCzw6rixhrvN8vA8kuVwqNTlxni8yqgc6J5lA52iM6xVBW ZAS0YPkTp0UJN/CqMpMpPaJcHN9vvDx8RZIkjopRDKnGcm3HalNx3ErUsafD6C3fSTeD TFbK2+UxdHvpSDUANtttrylZd5bdFmEY4wQZWXhIo7sgan+TPBix999MPdb/Ov2UsvZP +31L7Wnf12oQ3o31v2MyTCydGrFMna8Me4eyfFuT3H6IimO5XGMErujeVPQ1HsU150li AWwPsceyp60qhYw4iAsJq8BAYMAv3uks1xVgJWiFFvkxtvUrDjjlSAp19PVdc1F9+mXy GxFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=ofN8tTu040IG9zE5E0ptBvEFZHL1PVrhn672uIhNjU0=; b=kTFMlrq2VdgufC0cINsfhlsupJ7zwrjK0lElx8CVgtbEiVwYc3KHbVfaLXItlj7hpO CecZ8IejXoEZES3KPKYCuNww4BYGQA4t/ZfvtA+fyJ44E/CAbTLspHKamt6qcRtTN2b7 y6dvEf0r5koedKs1+mTaTzALmrt/e5d33iq7lmoVMobSpMQLo1A4nY+q22cZQXp4jz9g G67zcGhpSngoRnOTfQIhrK7bA20NlL5Nche3GbEemRe7LjJF0VlRbEEvBhuB0lv7XPsI PAQTjh+nXBZk7vjC3z+ghsjLY6Ci43CGXQveujKpium1LVMsAf61d61cOgIEMhc0x0OW x8DA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s11-20020a1709067b8b00b009659a414142si4083002ejo.454.2023.05.07.06.35.06; Sun, 07 May 2023 06:35:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 815DF68C1A1; Sun, 7 May 2023 16:33:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A229F68C13D for ; Sun, 7 May 2023 16:33:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 19DF32406CA for ; Sun, 7 May 2023 15:33:21 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id U_STi1GKKR1c for ; Sun, 7 May 2023 15:33:20 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 233982404EC for ; Sun, 7 May 2023 15:33:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3EF4B3A048F for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:44 +0200 Message-Id: <20230507133255.20881-2-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: a44ONTfCJk45 This field contains the number of _field_ durations by which the standard frame duration should be extended. --- fftools/ffmpeg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 8323c32ffd..4e45ab74b9 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1008,10 +1008,10 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr return frame->duration; if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) { - int ticks = frame->repeat_pict >= 0 ? - frame->repeat_pict + 1 : - ist->dec_ctx->ticks_per_frame; - codec_duration = av_rescale_q(ticks, av_inv_q(ist->dec_ctx->framerate), + int fields = frame->repeat_pict + 2; + AVRational field_rate = av_mul_q(ist->dec_ctx->framerate, + (AVRational){ 2, 1 }); + codec_duration = av_rescale_q(fields, av_inv_q(field_rate), ist->st->time_base); } From patchwork Sun May 7 13:32:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41527 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1708190pzb; Sun, 7 May 2023 06:35:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4M5A9MQSJuy+rrPckLtIv1Ttwd5AwXBOjoWM3+ut0UOPCNLrdX90va8ShCKsz3kd3CC24J X-Received: by 2002:a17:907:9806:b0:966:634d:9d84 with SMTP id ji6-20020a170907980600b00966634d9d84mr387504ejc.20.1683466515725; Sun, 07 May 2023 06:35:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466515; cv=none; d=google.com; s=arc-20160816; b=E00PfRgzaBpEH6z5Sp8Rf6Zz0GHwL2iksvc5oFe6d0rZVfb92Ykdirfs1vBfnmdbh4 XXnZgg0ql3cO015b4A51mgMh2fVCfdlZ8xAbElK+cPkkP3t6wUo7iUAfY16TkCDtF67+ sW9uhjE97iunwr8CQ1x4wgcrh8VrG/BShqyh5yrTWob5+uKL49GhfqUXSIu76ZlFmwzi AimqJilygl4JVX/wV6+4VaEd0f3MfXZN8sHZ8SSxQsQkpivYVN0EwrNT+9i5M9GWfrNl 577uiGw53C2hcWCaT+g1MPJBUBR5GRW8rTYkl5Ktp8pMJcxwnYeoU3qYDFPgku2HnEF/ e8rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=9eVMay1PDzmXIfBRr0WTOhojd3wbacHXfjlQcGMdDyg=; b=L9AJ4Q3wW1+KqDQlTjJITWDdQhhT0n6S/PmAowDuv7DYYKxRYug9+ibowCsPnY7siX KuO4AqyjJkvah5opLKzEG5sSpgDdsF4KQCLJzdewdYy6NEEiSRf79+iOffYj3qnOEJ2e HeS73Lko7ejstHPHjM0xUQt4SnNOcczZiU4KGpbt1HJVfld1bKL4Fx07fEy8nfIFFx4T dMOh/9ZNcEw1Pqk9u/qkuZ56YK59grDJlU3x11y/DsrPoLkigNDz+9sgyOjxHXBUv9Sn ZrSqinJcMgweu1tWTPlQv9Bygc9xHhEhFlV/Mm/VRd3qH+iQPcIO0VcjphwNFASq4bdP Wo1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id de13-20020a1709069bcd00b009572f7dadc5si4168954ejc.248.2023.05.07.06.35.15; Sun, 07 May 2023 06:35:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6EB4F68C1A6; Sun, 7 May 2023 16:33:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44B9F68C14D for ; Sun, 7 May 2023 16:33:22 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B91A02404EC for ; Sun, 7 May 2023 15:33:21 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id gqLhOPX3mxE2 for ; Sun, 7 May 2023 15:33:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 1F5A92406CB for ; Sun, 7 May 2023 15:33:14 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4A7883A11B4 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:45 +0200 Message-Id: <20230507133255.20881-3-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/13] lavc/codec_desc: add a property for codecs that support field coding 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JHrZxtw8ciFM Multiple places currently use AVCodecContext.ticks_per_frame > 1 to identify such codecs, which * requires a codec context * requires it to be open --- doc/APIchanges | 3 +++ libavcodec/codec_desc.c | 16 ++++++++++++---- libavcodec/codec_desc.h | 6 ++++++ libavcodec/version.h | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index fd01def1b2..777485ce86 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-05-xx - xxxxxxxxxx - lavc 60.11.100 - codec_desc.h + Add AV_CODEC_PROP_FIELDS. + 2023-05-04 - xxxxxxxxxx - lavu 58.7.100 - frame.h Deprecate AVFrame.interlaced_frame, AVFrame.top_field_first, and AVFrame.key_frame. diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index d40977d6b3..49dddd1a49 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -38,14 +38,20 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_VIDEO, .name = "mpeg1video", .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"), - .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER, + .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER | + // FIXME this is strigly speaking not true, as MPEG-1 does + // not allow field coding, but our mpeg12 code (decoder and + // parser) can sometimes change codec id at runtime, so + // this is safer + AV_CODEC_PROP_FIELDS, }, { .id = AV_CODEC_ID_MPEG2VIDEO, .type = AVMEDIA_TYPE_VIDEO, .name = "mpeg2video", .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"), - .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER, + .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER | + AV_CODEC_PROP_FIELDS, .profiles = NULL_IF_CONFIG_SMALL(ff_mpeg2_video_profiles), }, { @@ -225,7 +231,8 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_VIDEO, .name = "h264", .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), - .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS | AV_CODEC_PROP_REORDER, + .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS | + AV_CODEC_PROP_REORDER | AV_CODEC_PROP_FIELDS, .profiles = NULL_IF_CONFIG_SMALL(ff_h264_profiles), }, { @@ -529,7 +536,8 @@ static const AVCodecDescriptor codec_descriptors[] = { .type = AVMEDIA_TYPE_VIDEO, .name = "vc1", .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"), - .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER, + .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER | + AV_CODEC_PROP_FIELDS, .profiles = NULL_IF_CONFIG_SMALL(ff_vc1_profiles), }, { diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h index 126b52df47..dd4491112b 100644 --- a/libavcodec/codec_desc.h +++ b/libavcodec/codec_desc.h @@ -90,6 +90,12 @@ typedef struct AVCodecDescriptor { * equal. */ #define AV_CODEC_PROP_REORDER (1 << 3) + +/** + * Video codec supports separate coding of fields in interlaced frames. + */ +#define AV_CODEC_PROP_FIELDS (1 << 4) + /** * Subtitle codec is bitmap based * Decoded AVSubtitle data can be read from the AVSubtitleRect->pict field. diff --git a/libavcodec/version.h b/libavcodec/version.h index 80e2ae630d..8b53586be1 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #include "version_major.h" -#define LIBAVCODEC_VERSION_MINOR 10 +#define LIBAVCODEC_VERSION_MINOR 11 #define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ From patchwork Sun May 7 13:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41525 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707975pzb; Sun, 7 May 2023 06:34:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XpqV8ygJW8loUxuRQrFUHl7y8vnEdr9HvC+bvPGikm246gnIxGP5JYrudxzCkDMo30K4G X-Received: by 2002:a05:6402:1256:b0:50b:c5dc:28d8 with SMTP id l22-20020a056402125600b0050bc5dc28d8mr5646639edw.16.1683466497716; Sun, 07 May 2023 06:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466497; cv=none; d=google.com; s=arc-20160816; b=0zY5X4lGbTxJ8e1wpgeGjSE7MLCIyME1G6H0UplxyfUKydVB+3p5ujr9IRdt8QNEy0 IMAFFgBjAioyPGEFP1dqSvROLPbT0ZnkxtOZgDExtxiXsP5w+ei7BsqryLfCA+nGMEZ2 4eFpfjpDXsAgWqNoO2p7df0FClqCdpgOTamtrxTonZroeSI8B2CpYYOl5TSQipHIxLrc ijRjnZyTvR6V4eH3FQUiWgErYwhEtpiNicu8BcgmpnQ67349GvzUYHQIBz9uChYJ0K7H 7v03HKv8UvegSvvUPdFhwhbFKs1fiCaQWsVIOrDp5acfgk/tEWsJd7Adi9m7FWlvJTAj LSWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=iCkcAyYCaBMmvDyCsFlWrTuF34KMQpaWr2oLKOM9LJ4=; b=TtLweFbosK3z4aO+fR7sk5HDiC1yMyw/M00nSQj2MCJbEeqQrku8A0BwWBtOTYutR0 LEk9Djt0Xs83VaACPNrIPuXQIuLPVdC9vun35Xj8OXPj2KVUKLdsxRAw1UuqcA5eK7Ii Kj2MC8alc0BcvQyg5ezKh1+aCOw4DyJzREJ2wWJ8LmglgW7YPQz0ji+6BCaiImFi+6xx a0LoEfwtUWOTLMvR0PAQrw6dKdbzwpkc513Pwwj1tPIgmr2VNQRqW6tGJB7M1AyK76ky kkzBPgdO3hwfn88DMbepS5RPFK3+9LeD5NSljbnhMCyanlez5U/ZdK2d3SETFnwptdbb CT5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q20-20020aa7d454000000b0050bd2d66983si7273827edr.255.2023.05.07.06.34.57; Sun, 07 May 2023 06:34:57 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8985368C196; Sun, 7 May 2023 16:33:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C23F68C13C for ; Sun, 7 May 2023 16:33:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 845B22405EC for ; Sun, 7 May 2023 15:33:20 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xnkJTFhYfiAs for ; Sun, 7 May 2023 15:33:19 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 1DA0A2406CA for ; Sun, 7 May 2023 15:33:14 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 560DA3A11DB for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:46 +0200 Message-Id: <20230507133255.20881-4-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kCe90BLLmul/ H.264 and mpeg12 parsers need to be adjusted at the same time to stop using the value of AVCodecContext.ticks_per_frame, because it is not set correctly unless the codec has been opened. Previously this would result in both the parser and lavf seeing the same incorrect value, which would cancel out. Updating lavf and not the parsers would result in correct value in lavf, but the wrong one in parsers, which would break some tests. --- libavcodec/h264_parser.c | 4 ++-- libavcodec/mpegvideo_parser.c | 2 +- libavformat/avformat.c | 9 ++++++--- libavformat/demux.c | 29 +++++++++++++++++++---------- libavformat/internal.h | 3 +++ 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 46134a1c48..43abc45f9c 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -568,7 +568,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, if (p->sei.common.unregistered.x264_build < 44U) den *= 2; av_reduce(&avctx->framerate.den, &avctx->framerate.num, - sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 << 30); + sps->num_units_in_tick * 2, den, 1 << 30); } av_freep(&rbsp.rbsp_buffer); @@ -625,7 +625,7 @@ static int h264_parse(AVCodecParserContext *s, parse_nal_units(s, avctx, buf, buf_size); if (avctx->framerate.num) - time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1})); + time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){2, 1})); if (p->sei.picture_timing.cpb_removal_delay >= 0) { s->dts_sync_point = p->sei.buffering_period.present; s->dts_ref_dts_delta = p->sei.picture_timing.cpb_removal_delay; diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 8e7e88ff25..08e5316960 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -129,6 +129,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, s->pict_type = (buf[1] >> 3) & 7; if (bytes_left >= 4) vbv_delay = ((buf[1] & 0x07) << 13) | (buf[2] << 5) | (buf[3] >> 3); + s->repeat_pict = 1; } break; case SEQ_START_CODE: @@ -186,7 +187,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, progressive_frame = buf[4] & (1 << 7); /* check if we must repeat the frame */ - s->repeat_pict = 1; if (repeat_first_field) { if (pc->progressive_sequence) { if (top_field_first) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 708d90b38c..fea905693d 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -679,6 +679,7 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame) { AVRational fr = st->r_frame_rate; + const AVCodecDescriptor *desc = cffstream(st)->codec_desc; AVCodecContext *const avctx = ffstream(st)->avctx; AVRational codec_fr = avctx->framerate; AVRational avg_fr = st->avg_frame_rate; @@ -688,7 +689,7 @@ AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *f fr = avg_fr; } - if (avctx->ticks_per_frame > 1) { + if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) { if ( codec_fr.num > 0 && codec_fr.den > 0 && (fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1)) fr = codec_fr; @@ -701,10 +702,12 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVStream *ost, const AVStream *ist, enum AVTimebaseSource copy_tb) { + const AVCodecDescriptor *desc = cffstream(ist)->codec_desc; const AVCodecContext *const dec_ctx = cffstream(ist)->avctx; AVCodecContext *const enc_ctx = ffstream(ost)->avctx; - AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, - (AVRational){dec_ctx->ticks_per_frame, 1})) + + AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; + AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, mul)) : (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1} : ist->time_base); diff --git a/libavformat/demux.c b/libavformat/demux.c index 45e5f5c4c2..1e47cd2bba 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -213,6 +213,8 @@ FF_ENABLE_DEPRECATION_WARNINGS if (ret < 0) return ret; + sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); + sti->need_context_update = 0; } return 0; @@ -677,10 +679,11 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, *pnum = st->time_base.num; *pden = st->time_base.den; } else if (codec_framerate.den * 1000LL > codec_framerate.num) { - av_assert0(sti->avctx->ticks_per_frame); + int ticks_per_frame = (sti->codec_desc && + (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1; av_reduce(pnum, pden, codec_framerate.den, - codec_framerate.num * (int64_t)sti->avctx->ticks_per_frame, + codec_framerate.num * (int64_t)ticks_per_frame, INT_MAX); if (pc && pc->repeat_pict) { @@ -692,7 +695,8 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden, /* If this codec can be interlaced or progressive then we need * a parser to compute duration of a packet. Thus if we have * no parser in such case leave duration undefined. */ - if (sti->avctx->ticks_per_frame > 1 && !pc) + if (sti->codec_desc && + (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc) *pnum = *pden = 0; } break; @@ -1288,6 +1292,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) return ret; } + sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id); + sti->need_context_update = 0; } @@ -2164,9 +2170,10 @@ static int get_std_framerate(int i) static int tb_unreliable(AVFormatContext *ic, AVStream *st) { FFStream *const sti = ffstream(st); + const AVCodecDescriptor *desc = sti->codec_desc; AVCodecContext *c = sti->avctx; - AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, - (AVRational){c->ticks_per_frame, 1})) + AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; + AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul)) /* NOHEADER check added to not break existing behavior */ : (((ic->ctx_flags & AVFMTCTX_NOHEADER) || st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? (AVRational){0, 1} @@ -2718,13 +2725,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) break; } if (pkt->duration > 0) { + const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS); if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time && (uint64_t)pkt->pts - st->start_time < INT64_MAX ) { sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration); } else sti->info->codec_info_duration += pkt->duration; - sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && avctx->ticks_per_frame == 2 + sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields ? sti->parser->repeat_pict + 1 : 2; } } @@ -2864,15 +2872,16 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) best_fps, 12 * 1001, INT_MAX); } if (!st->r_frame_rate.num) { - AVRational time_base = avctx->framerate.num ? av_inv_q(av_mul_q(avctx->framerate, - (AVRational){avctx->ticks_per_frame, 1})) + const AVCodecDescriptor *desc = sti->codec_desc; + AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 }; + AVRational time_base = avctx->framerate.num ? av_inv_q(av_mul_q(avctx->framerate, mul)) /* NOHEADER check added to not break existing behavior */ : ((ic->ctx_flags & AVFMTCTX_NOHEADER) ? (AVRational){0, 1} : st->time_base); if ( time_base.den * (int64_t) st->time_base.num - <= time_base.num * (uint64_t)avctx->ticks_per_frame * st->time_base.den) { + <= time_base.num * (uint64_t)mul.num * st->time_base.den) { av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, - time_base.den, (int64_t)time_base.num * avctx->ticks_per_frame, INT_MAX); + time_base.den, (int64_t)time_base.num * mul.num, INT_MAX); } else { st->r_frame_rate.num = st->time_base.den; st->r_frame_rate.den = st->time_base.num; diff --git a/libavformat/internal.h b/libavformat/internal.h index f575064e8f..40c46311c8 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -23,6 +23,7 @@ #include +#include "libavcodec/codec_desc.h" #include "libavcodec/packet_internal.h" #include "avformat.h" @@ -408,6 +409,8 @@ typedef struct FFStream { */ int64_t first_dts; int64_t cur_dts; + + const AVCodecDescriptor *codec_desc; } FFStream; static av_always_inline FFStream *ffstream(AVStream *st) From patchwork Sun May 7 13:32:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41517 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707297pzb; Sun, 7 May 2023 06:33:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jBJrhcWECyE8ClrR/pvACnK1r2mEhZuyVaepQn2jJAdTclE2wEJHe5ZE5QTo2AsDAdtDe X-Received: by 2002:a17:907:6e0c:b0:93e:8791:7d8e with SMTP id sd12-20020a1709076e0c00b0093e87917d8emr6009669ejc.2.1683466427893; Sun, 07 May 2023 06:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466427; cv=none; d=google.com; s=arc-20160816; b=U5Xca2J/4WNtEzs+uzi3En/X5d7QKMbl0S7eKeSxjhnplBVW4Jq/XoSEhMVUpGbvIJ qM0qgjVRB1Q2+RoOCpYhPioUAP+5+M4Vx5eL+P2SI8DsdFLUvkSb+Uak2niAd0Bu4htv 4k3XceJEbkm1gCJ475ztd8ZcCTN7KxGgrn1P+keQxGK9kSPbddyx8XDkCYoY1AlbxNCi GbFe+ZObKYGRjXaa1Kq6dYTJqcSJzuE3awJ9QgYS3ghl5iyp+rE5WEsBemLgvwUgKRPw Xp+4VFvlumqnK7nQNr79z7+8S8rfQCoGUIPwbo0YOnLtmAu494F/eio+noazhW6Rps+w LQhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=Ld5igpEot/6fjsEnNhLxRueOa0Q8Yl+yJPa0NTNx1vY=; b=F9IOj/qAbAK9eN2pyJPqbjgm2YntiimC6XuT6qM98dXbT490WxxzDBR+A2ONOrkhZP uYa8RjfzRykpNltN78z23HsQ+2qrdk4f1yHMrKcY0YXAd0um+V/+PdYvFvcJbjo6M/0k epw5qh0+JuiNrmR2kR9L3qcUIKv8Un7uRgMFR55/abl054W5p3YhQGw7jes0Y9+XaP2+ XbACD8fHfWyTcUi9VwgLvZnL5flbcaOwR+flhvpC1JXdhdlIRl0hl6FkstKRwTZKRj2Z VczQ85U4PjhtTxqcL8PMQ7xei3OuHw4Z/7rMMg9weYo0yWPaU6eMPh+R0v85wCmTcDC/ 0vJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hp29-20020a1709073e1d00b00965e7c0e21csi4087022ejc.496.2023.05.07.06.33.47; Sun, 07 May 2023 06:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 84EDD68C111; Sun, 7 May 2023 16:33:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6331A68BFF3 for ; Sun, 7 May 2023 16:33:16 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2B1922404F5 for ; Sun, 7 May 2023 15:33:16 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id U8zTTJOqMMfc for ; Sun, 7 May 2023 15:33:12 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6F633240177 for ; Sun, 7 May 2023 15:33:12 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 60E5A3A1251 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:47 +0200 Message-Id: <20230507133255.20881-5-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OEiWLseI/qtA * take num_ticks_per_picture_minus_1 into account, since that is a part of the framerate computation * stop exporting num_ticks_per_picture_minus_1 into AVCodecContext.ticks_per_frame, as that field is used for other purposes (in conjunction with repeat_pict, which is not used at all by av1) --- libavcodec/Makefile | 2 +- libavcodec/av1_parse.c | 15 +++++++++++++++ libavcodec/av1_parse.h | 4 ++++ libavcodec/av1_parser.c | 9 ++++----- libavcodec/av1dec.c | 12 +++--------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b0971ce833..8162bcf4fa 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \ ac3_channel_layout_tab.o OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o -OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o +OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c index 59ea0bc6e7..cf325e09b9 100644 --- a/libavcodec/av1_parse.c +++ b/libavcodec/av1_parse.c @@ -24,6 +24,7 @@ #include "av1.h" #include "av1_parse.h" +#include "cbs_av1.h" #include "bytestream.h" int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx) @@ -108,3 +109,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt) av_freep(&pkt->obus); pkt->obus_allocated = pkt->obus_allocated_size = 0; } + +AVRational ff_av1_framerate(const AV1RawTimingInfo *ti) +{ + const int ticks = ti->num_ticks_per_picture_minus_1 + 1; + AVRational fr = (AVRational){ 0, 1 }; + + if (ti->num_units_in_display_tick && ti->time_scale && + ticks < INT_MAX / ti->num_units_in_display_tick) { + av_reduce(&fr.den, &fr.num, ti->num_units_in_display_tick * ticks, + ti->time_scale, INT_MAX); + } + + return fr; +} diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h index f4a5d2830e..60a6fd0ba2 100644 --- a/libavcodec/av1_parse.h +++ b/libavcodec/av1_parse.h @@ -181,4 +181,8 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type) return size; } +struct AV1RawTimingInfo; + +AVRational ff_av1_framerate(const struct AV1RawTimingInfo *ti); + #endif /* AVCODEC_AV1_PARSE_H */ diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c index 14dae92fe9..978bbebe30 100644 --- a/libavcodec/av1_parser.c +++ b/libavcodec/av1_parser.c @@ -21,6 +21,8 @@ */ #include "libavutil/avassert.h" + +#include "av1_parse.h" #include "cbs.h" #include "cbs_av1.h" #include "parser.h" @@ -162,11 +164,8 @@ static int av1_parser_parse(AVCodecParserContext *ctx, avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics; avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; - if (seq->timing_info_present_flag) { - const AV1RawTimingInfo *timing = &seq->timing_info; - av_reduce(&avctx->framerate.den, &avctx->framerate.num, - timing->num_units_in_display_tick, timing->time_scale, INT_MAX); - } + if (seq->timing_info_present_flag) + avctx->framerate = ff_av1_framerate(&seq->timing_info); end: ff_cbs_fragment_reset(td); diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index c90c9c1a69..693673b436 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -26,6 +26,7 @@ #include "libavutil/pixdesc.h" #include "libavutil/opt.h" #include "avcodec.h" +#include "av1_parse.h" #include "av1dec.h" #include "atsc_a53.h" #include "bytestream.h" @@ -709,15 +710,8 @@ static int set_context_with_sequence(AVCodecContext *avctx, } avctx->sample_aspect_ratio = (AVRational) { 1, 1 }; - if (seq->timing_info.num_units_in_display_tick && - seq->timing_info.time_scale) { - av_reduce(&avctx->framerate.den, &avctx->framerate.num, - seq->timing_info.num_units_in_display_tick, - seq->timing_info.time_scale, - INT_MAX); - if (seq->timing_info.equal_picture_interval) - avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1; - } + if (seq->timing_info_present_flag) + avctx->framerate = ff_av1_framerate(&seq->timing_info); return 0; } From patchwork Sun May 7 13:32:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41515 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707122pzb; Sun, 7 May 2023 06:33:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5sa12gv9+glKnIWeBIXzSrEYIWxdbkMBd80S/KvuEJLNl2Iltv+PokSc9giDouhH1iO8by X-Received: by 2002:a17:907:6289:b0:961:8d21:a480 with SMTP id nd9-20020a170907628900b009618d21a480mr6051305ejc.58.1683466407244; Sun, 07 May 2023 06:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466407; cv=none; d=google.com; s=arc-20160816; b=k11M6BtICghlrEN28lsOdpVKz3xhtrXuI5U5MjuYrnQGQ2MOyTebOUTa56ND2EfHB7 mCpEDTqeRl51eqeGfXkW+9YrMeb+fxuAQ7A7Bm+odyO4DorSMko2tqlr1wFsRmsbztY9 7i/fsn9Tmy8qjULUAc6IU4XuFqntE060N7Sd2qlHdVrs0Lobg/fTkKrrrMNgMGFkhruP mrpmCiXHs5Km2zItDBwy+Jp9HJfc5kyixfXvP6aABqpPZzyzPgpsE+ErHN3Vks8miuKR V7v6W6izXxD35mZJFyr73cIMtwJz8vAdfk3vnYkKHPWD5NCgOOmQJIJ0e5mbETWDJYTL i93w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=oLBLHm0+oplAEkKHfcJjxyPOtsf2wnrE4qrUvy8ow9I=; b=QdHcHfnSPNaOvQD2hRFQ6YoNFT22Wk0PFTwM447WdlVaQSAUOgIxA8dPL3L5DfS7oG HqSf3E+Mv/nZlL18CfZUrMbp5qG/x+hJVdB03+eVR+AwsLWdZmCzCG2P4EPO2ZOGIKJw lLufIao9iyU8VJudfZzjsNKAVmrGeDhTZwb9xFqVy5cD4SYTaXNLq7j9tpM1sjYI+IdF WDZu5nLmIRCh8deAYs1SbQaSj/+S2ceCQR07T6LL+ivI4ErVPCTKomYb7CdMv84UdzQd 5I1j1omEOr3WTcVCNbylBwMmbY8SXHFuzXQ3WTKOH0U97hMWGptuvt6bStH88Gjra/LU rECA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hc36-20020a17090716a400b0096646da8955si954749ejc.760.2023.05.07.06.33.26; Sun, 07 May 2023 06:33:27 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5C12B68C06B; Sun, 7 May 2023 16:33:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6687868BFF3 for ; Sun, 7 May 2023 16:33:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B85922406CC for ; Sun, 7 May 2023 15:33:14 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id fF6wnKBfgN-8 for ; Sun, 7 May 2023 15:33:12 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id AC54B2404EC for ; Sun, 7 May 2023 15:33:12 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 6C82B3A1267 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:48 +0200 Message-Id: <20230507133255.20881-6-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: fix exporting framerate 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 3YE71S0xHyH6 Same issues as in the previous commit. --- libavcodec/libdav1d.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index 87aed16749..19b6a880da 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -154,11 +154,11 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s else c->pix_fmt = pix_fmt[seq->layout][seq->hbd]; - if (seq->num_units_in_tick && seq->time_scale) { + if (seq->num_units_in_tick && seq->time_scale && + seq->num_ticks_per_picture < INT_MAX / seq->num_units_in_tick) { av_reduce(&c->framerate.den, &c->framerate.num, - seq->num_units_in_tick, seq->time_scale, INT_MAX); - if (seq->equal_picture_interval) - c->ticks_per_frame = seq->num_ticks_per_picture; + seq->num_units_in_tick * FFMAX(seq->num_ticks_per_picture, 1), + seq->time_scale, INT_MAX); } if (seq->film_grain_present) From patchwork Sun May 7 13:32:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41516 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707217pzb; Sun, 7 May 2023 06:33:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ze5dO7xI/2VqljDULjIOz3paVrU9XMMG+AST2m40wQz17l7GFewTW7y4byHkqTnx4qj7X X-Received: by 2002:a17:907:868b:b0:961:57fb:10c1 with SMTP id qa11-20020a170907868b00b0096157fb10c1mr6344408ejc.63.1683466418278; Sun, 07 May 2023 06:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466418; cv=none; d=google.com; s=arc-20160816; b=u5miDaCk8FXirO7vKpj5MqwrHHbXyA1zD+qh4fN8M+5pZg85BzMXteMWn7sfp7XVac 5/p7dpT2iEUAlokbnnJs95kJ3UPLbPAPHdAtrjw7yamgrspfQoLAXxWHka/0y4c2tjAO ygim3KGYqcUkNB9c2vCdNofs6w0ECNy0fBMq8KRWolNNG4mTj7tTQj7TVucQbxVG/sLq Cd5UHpzRV4ImUCZ0Lm65Vb/lhkykD5xZxLVSnQmVCLr/OM3nhtlzzkEO6OHVwJmjpI0V XlrCGeenqHJcUVjLcRHm/+vfmX/mOuN/gUUWXFOkY2ATTZjtysEC80heYV27Bd8GMb8Z +i1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=HNy2P7t4Mo+JgnOGMZx7rt2wpJ2HZ35+jQ2dXbhVf1k=; b=wH7bPfwLutQTZ7AN1wWYrB5WCfUYhV7eEHiq8JVQbN+WNszr8U287AsBTDogRdXWAR aIdeRQP5QJlRgY0RN1rAB/9dL3rkHzQba6hzjcdGp6WClUB2QxCrAT5C8nZUJnZ0vZN9 ilv1YEOZXkc7u2d3twe5R2cehCAokbmVKr9eofTKtsQlGhehQsx/znA4P019FGstTZj+ hNxaPu35yc+W0UGXYTqCTvhrCouJcoBqqbaXJnFHXBbkDZYnPc9Ny7q/zSkpU1ZvT0ga iJjV4d9Y6RvbRC0OnlG/23A8PYmQnI1v/2DvQPw/oZgv3wz8xTG3tLYAXvP6ruHMY6EW B04w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qk16-20020a170906d9d000b00965604f0e3asi4406355ejb.808.2023.05.07.06.33.37; Sun, 07 May 2023 06:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 78D7868C0FB; Sun, 7 May 2023 16:33:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E33EA68BFF3 for ; Sun, 7 May 2023 16:33:15 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A8CD72406CE for ; Sun, 7 May 2023 15:33:15 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id DyJMJa-tXT57 for ; Sun, 7 May 2023 15:33:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 11C3A2404F5 for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 7740A3A1506 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:49 +0200 Message-Id: <20230507133255.20881-7-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/13] lavc/ratecontrol: use AVCodecContext.framerate when available 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: /GQ+2ygFaUyU --- libavcodec/ratecontrol.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 6a40f9cbdc..890ae33cb3 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -57,6 +57,9 @@ void ff_write_pass1_stats(MpegEncContext *s) static double get_fps(AVCodecContext *avctx) { + if (avctx->framerate.num > 0 && avctx->framerate.den > 0) + return av_q2d(avctx->framerate); + return 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1); } From patchwork Sun May 7 13:32:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41521 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707635pzb; Sun, 7 May 2023 06:34:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4abzOosdRR6HoGta5myo0N9Kd3jdWwXoUsdRblhgBUAfcM8rLCHuycYpqK39hWECqAxOHy X-Received: by 2002:aa7:cd53:0:b0:50b:c49b:62d4 with SMTP id v19-20020aa7cd53000000b0050bc49b62d4mr5391896edw.28.1683466462864; Sun, 07 May 2023 06:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466462; cv=none; d=google.com; s=arc-20160816; b=f0AN1Tr8wuAw4GDsUEFuVPHBuI5BbWCwIAVE/0qIlNKZgBT1jTOcuGbARftHhHnflG NsRDYU2ukzYhZ/qNOkOebnwuAL1ebfW4rwFqTvYvTVIGRizgV79DvcSdRKXPDBsDAv9C 00DdmBRWqGl3anf4VM2g3DP3AGHr4B8btR3fmQn0huOcJMqh5+Yfbevhs1c3nDfPukU3 U7hjhSiuFYqZURgrQhTucpCC0Ug6HybOkQTRr99MVnVCgwlU2RYQ7U3uu9MkWlWXGxIL OqYL2DU4veE6ozAJYi/SeEWZvHV9ZCuP/VZJ9rWbQVZT4eiaItkjFCkqqi8YKw6R2tPY Pu5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=xc2hgEU7Mwlq2xb+u4Y0lS40dp3/i5UXxRpu7y8MtnI=; b=HaWwfS0ZZCxOwuVJDcToKEJtkyt9GnYNo9NGyrgxb6YR8vvTSM6sgzYwJfyhroo3e8 p0Gr/emp1y6iH5K8AsCwVnBpRyczWMthnzvQy1PbFFcVR5+fHlOrlOUOVaWQafpl2Ot3 T0kyWSBzLJiQAQvDn62+xvCMXbkYHvGqJkploUop8RJEf96ptM6JdCTflqH+oO/crnhx 1MH7Pc7cuxBUmIUshN7CdBv1s3BGdHzKE/btLNKiY9CYIKIKwE7d/weZf/Sd4c7A2q2L LhqPzGazwMjRIbhv0lGo5UJ2d9tTbRqqsj3tINstZcd3CTVN/jprotW4HSk6ktbGlrAv Uw/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c16-20020aa7c990000000b0050ce388a8aesi3606514edt.50.2023.05.07.06.34.22; Sun, 07 May 2023 06:34:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9488D68C108; Sun, 7 May 2023 16:33:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B3F5F68C11D for ; Sun, 7 May 2023 16:33:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3AAD8240591 for ; Sun, 7 May 2023 15:33:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id pB-mItfKZ7gu for ; Sun, 7 May 2023 15:33:15 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 0F7002404EE for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 824E13A154F for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:50 +0200 Message-Id: <20230507133255.20881-8-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/13] lavc/msmpeg4enc: use AVCodecContext.framerate when available 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NdkHsDmIBpz1 --- libavcodec/msmpeg4enc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c index 54121438a0..df190d376c 100644 --- a/libavcodec/msmpeg4enc.c +++ b/libavcodec/msmpeg4enc.c @@ -280,7 +280,13 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s) void ff_msmpeg4_encode_ext_header(MpegEncContext * s) { - unsigned fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1); + unsigned fps; + + if (s->avctx->framerate.num > 0 && s->avctx->framerate.den > 0) + fps = s->avctx->framerate.num / s->avctx->framerate.den; + else + fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1); + put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29 put_bits(&s->pb, 11, FFMIN(s->bit_rate / 1024, 2047)); From patchwork Sun May 7 13:32:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41518 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707369pzb; Sun, 7 May 2023 06:33:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dbIQdT3SeUoKZzfB1BOS7kGv6j5FiGYhBBW7CadJUGF/cM2FTn3+KL68D44kv5zMWz5Fn X-Received: by 2002:a05:6402:203b:b0:505:48c:3266 with SMTP id ay27-20020a056402203b00b00505048c3266mr6032122edb.20.1683466436656; Sun, 07 May 2023 06:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466436; cv=none; d=google.com; s=arc-20160816; b=M73UcxmrgEF1MUE+Bkj4gfuA40CicYvBFC+aR4Uw2hCczeSgHLrEpf888N9dms16Jf YyAdb4KauC/9mzsBbWDGsawPiVHXg8kRtw8l38Jo3nJBOxGzsE5FtqozU2xKADdLXCG/ mJ2LDeUauZTAqRXPtkIbJHUf2KK2GdaZwuKQH6rTVuNoLYTWO8VX/BOqLW/APAM6FaeQ YpAPMTRJyBRZhQUre3vKUe5EdjUVaYtkRBDtTnst0OanykBOU4YlOxb8GSfh6NnX+Fhw CBgiudWxWL/7uL7sUKjKqf/ryiJLoHMzLugLCKC8Lv4H4RqEV4UPhKpvDgLkdcWE/61v ueSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=0pDQY/qVDGh22eagrD5P2icerQBTrrtu9CIpk9s9B+U=; b=Q0vrwQ1MMCkWDGtmO0Mpl33SXJ79zYo/cpwIjuCBmQaMP/moykmIk1u9bYeqePEeCZ 2Jl3I63T7Y9W63s4gInOHdsB+23KuFmCeCDTBhzvXhyE1hWxL+xFaCtTl9zkUHkSOSjd oIHbvwo+C59cEQ5EOILAJasKGa5nENRwAA2vwjHINQFTXjYseEKvM38a9P2+X23AQWtR i1meaFOjTmGWd6GuxPGBkRCMPe792ck2amWW7F7VqWFJpFILRf0rkKc506s+puBLjPpE yN85bh8bmtV5HLaIWpXRwRvg4p9AQocIptHn16SIDFpuv2BhCDYjPm2JgdqU9KlAtMpT Vsig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f20-20020a056402005400b0050489449e77si8040154edu.569.2023.05.07.06.33.56; Sun, 07 May 2023 06:33:56 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9933D68C11C; Sun, 7 May 2023 16:33:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 014AB68C06B for ; Sun, 7 May 2023 16:33:16 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B8F47240177 for ; Sun, 7 May 2023 15:33:16 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id VTVqbzdYzRdc for ; Sun, 7 May 2023 15:33:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 140A92404F8 for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8EEC83A1571 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:51 +0200 Message-Id: <20230507133255.20881-9-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/13] libaomenc: use AVCodecContext.framerate when available 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: K/SmDEkxvG/N --- libavcodec/libaomenc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index 0b88102c77..1d3a4ae64c 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -1295,8 +1295,12 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, if (frame->duration > ULONG_MAX) { av_log(avctx, AV_LOG_WARNING, "Frame duration too large: %"PRId64"\n", frame->duration); - } else - duration = frame->duration ? frame->duration : avctx->ticks_per_frame; + } else if (frame->duration) + duration = frame->duration; + else if (avctx->framerate.num > 0 && avctx->framerate.den > 0) + duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base); + else + duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1; switch (frame->color_range) { case AVCOL_RANGE_MPEG: From patchwork Sun May 7 13:32:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41519 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707455pzb; Sun, 7 May 2023 06:34:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4WDbSTG3SO2JfBX/iWjpLdHmweWwHtFbb2glxU9gJh0jjPCRfvGfHdsCYHiRN5loWeBXqu X-Received: by 2002:a05:6402:185a:b0:50d:82f9:6867 with SMTP id v26-20020a056402185a00b0050d82f96867mr5371453edy.31.1683466445834; Sun, 07 May 2023 06:34:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466445; cv=none; d=google.com; s=arc-20160816; b=mUF0VggNmJHxmKZeEypvUOAWVs5eTJ6oQkBMZlljib7Za5hTSH4+n/2QHQdc3dToFs mM4pH6zOXurKpxfhOwPO1PogThPv+K3FgP6oqGY3kxj4xJgvtyA6cMR4bqhJ1d1RkQ/g viu6DeFWcqXlFDTP/XpWzWD1InR4jtJTaCtp7seg5RoBIqmiY8kh0PgKc6ytGxV6okPl O45jBi0jeV/zqns1cSIkUAAwO7+1m+0J6kidZRycP5zGnZ/I1klOvbyVA0vw/tZP1Kz6 2YkZ5fnMcWmibe5S7iEP0PjHuYYzAnDJQEBgiZnjtK9oxKYUwTEv5srgDDZJ+0WvjAGE tAfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=c5/OEbruFf5nGzfyoqGEfM8LwOKyyQlL4mHMdqMDS/Q=; b=Q7kkyDff8gPxRMG5Tfv298Xd45ju9/3tv1RkFkRT6LK7LvI4QSOfZrYxpEJJe5X0/N dORncdY3PwF7GndXUAg6xeTQe+GjCqZxFrPWV0pkC7f3K8S+Ew3XWzZBNXX6KIzRE9al i2NgJTfnfR7uXO2V5IgYT94ZzxTN+wIVaMr5RlIZ5v9V3rrwXgULI/k2SVCekiShvjZh ddMIDuy50y8uulDSMuQB7uJyX/8rFzcut4gHyUTXIYAnEzLNYm7dJab40ZQS48RE05lp ABHMp7BM0PQxLwWw4ZfoRCyeJsu4tZceqoqEqHkRqgJnwzf3L5T0IDCjv1oOFVZINeNi SPbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id y24-20020aa7c258000000b0050bc5550f4esi8225999edo.231.2023.05.07.06.34.05; Sun, 07 May 2023 06:34:05 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A24DA68C140; Sun, 7 May 2023 16:33:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9DC0C68C0FC for ; Sun, 7 May 2023 16:33:17 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5B5E32404F8 for ; Sun, 7 May 2023 15:33:17 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Fpu2lDyzMFD6 for ; Sun, 7 May 2023 15:33:16 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 295EC240591 for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 9A8033A1594 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:52 +0200 Message-Id: <20230507133255.20881-10-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/13] lavc/libkvazaar, libopenh264enc: drop redundant checks 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: s/kegwpJ6+Dg The same check is present in encode_preinit_video(). --- libavcodec/libkvazaar.c | 5 ----- libavcodec/libopenh264enc.c | 5 ----- 2 files changed, 10 deletions(-) diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c index 168486f4ec..b3faa0a64b 100644 --- a/libavcodec/libkvazaar.c +++ b/libavcodec/libkvazaar.c @@ -85,11 +85,6 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx) cfg->framerate_num = avctx->framerate.num; cfg->framerate_denom = avctx->framerate.den; } else { - if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) { - av_log(avctx, AV_LOG_ERROR, - "Could not set framerate for kvazaar: integer overflow\n"); - return AVERROR(EINVAL); - } cfg->framerate_num = avctx->time_base.den; cfg->framerate_denom = avctx->time_base.num * avctx->ticks_per_frame; } diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c index 3c605fe8ea..15c3822824 100644 --- a/libavcodec/libopenh264enc.c +++ b/libavcodec/libopenh264enc.c @@ -139,11 +139,6 @@ static av_cold int svc_encode_init(AVCodecContext *avctx) if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { param.fMaxFrameRate = av_q2d(avctx->framerate); } else { - if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) { - av_log(avctx, AV_LOG_ERROR, - "Could not set framerate for libopenh264enc: integer overflow\n"); - return AVERROR(EINVAL); - } param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1); } param.iPicWidth = avctx->width; From patchwork Sun May 7 13:32:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41523 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707775pzb; Sun, 7 May 2023 06:34:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PLEZfIE4TeSa1+yL+tFH9VVr/plnblpsWK0TyBxKmKG/o3HDZzPVpL9X5JCaYnMzRZSvW X-Received: by 2002:a17:907:6eaa:b0:94f:81c:725e with SMTP id sh42-20020a1709076eaa00b0094f081c725emr7479741ejc.59.1683466479490; Sun, 07 May 2023 06:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466479; cv=none; d=google.com; s=arc-20160816; b=s60v/aO/EicK7ZI+BC9PKpoNp7bD3fzzOHuDLLWK/mCPIf+ah+kPkNqYKNw4EIaCvb kn91PN6pDLlD2J06VrxjFCCypqq6gAE8MHg9TNLLuZiUM6HANanQ79HaRhlfjlumv419 M8DqMTxOorLT9iQFAVPM5QSy1Hy+aLwEgJ3k2oFx3olRmZcDqZAdlcTB+TUz7E+ueoyz tgM71ZQSUT2fLNXGq7xMW0Ocv0RIHMQvaNIgskmWjNZbwhTkNb0AFe78oNy4BOj+JMaa 9IuEyFUROymtPXutWnSnBWyPDbKjCtMLqMgyvAmTmrN0+BsA3Q0CBGZ5T/oY5bbgSB3A B16Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=1K3yV+p2VYBZRUiPv+PkqG+0U1xzDmxXH7Spxs4mlOA=; b=qIT5T2M3kk8IxYZ/t2HUR9WjhWMGOQoXV5hOHK7bYxlroUS4m4LPcGaYNeTzq8G4UF g4dpsgj9bwUqAp3+92UMXsVX3ejsy13Hws/x79VbJg8z6RmK60rqb2dy4lAiOHcoS0Q8 TO3I6oj6qKrh0b0ebJmHOvs3Zj7zJKg1Z2qdPXphUOawpvPSt6CiPOqKN8oHxJMhRrsn sTa5cHsxxhOxWo7zXEglEGaQdLPsnjmBvDqH3vdBVVgH/1ai8wBh41CF3rw4xNwdnhNo xKSltaTh+pTOhwiaroKo2s5nHAcFAmgP2Tq9hB8iyGVqNP2iIx4zr0II/b5mMnceFVuL oNDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id oy4-20020a170907104400b0094f1eee5a9dsi4453703ejb.555.2023.05.07.06.34.39; Sun, 07 May 2023 06:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7FEEB68C17B; Sun, 7 May 2023 16:33:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C82568C12A for ; Sun, 7 May 2023 16:33:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 780602405B5 for ; Sun, 7 May 2023 15:33:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id KoEeQzcZr00h for ; Sun, 7 May 2023 15:33:18 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 5CB552405F9 for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A66E73A163A for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:53 +0200 Message-Id: <20230507133255.20881-11-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OMdSabMBdF8+ Adapt similar code from libaomenc - stop using ticks_per_frame except as a last resort. --- libavcodec/libvpxenc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index a20e949842..a89497665b 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1692,6 +1692,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc; vpx_svc_layer_id_t layer_id; int layer_id_valid = 0; + unsigned long duration; if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) { struct vpx_codec_enc_cfg cfg = *enccfg; @@ -1820,8 +1821,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, #endif } + if (frame && frame->duration > ULONG_MAX) { + av_log(avctx, AV_LOG_WARNING, + "Frame duration too large: %"PRId64"\n", frame->duration); + } else if (frame && frame->duration) + duration = frame->duration; + else if (avctx->framerate.num > 0 && avctx->framerate.den > 0) + duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base); + else + duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1; + res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp, - avctx->ticks_per_frame, flags, ctx->deadline); + duration, flags, ctx->deadline); if (res != VPX_CODEC_OK) { log_encoder_error(avctx, "Error encoding frame"); return AVERROR_INVALIDDATA; @@ -1829,7 +1840,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, if (ctx->is_alpha) { res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp, - avctx->ticks_per_frame, flags, ctx->deadline); + duration, flags, ctx->deadline); if (res != VPX_CODEC_OK) { log_encoder_error(avctx, "Error encoding alpha frame"); return AVERROR_INVALIDDATA; From patchwork Sun May 7 13:32:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41524 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707891pzb; Sun, 7 May 2023 06:34:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Ps+uujGZ0ZmZhV7shja8N9eTpXT+2v5dJHib9N9NJu4XVXxDplHl1xaIM48pdSFxP8nch X-Received: by 2002:aa7:c44e:0:b0:50b:d819:4fd2 with SMTP id n14-20020aa7c44e000000b0050bd8194fd2mr5409898edr.17.1683466491894; Sun, 07 May 2023 06:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466491; cv=none; d=google.com; s=arc-20160816; b=KwB2borf/fUBV3ATXO2TuSQdGKIKSlWWlimJM870bB4p/iB4uZUsyqASOyxQi3GEfu NFl8Kiw3WlN0Lyh2bR31glF6q9WFHbMEqZScYjc1dVVa3xOWF+ntLBT2BFVHg3h5xBYd 61a7tZi5Qa2zG931L3aC29axYZd9I///V8VaprCZhRPijM4ZYMsmkM6xY2VnayzpGQSU PhXVvS37OQXB+VZ58gC6ig44krzhpctvNmcXjhkvlfenN172I4YIuI/USjN2/miJf7c0 dWNcYSo3y0vF3Z7sDryXVP9/sCqslKtOjg1nTOEWRL6pC6XM5fr7c7AH68Dun9kTwGBT d7vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=g4KpQ+YqfMJSuems+8P3UGQgXwytuDWVrd7M1Vtngwc=; b=yALmKnJiLmJLe58aJr44IOq9LFIXIDj3g2GxGe7kXWizpXFfqQYzhM8nyANXOeixVj jOs+jS3UXreXF1UVG8iSF9PSi9Q4dKGjA4s1+p2Z/F6P+9pV8TZvlHkLWnrgX30rZnRE 0HNoYJdcIfcYNaXWY3Mgn0ix82sfgTR4xk1C1zz6hhUALDUacpNWyejwK0yE/tl8lpka JQWGiYcwOujtZyIXetjXiWbNbDuO4NSrZVGy4xxazzPaVtI9Qkqf94ONNvJT/azP9ctj qFDnmB9EWLpqZfHW/MuOGxXoWQdnp6kpycFvRHcX9tn00KW4M9He59t8oH7YHbDPQCYF 690w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r16-20020a056402035000b0050bc89f5fe3si7634383edw.59.2023.05.07.06.34.47; Sun, 07 May 2023 06:34:51 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8258468C189; Sun, 7 May 2023 16:33:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 33D2968C130 for ; Sun, 7 May 2023 16:33:21 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BBDBF2405F9 for ; Sun, 7 May 2023 15:33:19 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id atdL_nL7ha-5 for ; Sun, 7 May 2023 15:33:17 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 371B92405EC for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B24BF3A168E for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:54 +0200 Message-Id: <20230507133255.20881-12-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/13] lavc: deprecate AVCodecContext.ticks_per_frame 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rE/29lDs3Vng For encoding, this field is entirely redundant with AVCodecContext.framerate. For decoding, this field is entirely redundant with AV_CODEC_PROP_FIELDS. --- doc/codecs.texi | 1 - libavcodec/amfenc_av1.c | 8 +++++++- libavcodec/amfenc_h264.c | 8 +++++++- libavcodec/amfenc_hevc.c | 8 +++++++- libavcodec/avcodec.h | 8 ++++++++ libavcodec/encode.c | 4 ++++ libavcodec/h264_slice.c | 2 +- libavcodec/h264dec.c | 4 ++++ libavcodec/libaomenc.c | 8 +++++++- libavcodec/libkvazaar.c | 8 +++++++- libavcodec/libopenh264enc.c | 8 +++++++- libavcodec/librav1e.c | 9 +++++++-- libavcodec/libsvtav1.c | 8 +++++++- libavcodec/libvpxenc.c | 8 +++++++- libavcodec/libx264.c | 8 +++++++- libavcodec/libx265.c | 8 +++++++- libavcodec/mfenc.c | 4 ++++ libavcodec/mpeg12dec.c | 8 ++++++++ libavcodec/mpegvideo_parser.c | 8 ++++++++ libavcodec/msmpeg4enc.c | 8 +++++++- libavcodec/nvenc.c | 16 ++++++++++++++-- libavcodec/options_table.h | 2 ++ libavcodec/pthread_frame.c | 4 ++++ libavcodec/ratecontrol.c | 8 +++++++- libavcodec/vc1.c | 11 ++++++++--- libavcodec/vc1_parser.c | 3 +-- libavcodec/vc1dec.c | 1 - libavcodec/version_major.h | 1 + libavformat/avformat.c | 15 +++++++++++++-- 29 files changed, 171 insertions(+), 26 deletions(-) diff --git a/doc/codecs.texi b/doc/codecs.texi index 1adacd2b59..f903dad754 100644 --- a/doc/codecs.texi +++ b/doc/codecs.texi @@ -775,7 +775,6 @@ Possible values: @end table @item rc_max_vbv_use @var{float} (@emph{encoding,video}) @item rc_min_vbv_use @var{float} (@emph{encoding,video}) -@item ticks_per_frame @var{integer} (@emph{decoding/encoding,audio,video}) @item color_primaries @var{integer} (@emph{decoding/encoding,video}) Possible values: diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c index 8093cb7357..ad09b7910a 100644 --- a/libavcodec/amfenc_av1.c +++ b/libavcodec/amfenc_av1.c @@ -117,7 +117,13 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); } else { - framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num * avctx->ticks_per_frame); +FF_DISABLE_DEPRECATION_WARNINGS + framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ); +FF_ENABLE_DEPRECATION_WARNINGS } if ((ret = ff_amf_encode_init(avctx)) < 0) diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c index eaf7f974f3..d2fc33971b 100644 --- a/libavcodec/amfenc_h264.c +++ b/libavcodec/amfenc_h264.c @@ -142,7 +142,13 @@ static av_cold int amf_encode_init_h264(AVCodecContext *avctx) if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); } else { - framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num * avctx->ticks_per_frame); +FF_DISABLE_DEPRECATION_WARNINGS + framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ); +FF_ENABLE_DEPRECATION_WARNINGS } if ((ret = ff_amf_encode_init(avctx)) != 0) diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c index 9b46946f1e..674a4095d6 100644 --- a/libavcodec/amfenc_hevc.c +++ b/libavcodec/amfenc_hevc.c @@ -109,7 +109,13 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx) if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); } else { - framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num * avctx->ticks_per_frame); +FF_DISABLE_DEPRECATION_WARNINGS + framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ); +FF_ENABLE_DEPRECATION_WARNINGS } if ((ret = ff_amf_encode_init(avctx)) < 0) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 1e91b9cb53..06b1a120ab 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -556,14 +556,22 @@ typedef struct AVCodecContext { */ AVRational time_base; +#if FF_API_TICKS_PER_FRAME /** * For some codecs, the time base is closer to the field rate than the frame rate. * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration * if no telecine is used ... * * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2. + * + * @deprecated + * - decoding: Use AVCodecDescriptor.props & AV_CODEC_PROP_FIELDS + * - encoding: Set AVCodecContext.framerate instead + * */ + attribute_deprecated int ticks_per_frame; +#endif /** * Codec delay. diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 14e2876742..ab5f889615 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -582,6 +582,8 @@ static int encode_preinit_video(AVCodecContext *avctx) return AVERROR(EINVAL); } +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS if (avctx->ticks_per_frame && avctx->time_base.num && avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) { av_log(avctx, AV_LOG_ERROR, @@ -591,6 +593,8 @@ static int encode_preinit_video(AVCodecContext *avctx) avctx->time_base.den); return AVERROR(EINVAL); } +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (avctx->hw_frames_ctx) { AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 8526782560..be7a8e0b5a 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -957,7 +957,7 @@ static int h264_slice_header_init(H264Context *h) if (h->x264_build < 44U) den *= 2; av_reduce(&h->avctx->framerate.den, &h->avctx->framerate.num, - sps->num_units_in_tick * h->avctx->ticks_per_frame, den, 1 << 30); + sps->num_units_in_tick * 2, den, 1 << 30); } ff_h264_free_tables(h); diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index cdd4b98c83..521b1e2235 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -382,7 +382,11 @@ static av_cold int h264_decode_init(AVCodecContext *avctx) return AVERROR_UNKNOWN; } +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS avctx->ticks_per_frame = 2; +FF_ENABLE_DEPRECATION_WARNINGS +#endif if (!avctx->internal->is_copy) { if (avctx->extradata_size > 0 && avctx->extradata) { diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index 1d3a4ae64c..16747e7e92 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -1300,7 +1300,13 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt, else if (avctx->framerate.num > 0 && avctx->framerate.den > 0) duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base); else - duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1; +FF_DISABLE_DEPRECATION_WARNINGS + duration = +#if FF_API_TICKS_PER_FRAME + avctx->ticks_per_frame ? avctx->ticks_per_frame : +#endif + 1; +FF_ENABLE_DEPRECATION_WARNINGS switch (frame->color_range) { case AVCOL_RANGE_MPEG: diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c index b3faa0a64b..2ef34dd82e 100644 --- a/libavcodec/libkvazaar.c +++ b/libavcodec/libkvazaar.c @@ -86,7 +86,13 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx) cfg->framerate_denom = avctx->framerate.den; } else { cfg->framerate_num = avctx->time_base.den; - cfg->framerate_denom = avctx->time_base.num * avctx->ticks_per_frame; +FF_DISABLE_DEPRECATION_WARNINGS + cfg->framerate_denom = avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } cfg->target_bitrate = avctx->bit_rate; cfg->vui.sar_width = avctx->sample_aspect_ratio.num; diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c index 15c3822824..5b59af6f94 100644 --- a/libavcodec/libopenh264enc.c +++ b/libavcodec/libopenh264enc.c @@ -139,7 +139,13 @@ static av_cold int svc_encode_init(AVCodecContext *avctx) if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { param.fMaxFrameRate = av_q2d(avctx->framerate); } else { - param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1); +FF_DISABLE_DEPRECATION_WARNINGS + param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) +#if FF_API_TICKS_PER_FRAME + / FFMAX(avctx->ticks_per_frame, 1) +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } param.iPicWidth = avctx->width; param.iPicHeight = avctx->height; diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c index 08affabe3e..56539435a7 100644 --- a/libavcodec/librav1e.c +++ b/libavcodec/librav1e.c @@ -219,10 +219,15 @@ static av_cold int librav1e_encode_init(AVCodecContext *avctx) avctx->framerate.den, avctx->framerate.num }); } else { +FF_DISABLE_DEPRECATION_WARNINGS rav1e_config_set_time_base(cfg, (RaRational) { - avctx->time_base.num * avctx->ticks_per_frame, - avctx->time_base.den + avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + , avctx->time_base.den }); +FF_ENABLE_DEPRECATION_WARNINGS } if ((avctx->flags & AV_CODEC_FLAG_PASS1 || avctx->flags & AV_CODEC_FLAG_PASS2) && !avctx->bit_rate) { diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c index 9174e2753c..8354793a34 100644 --- a/libavcodec/libsvtav1.c +++ b/libavcodec/libsvtav1.c @@ -250,7 +250,13 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param, param->frame_rate_denominator = avctx->framerate.den; } else { param->frame_rate_numerator = avctx->time_base.den; - param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame; +FF_DISABLE_DEPRECATION_WARNINGS + param->frame_rate_denominator = avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } /* 2 = IDR, closed GOP, 1 = CRA, open GOP */ diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index a89497665b..868b55b756 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1829,7 +1829,13 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, else if (avctx->framerate.num > 0 && avctx->framerate.den > 0) duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base); else - duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1; +FF_DISABLE_DEPRECATION_WARNINGS + duration = +#if FF_API_TICKS_PER_FRAME + avctx->ticks_per_frame ? avctx->ticks_per_frame : +#endif + 1; +FF_ENABLE_DEPRECATION_WARNINGS res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp, duration, flags, ctx->deadline); diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 3aea29e995..5736f1efa7 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -1018,7 +1018,13 @@ static av_cold int X264_init(AVCodecContext *avctx) x4->params.i_fps_den = avctx->framerate.den; } else { x4->params.i_fps_num = avctx->time_base.den; - x4->params.i_fps_den = avctx->time_base.num * avctx->ticks_per_frame; +FF_DISABLE_DEPRECATION_WARNINGS + x4->params.i_fps_den = avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } x4->params.analyse.b_psnr = avctx->flags & AV_CODEC_FLAG_PSNR; diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 420d0953af..873b3021ee 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -220,7 +220,13 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) ctx->params->fpsDenom = avctx->framerate.den; } else { ctx->params->fpsNum = avctx->time_base.den; - ctx->params->fpsDenom = avctx->time_base.num * avctx->ticks_per_frame; +FF_DISABLE_DEPRECATION_WARNINGS + ctx->params->fpsDenom = avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } ctx->params->sourceWidth = avctx->width; ctx->params->sourceHeight = avctx->height; diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c index f3415df10b..8d950a3109 100644 --- a/libavcodec/mfenc.c +++ b/libavcodec/mfenc.c @@ -659,7 +659,11 @@ static int mf_encv_output_adjust(AVCodecContext *avctx, IMFMediaType *type) framerate = avctx->framerate; } else { framerate = av_inv_q(avctx->time_base); +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS framerate.den *= avctx->ticks_per_frame; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } ff_MFSetAttributeRatio((IMFAttributes *)type, &MF_MT_FRAME_RATE, framerate.num, framerate.den); diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index ebde68a4dd..27c862ffb2 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1265,7 +1265,11 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) { // MPEG-1 fps avctx->framerate = ff_mpeg12_frame_rate_tab[s1->frame_rate_index]; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS avctx->ticks_per_frame = 1; +FF_ENABLE_DEPRECATION_WARNINGS +#endif avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; } else { // MPEG-2 @@ -1275,7 +1279,11 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) ff_mpeg12_frame_rate_tab[s1->frame_rate_index].num * s1->frame_rate_ext.num, ff_mpeg12_frame_rate_tab[s1->frame_rate_index].den * s1->frame_rate_ext.den, 1 << 30); +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS avctx->ticks_per_frame = 2; +FF_ENABLE_DEPRECATION_WARNINGS +#endif switch (s->chroma_format) { case 1: avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; break; diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c index 08e5316960..1204789c67 100644 --- a/libavcodec/mpegvideo_parser.c +++ b/libavcodec/mpegvideo_parser.c @@ -145,7 +145,11 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, pc->frame_rate = avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_index]; bit_rate = (buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6); avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS avctx->ticks_per_frame = 1; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } break; case EXT_START_CODE: @@ -177,7 +181,11 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s, avctx->framerate.num = pc->frame_rate.num * (frame_rate_ext_n + 1); avctx->framerate.den = pc->frame_rate.den * (frame_rate_ext_d + 1); avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS avctx->ticks_per_frame = 2; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } break; case 0x8: /* picture coding extension */ diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c index df190d376c..9828901bea 100644 --- a/libavcodec/msmpeg4enc.c +++ b/libavcodec/msmpeg4enc.c @@ -285,7 +285,13 @@ void ff_msmpeg4_encode_ext_header(MpegEncContext * s) if (s->avctx->framerate.num > 0 && s->avctx->framerate.den > 0) fps = s->avctx->framerate.num / s->avctx->framerate.den; else - fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1); +FF_DISABLE_DEPRECATION_WARNINGS + fps = s->avctx->time_base.den / s->avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + / FFMAX(s->avctx->ticks_per_frame, 1) +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29 diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index b2f6253a43..c1798ce564 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1571,7 +1571,13 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) ctx->init_encode_params.frameRateDen = avctx->framerate.den; } else { ctx->init_encode_params.frameRateNum = avctx->time_base.den; - ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame; +FF_DISABLE_DEPRECATION_WARNINGS + ctx->init_encode_params.frameRateDen = avctx->time_base.num +#if FF_API_TICKS_PER_FRAME + * avctx->ticks_per_frame +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } ctx->init_encode_params.enableEncodeAsync = 0; @@ -2266,8 +2272,14 @@ static int nvenc_set_timestamp(AVCodecContext *avctx, dts = reorder_queue_dequeue(ctx->reorder_queue, avctx, pkt); if (avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) { +FF_DISABLE_DEPRECATION_WARNINGS pkt->dts = dts - - FFMAX(ctx->encode_config.frameIntervalP - 1, 0) * FFMAX(avctx->ticks_per_frame, 1) * FFMAX(avctx->time_base.num, 1); + FFMAX(ctx->encode_config.frameIntervalP - 1, 0) +#if FF_API_TICKS_PER_FRAME + * FFMAX(avctx->ticks_per_frame, 1) +#endif + * FFMAX(avctx->time_base.num, 1); +FF_ENABLE_DEPRECATION_WARNINGS } else { pkt->dts = pkt->pts; } diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 4f5918c7f6..03059cc39c 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -276,7 +276,9 @@ static const AVOption avcodec_options[] = { #endif {"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0.0, FLT_MAX, V|E}, {"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), AV_OPT_TYPE_FLOAT, {.dbl = 3 }, 0.0, FLT_MAX, V|E}, +#if FF_API_TICKS_PER_FRAME {"ticks_per_frame", NULL, OFFSET(ticks_per_frame), AV_OPT_TYPE_INT, {.i64 = 1 }, 1, INT_MAX, A|V|E|D}, +#endif {"color_primaries", "color primaries", OFFSET(color_primaries), AV_OPT_TYPE_INT, {.i64 = AVCOL_PRI_UNSPECIFIED }, 1, INT_MAX, V|E|D, "color_primaries_type"}, {"bt709", "BT.709", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_PRI_BT709 }, INT_MIN, INT_MAX, V|E|D, "color_primaries_type"}, {"unknown", "Unspecified", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_PRI_UNSPECIFIED }, INT_MIN, INT_MAX, V|E|D, "color_primaries_type"}, diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 74864e19c5..773e78ae34 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -286,7 +286,11 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src, dst->level = src->level; dst->bits_per_raw_sample = src->bits_per_raw_sample; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS dst->ticks_per_frame = src->ticks_per_frame; +FF_ENABLE_DEPRECATION_WARNINGS +#endif dst->color_primaries = src->color_primaries; dst->color_trc = src->color_trc; diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c index 890ae33cb3..649f570c9d 100644 --- a/libavcodec/ratecontrol.c +++ b/libavcodec/ratecontrol.c @@ -60,7 +60,13 @@ static double get_fps(AVCodecContext *avctx) if (avctx->framerate.num > 0 && avctx->framerate.den > 0) return av_q2d(avctx->framerate); - return 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1); +FF_DISABLE_DEPRECATION_WARNINGS + return 1.0 / av_q2d(avctx->time_base) +#if FF_API_TICKS_PER_FRAME + / FFMAX(avctx->ticks_per_frame, 1) +#endif + ; +FF_ENABLE_DEPRECATION_WARNINGS } static inline double qp2bits(RateControlEntry *rce, double qp) diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c index d4014d25ab..795c6db541 100644 --- a/libavcodec/vc1.c +++ b/libavcodec/vc1.c @@ -418,6 +418,14 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace, v->tfcntrflag, v->finterpflag); +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS + if (v->broadcast) { // Pulldown may be present + v->s.avctx->ticks_per_frame = 2; + } +FF_ENABLE_DEPRECATION_WARNINGS +#endif + v->psf = get_bits1(gb); if (v->psf) { //PsF, 6.1.13 av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n"); @@ -467,9 +475,6 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) v->s.avctx->framerate.num = ff_vc1_fps_nr[nr - 1] * 1000; } } - if (v->broadcast) { // Pulldown may be present - v->s.avctx->ticks_per_frame = 2; - } } if (get_bits1(gb)) { diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c index 4167215fb1..ec284dca00 100644 --- a/libavcodec/vc1_parser.c +++ b/libavcodec/vc1_parser.c @@ -89,11 +89,10 @@ static void vc1_extract_header(AVCodecParserContext *s, AVCodecContext *avctx, else s->pict_type = vpc->v.s.pict_type; - if (avctx->ticks_per_frame > 1){ + if (vpc->v.broadcast){ // process pulldown flags s->repeat_pict = 1; // Pulldown flags are only valid when 'broadcast' has been set. - // So ticks_per_frame will be 2 if (vpc->v.rff){ // repeat field s->repeat_pict = 2; diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 8298cefbc7..9e343d003f 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -1087,7 +1087,6 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, // process pulldown flags s->current_picture_ptr->f->repeat_pict = 0; // Pulldown flags are only valid when 'broadcast' has been set. - // So ticks_per_frame will be 2 if (v->rff) { // repeat field s->current_picture_ptr->f->repeat_pict = 1; diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h index 40db213499..546999ce76 100644 --- a/libavcodec/version_major.h +++ b/libavcodec/version_major.h @@ -46,6 +46,7 @@ #define FF_API_VT_HWACCEL_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 61) #define FF_API_AVCTX_FRAME_NUMBER (LIBAVCODEC_VERSION_MAJOR < 61) #define FF_API_SLICE_OFFSET (LIBAVCODEC_VERSION_MAJOR < 61) +#define FF_API_TICKS_PER_FRAME (LIBAVCODEC_VERSION_MAJOR < 61) // reminder to remove CrystalHD decoders on next major bump #define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index fea905693d..356b4de931 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -710,7 +710,6 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, mul)) : (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1} : ist->time_base); - enc_ctx->time_base = ist->time_base; /* * Avi is a special case here because it supports variable fps but @@ -727,7 +726,11 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, || copy_tb == AVFMT_TBCF_R_FRAMERATE) { enc_ctx->time_base.num = ist->r_frame_rate.den; enc_ctx->time_base.den = 2*ist->r_frame_rate.num; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS enc_ctx->ticks_per_frame = 2; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } else #endif if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->framerate.num && @@ -736,9 +739,13 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, || (copy_tb == AVFMT_TBCF_DECODER && (dec_ctx->framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) { enc_ctx->time_base = dec_ctx_tb; - enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; enc_ctx->time_base.den *= 2; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS + enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; enc_ctx->ticks_per_frame = 2; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS) && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) { @@ -748,7 +755,11 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, || (copy_tb == AVFMT_TBCF_DECODER && (dec_ctx->framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) { enc_ctx->time_base = dec_ctx_tb; +#if FF_API_TICKS_PER_FRAME +FF_DISABLE_DEPRECATION_WARNINGS enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; +FF_ENABLE_DEPRECATION_WARNINGS +#endif } } From patchwork Sun May 7 13:32:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41522 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp1707700pzb; Sun, 7 May 2023 06:34:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6S/HbgQP7NwvQAyYAMKWqBjGfOackL3IzeVMg0cEbzdUKLmnoV0AFaYR9OFcGqb1znJTZI X-Received: by 2002:a17:907:1c01:b0:966:335a:5b0b with SMTP id nc1-20020a1709071c0100b00966335a5b0bmr2847215ejc.18.1683466471204; Sun, 07 May 2023 06:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683466471; cv=none; d=google.com; s=arc-20160816; b=JzoFki7XRJfaXzT2zO5RAkmurC8FFxa8SN6f845x8VpzOqRXPeggslNOFyOoPhVAaD QoC22oMqA6EQWCCcqHgYvAb3hS4GAnj2tn17I36E9J/43c2SovpgmFQyF58U37ZD0Wqs 1z2XBRRfbhJNnMVav1xCsC9gm/J9Uqu0AnM4JZOc1jplpaStXu7GS//Uhv/IfYzx6ZoH weQDYBuXXDwO5RAQo3KHwJzRhm3/3yGgGrqvM1Ha6vY75gquBVY0ONixx3FnEa3ZmYwL PUWotQ4wIP6Ba03a7JZCxYKBDkI3n21lt+ziL4iGwaV2muUsmsRt1rl5KLU3vNpIUReh JZfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=whsxq3YhcJ+9N8DiKlJNHIgbHFPjTI2+a0VUAv/1yKc=; b=HEJ43f49EWOySBYpLWEPnsFTmoVLODmaw7t9flfX+z+PpYzMCrU6cmjHpeYDoY52XV RWV2iLTUdnipHQFPcQ8XfSIkDflbFcuFHWYo/TFuTf/CiXNe70imx4uKqSiT3bpZOYOr HfR4CMAFBN+yio9XV5daCncyg+1lP51wE0+wo50+56aT1Nh+bPnA4Z1PGpb2iWEO1uRv QbdUDli7+yMF0sXupOUaVn3xbz/uA5FHSia2DnUx/ZWamgjNDTUJG59frs4FGED2ufTn oIt0oEIm+aub8KqRi+ynj+7hruHrI2zHwp6eQ9SevBG3G7bfJ7Teywh5kgR93ZXVVk9h /9qw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v8-20020a17090690c800b009591e24d0fdsi4030929ejw.981.2023.05.07.06.34.30; Sun, 07 May 2023 06:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8BAD668C173; Sun, 7 May 2023 16:33:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BB5B268C128 for ; Sun, 7 May 2023 16:33:20 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C95622404EE for ; Sun, 7 May 2023 15:33:18 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WCrZcANV786X for ; Sun, 7 May 2023 15:33:18 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 371082405B5 for ; Sun, 7 May 2023 15:33:13 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BDBD43A16B6 for ; Sun, 7 May 2023 15:33:05 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 7 May 2023 15:32:55 +0200 Message-Id: <20230507133255.20881-13-anton@khirnov.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230507133255.20881-1-anton@khirnov.net> References: <20230507133255.20881-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: stop using deprecated ticks_per_frame 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: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2QHW/NWnM7kr --- fftools/ffmpeg.c | 13 +++++++------ fftools/ffmpeg.h | 1 + fftools/ffmpeg_demux.c | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 4e45ab74b9..a731b4bd7d 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1516,12 +1516,13 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo } else if (pkt->duration) { ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q); } else if(ist->dec_ctx->framerate.num != 0) { - int ticks = ist->last_pkt_repeat_pict >= 0 ? - ist->last_pkt_repeat_pict + 1 : - ist->dec_ctx->ticks_per_frame; - ist->next_dts += ((int64_t)AV_TIME_BASE * - ist->dec_ctx->framerate.den * ticks) / - ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame; + int fields = (ist->codec_desc && + (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? + ist->last_pkt_repeat_pict + 1 : 2; + AVRational field_rate = av_mul_q(ist->dec_ctx->framerate, + (AVRational){ 2, 1 }); + + ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q); } break; } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index b6389d7f99..0cceffbe9b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -354,6 +354,7 @@ typedef struct InputStream { AVCodecParameters *par; AVCodecContext *dec_ctx; const AVCodec *dec; + const AVCodecDescriptor *codec_desc; AVFrame *decoded_frame; AVPacket *pkt; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 26426c7ac1..6f26e4226d 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -941,6 +941,8 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n"); exit_program(1); } + + ist->codec_desc = avcodec_descriptor_get(ist->par->codec_id); } }