From patchwork Sat Nov 26 08:19:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39453 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013189pzb; Sat, 26 Nov 2022 00:20:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf42nMjkF8pXXvrfUUwmMZR+Gx0aC7lHfm3FGhZmLpTeSta2oFjMO7qHBUfqCSIxeCO2wlvl X-Received: by 2002:a05:6402:4498:b0:458:8e63:d667 with SMTP id er24-20020a056402449800b004588e63d667mr37179185edb.354.1669450804199; Sat, 26 Nov 2022 00:20:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450804; cv=none; d=google.com; s=arc-20160816; b=QWlX1koIow00Tu8KMHdSp4PgKjS6al22f5xa8UrAFYFpkflthiwjtkxI75gnL/cgJp nH4KaIu05wfoRt31E38RXQtqx8af/PKIJNK6cTkABIN8Rl6aTGfSC9lw63qN7A8F9dWo xWvJ1uYY3XcgcBlR0Fvx1rLzbUzv8DOYSN0lzZfQtrspCtAsaiZwMVNaaDVCXUBKbP1G xVVJ+xxrZfTU98wVgHouM78SrsycU2WoiVpdikR5/biY255016TLQdK5BRZSM1/kunTq GlqJjEE0J4iPobW0KG625uvSfOJf7xc+7y49lGiVL7KsbOnCkM/vdkL0l28srioKUAwA e5+Q== 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=/8VqDYv4cpCwNMFYgkThp3NTdBnnMLPRfNZWJrnI3hk=; b=GIoaO5RENCqlNjvbiTXAM7DIhUIbKZ22JXI+auja4f8jpw/JcQwZZ8iqy1rg3FUo1E AfhYQxH24uzjv3xUFD0he43dJteBE2ecOzIjPUy/9ImCOPq2k+5Ji/RnrEE+/kHur/RO J1AHT29DzogCMdMyA+9BFOi4Qh4TIU/+Y6ZeGlhWigK084iwnPJC0sRvbAKXhTyDdfBo Xac84QMgQpPtwXITOyF0TGNLYQZTwfZzktWf/Yg9vucW3tLFtZi6IIhorI2QjxlY7v9P tBogNelgorpQ7Hxe8J5pj31L5/iMVYkvyd4NPDu34HqiDU5Dy14vBk+MlITSluv1gJ9S fs7Q== 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 s15-20020a056402036f00b00461ebc19dcesi5233739edw.56.2022.11.26.00.20.03; Sat, 26 Nov 2022 00:20:04 -0800 (PST) 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 5E61968B7E9; Sat, 26 Nov 2022 10:19:34 +0200 (EET) 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 45C2268B48E for ; Sat, 26 Nov 2022 10:19:25 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 091432404F7 for ; Sat, 26 Nov 2022 09:19:25 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id AL3u-qWGZrMJ for ; Sat, 26 Nov 2022 09:19:24 +0100 (CET) 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 96B702404F8 for ; Sat, 26 Nov 2022 09:19:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 62B443A05A8 for ; Sat, 26 Nov 2022 09:19:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Nov 2022 09:19:01 +0100 Message-Id: <20221126081911.31275-3-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221126081911.31275-1-anton@khirnov.net> References: <20221126081911.31275-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/13] fftools/ffmpeg: store forced keyframe pts in AV_TIME_BASE_Q 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: brQxiZI6A1oi Rather than the encoder timebase. Since the times are parsed as microseconds, this will not reduce precision, except possibly when chapter times are used and the chapter timebase happens to be better aligned with the encoder timebase, which is unlikely. This will allow parsing the keyframe times earlier (before encoder timebase is known) in future commits. --- fftools/ffmpeg.c | 15 +++++---------- fftools/ffmpeg.h | 1 + 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3d10ffc3b2..5d39d8f69b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1052,7 +1052,7 @@ static enum AVPictureType forced_kf_apply(KeyframeForceCtx *kf, AVRational tb, pts_time = (in_picture->pts - kf->ref_pts) * av_q2d(tb); if (kf->index < kf->nb_pts && - in_picture->pts >= kf->pts[kf->index]) { + av_compare_ts(in_picture->pts, tb, kf->pts[kf->index], AV_TIME_BASE_Q) >= 0) { kf->index++; goto force_keyframe; } else if (kf->pexpr) { @@ -2748,8 +2748,7 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost) AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); } -static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of, - AVCodecContext *avctx) +static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of) { const char *p; int n = 1, i, size, index = 0; @@ -2782,21 +2781,17 @@ static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of, sizeof(*pts)))) report_and_exit(AVERROR(ENOMEM)); t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; - t = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); for (j = 0; j < nb_ch; j++) { const AVChapter *c = ch[j]; av_assert1(index < size); pts[index++] = av_rescale_q(c->start, c->time_base, - avctx->time_base) + t; + AV_TIME_BASE_Q) + t; } } else { - - t = parse_time_or_die("force_key_frames", p, 1); av_assert1(index < size); - pts[index++] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); - + pts[index++] = parse_time_or_die("force_key_frames", p, 1); } p = next; @@ -2971,7 +2966,7 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes', // parse it only for static kf timings } else if(strncmp(ost->kf.forced_keyframes, "source", 6)) { - parse_forced_key_frames(&ost->kf, of, ost->enc_ctx); + parse_forced_key_frames(&ost->kf, of); } } break; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index db1f00b259..f5d51b90ec 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -492,6 +492,7 @@ typedef struct KeyframeForceCtx { int64_t ref_pts; + // timestamps of the forced keyframes, in AV_TIME_BASE_Q int64_t *pts; int nb_pts; int index;