From patchwork Sat May 7 11:28:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35664 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a885:b0:7f:4be2:bd17 with SMTP id ca5csp2122637pzb; Sat, 7 May 2022 04:34:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt7mSmt0FX0dLsHPnyr7MbFwBcmIUw7XWr9Ti2CkeDZRSrKYnrrsKEKiYCB44JfgbqCOOs X-Received: by 2002:a17:906:a5b:b0:6f4:55f6:78af with SMTP id x27-20020a1709060a5b00b006f455f678afmr7008957ejf.238.1651923240432; Sat, 07 May 2022 04:34:00 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w6-20020a1709060a0600b006e895cb661fsi6825825ejf.151.2022.05.07.04.33.59; Sat, 07 May 2022 04:34:00 -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; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Dn0c3dCB; arc=fail (body hash mismatch); 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 246D668B3E7; Sat, 7 May 2022 14:30:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073076.outbound.protection.outlook.com [40.92.73.76]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 79D7868B4B2 for ; Sat, 7 May 2022 14:30:35 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h3uUvhtSW+aazGaw82J8mLGJZDa2WSiUGTB2sOIRTulaKi75f0TeWMnfQ0vg6hQRBn/caIXHO4EhPJIcZG13nGJY1FRCcWSXCMO/cJ8geyX3YzFciLoj+WqF502AVk2MO1AHMQ9DpZ/YsFXuFZoOGQLQrYKWqv25F/ftWGfYiyxuNabgkAnre3QIDNJPD8ieDvcty2rTKITADGP1L0lDYqBjQTtI1KGvPy9nY3XHu0T0a1+zNJsJJGig5ZLJlg49L/STs6rx93GM8t2bIMJgGR3OkfPtnjZtUQGv8Jfj3rXZBRLq7rg8LTcTw3HoRACTyaayxMnMxDrQpIc9c6z9GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iOFStkDmQmtycK6PWcRffz8m2HtJmnPIshPBcf9+Huw=; b=MovJ7Z+KvIOOxTtRTOam2UUAxW0IUSuYC2P4M/NFmjbZcLDYmpTC8zLtJaCH1+D453HQiOxyiwEyKh5OiVGGEyi6e6EdHxxR2fwIJXdZXvUI4o8IiGIovTaUpSlhWnFY5QqsM9c0dh9GOQEerKfBw3SGioW3VqBpfV8owt6MQTeCp/rKaS7lO/1Cjmg+LDuX8UgbqB81MXxGbQHqQQFseJDnpIlZospOKwOe15s+CDnm5bvDJrfWHyYD74HwQ1vzO9H1uACa56T8fx776+WdnPvnKfH9wIlLO2v2WwaWlV1NSLl7St/llDEO9tGOCNK/kdV3eXUccwgScKZ4/gVmiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iOFStkDmQmtycK6PWcRffz8m2HtJmnPIshPBcf9+Huw=; b=Dn0c3dCBtfKmUXomw+4GS5i8fEVfypho1UMHY6mxC4aPLcG4rUcw3ps86sUQpfA2QhLkfWBRyK/FtMtO57ejZOIdETAiJLcdSilHKr2qN2MLxiMFke2A9Rhj52eQhTbROkJQ/FICuwrlXHCqywjxRqdQ6keVvup4auyGEDpe2mgNRzD1knDLtQctVcuKFpbhmSi1DyGUj4UiG5P3GZYySxI97uEAnbJW5AHtRqxbJtYfJXNQKNrIqTNplgFaZe2nNzGHqeOy3mk4AG5IMjv5ew0TmpSfPb0iBgzMNzeoUtMOwPGpV73GCmom5I9DYL7/SS31pvMxhfA/Gix2oyW1mg== Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) by DB6PR01MB3895.eurprd01.prod.exchangelabs.com (2603:10a6:6:4b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24; Sat, 7 May 2022 11:30:33 +0000 Received: from AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431]) by AS8PR01MB7944.eurprd01.prod.exchangelabs.com ([fe80::1854:2c30:7ba1:c431%6]) with mapi id 15.20.5206.024; Sat, 7 May 2022 11:30:33 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 7 May 2022 13:28:17 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [nPDGO3P6z3QXnYQe7c88TPsFwl9aR89B] X-ClientProxiedBy: ZRAP278CA0004.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::14) To AS8PR01MB7944.eurprd01.prod.exchangelabs.com (2603:10a6:20b:373::5) X-Microsoft-Original-Message-ID: <20220507112830.406162-30-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f33e128-8f23-468e-9d3e-08da301cfdf4 X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiRIovyFjHwHllp74iOQFItwlo3tc/Qzy8NO8XnY7oXLO1T365InGJtjplxvPoapFNaW6lqYVB6Kki1NW9yUctRtdLWFitwOl3tNDRd/92O10IAH99Xuni/yICoXRab1Sn4IR3nIkxtfsqLHupjHDfsinqP6a7E9NSDSlyXFee2H6BNv+DLZko3jquWzPij2tzssn9mmXeSwLjTdBb+NkYlTTprPAdW7jQRf+yzJ3Gxirw8QXwGSfuJ2LKAMStclBfh1pBWDjspZGcijFMsDHJE6BVYFlI19MHRxIiVh8kOAHobexyobQzzlXzn/+54OoRJ7ZEgSMYC9g6vtTpw1ogCJ/47OKjV07oORGw3idx8C2Seg19O4Tgiy6PthkkvF5mh5MCr6Od6juNGF1QfF7u1qKJeWUs1gkY2NTw+pV5u/Xb58j7L3C14aaKnf4QpUR7bHi9ATEx4/UK+o+oqc4neq06/2QJADXfnQPXXEjX9xUVKU7y459xe8hg4XRRIy8Rrw+2s11faEpNKp1G3hL9q5Tw2WR3aOV6/icPdm2qvV7iwbcT0mpu+ZwlRg6ZnM8uqtPgHLjiD8IiRZx0DdrJl/SikAGwdmf4aIWAXLnoXa87N2V6KMuLYyLvXXiN+rbaTCNCUDWwv0abk424E7SHJd7UsfjTRcJWp8aXmnAoMC53Cuz+PAkSGGXrzCvSrx5aCVGbUOyjOFCzicGks2MgsrKchg6LLAdgifDFUvNSFXEtIKe4u5TfI52e/PjGTftmQ= X-MS-TrafficTypeDiagnostic: DB6PR01MB3895:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HVfUClB1WeOJt4z9LsVJSMznTeUpvqDrhtcOF2vLV6QP679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enant-Network-Message-Id: 4f33e128-8f23-468e-9d3e-08da301cfdf4 X-MS-Exchange-CrossTenant-AuthSource: AS8PR01MB7944.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2022 11:30:30.6261 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR01MB3895 Subject: [FFmpeg-devel] [PATCH 31/44] avformat/utils: Move internal stream timebase stuff to avformat.c 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BzyGXN96OTXM Signed-off-by: Andreas Rheinhardt --- libavformat/avformat.c | 66 ++++++++++++++++++++++++++++++++++++++++++ libavformat/utils.c | 65 ----------------------------------------- 2 files changed, 66 insertions(+), 65 deletions(-) diff --git a/libavformat/avformat.c b/libavformat/avformat.c index 0b86ff025c..ac0e28a6a9 100644 --- a/libavformat/avformat.c +++ b/libavformat/avformat.c @@ -20,6 +20,8 @@ */ #include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/intreadwrite.h" #include "libavutil/mem.h" #include "libavutil/opt.h" #include "libavcodec/avcodec.h" @@ -254,3 +256,67 @@ void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx) return; } } + +int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, + AVStream *ost, const AVStream *ist, + enum AVTimebaseSource copy_tb) +{ + const AVCodecContext *const dec_ctx = cffstream(ist)->avctx; + AVCodecContext *const enc_ctx = ffstream(ost)->avctx; + + enc_ctx->time_base = ist->time_base; + /* + * Avi is a special case here because it supports variable fps but + * having the fps and timebase differe significantly adds quite some + * overhead + */ + if (!strcmp(ofmt->name, "avi")) { +#if FF_API_R_FRAME_RATE + if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num + && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate) + && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base) + && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base) + && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500 + || 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; + enc_ctx->ticks_per_frame = 2; + } else +#endif + if (copy_tb == AVFMT_TBCF_AUTO && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > 2*av_q2d(ist->time_base) + && av_q2d(ist->time_base) < 1.0/500 + || copy_tb == AVFMT_TBCF_DECODER) { + enc_ctx->time_base = dec_ctx->time_base; + enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; + enc_ctx->time_base.den *= 2; + enc_ctx->ticks_per_frame = 2; + } + } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS) + && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) { + if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->time_base.den + && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > av_q2d(ist->time_base) + && av_q2d(ist->time_base) < 1.0/500 + || copy_tb == AVFMT_TBCF_DECODER) { + enc_ctx->time_base = dec_ctx->time_base; + enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; + } + } + + if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd")) + && dec_ctx->time_base.num < dec_ctx->time_base.den + && dec_ctx->time_base.num > 0 + && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) { + enc_ctx->time_base = dec_ctx->time_base; + } + + av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den, + enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX); + + return 0; +} + +AVRational av_stream_get_codec_timebase(const AVStream *st) +{ + // See avformat_transfer_internal_stream_timing_info() TODO. + return cffstream(st)->avctx->time_base; +} diff --git a/libavformat/utils.c b/libavformat/utils.c index 3267db432e..f5d24e7a3a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -28,7 +28,6 @@ #include "libavutil/bprint.h" #include "libavutil/dict.h" #include "libavutil/internal.h" -#include "libavutil/intreadwrite.h" #include "libavutil/pixfmt.h" #include "libavutil/thread.h" #include "libavutil/time.h" @@ -1079,70 +1078,6 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf return 0; } -int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt, - AVStream *ost, const AVStream *ist, - enum AVTimebaseSource copy_tb) -{ - const AVCodecContext *const dec_ctx = cffstream(ist)->avctx; - AVCodecContext *const enc_ctx = ffstream(ost)->avctx; - - enc_ctx->time_base = ist->time_base; - /* - * Avi is a special case here because it supports variable fps but - * having the fps and timebase differe significantly adds quite some - * overhead - */ - if (!strcmp(ofmt->name, "avi")) { -#if FF_API_R_FRAME_RATE - if (copy_tb == AVFMT_TBCF_AUTO && ist->r_frame_rate.num - && av_q2d(ist->r_frame_rate) >= av_q2d(ist->avg_frame_rate) - && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(ist->time_base) - && 0.5/av_q2d(ist->r_frame_rate) > av_q2d(dec_ctx->time_base) - && av_q2d(ist->time_base) < 1.0/500 && av_q2d(dec_ctx->time_base) < 1.0/500 - || 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; - enc_ctx->ticks_per_frame = 2; - } else -#endif - if (copy_tb == AVFMT_TBCF_AUTO && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > 2*av_q2d(ist->time_base) - && av_q2d(ist->time_base) < 1.0/500 - || copy_tb == AVFMT_TBCF_DECODER) { - enc_ctx->time_base = dec_ctx->time_base; - enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; - enc_ctx->time_base.den *= 2; - enc_ctx->ticks_per_frame = 2; - } - } else if (!(ofmt->flags & AVFMT_VARIABLE_FPS) - && !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) { - if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->time_base.den - && av_q2d(dec_ctx->time_base)*dec_ctx->ticks_per_frame > av_q2d(ist->time_base) - && av_q2d(ist->time_base) < 1.0/500 - || copy_tb == AVFMT_TBCF_DECODER) { - enc_ctx->time_base = dec_ctx->time_base; - enc_ctx->time_base.num *= dec_ctx->ticks_per_frame; - } - } - - if ((enc_ctx->codec_tag == AV_RL32("tmcd") || ost->codecpar->codec_tag == AV_RL32("tmcd")) - && dec_ctx->time_base.num < dec_ctx->time_base.den - && dec_ctx->time_base.num > 0 - && 121LL*dec_ctx->time_base.num > dec_ctx->time_base.den) { - enc_ctx->time_base = dec_ctx->time_base; - } - - av_reduce(&enc_ctx->time_base.num, &enc_ctx->time_base.den, - enc_ctx->time_base.num, enc_ctx->time_base.den, INT_MAX); - - return 0; -} - -AVRational av_stream_get_codec_timebase(const AVStream *st) -{ - // See avformat_transfer_internal_stream_timing_info() TODO. - return cffstream(st)->avctx->time_base; -} - void ff_format_set_url(AVFormatContext *s, char *url) { av_assert0(url);