From patchwork Sat Nov 26 08:18:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39450 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013030pzb; Sat, 26 Nov 2022 00:19:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf6J7QTYPc2qBRgl8EuCQBRgw3jsR6THRetEuEtrivPobPyUbLA4CSIqQ/gopZGzlriGw5Ie X-Received: by 2002:aa7:c84d:0:b0:468:354b:280d with SMTP id g13-20020aa7c84d000000b00468354b280dmr39837248edt.178.1669450776212; Sat, 26 Nov 2022 00:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450776; cv=none; d=google.com; s=arc-20160816; b=nCBbMvOG4DkJdrWOFf/YSw7dT2ByaVE50nsifTZ2184FAOdruL/c4wOL2j6Z8Fy6hs DMlJFg87BRTRpQVk8zQiTNvXlDdH+X6zzcEAfFBIFsU9CS5VGGgVx0YpKmX0SGbCUnVc Nc/0BgQ4wy190MrBc8TM4fMMhQ2sb43DukUccLJQ4c9AdNQEd/4Ny8/QMVnrsOVQ29Ae CSpcRFQzrBkHOnxz2FV7NusF3DXXujePN4fruy+h+MyNsignowydxbV5momX2tSer/O8 05SdrIIK+K0o4V9t56078MKPqoVW0Fus7DuSK0y+Su9VW2KVGXRXNd/6CeqAZAfaOPlT lwbg== 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=CAD9B9UXiT60f9z3CCpmAe6PkN3OVIZgnpnahSmPS/E=; b=PUQiXyBZmiuckX3qxQFPcEFLdkrXxC8JIpUhxNiHrc3WNSKCafb6hXuv9Ktr7fi0mb M3ozBk4nIQE6BQwTYDZYnd6EjU2TToASDJoodPyXtdsktPdz7Monmht9AXQbwZpJ0KCO oVb0DiEcraqZi0CNWsdzxwSf++uW2TnzDNO7gouMR0Xdw3Eog1+acC1B0u5WWEv68Kmg 2hZfA2QJe/Zv/8dG9nQnxTbxCEMMziqniyHgxHG1zBZebAp+LWgsD9xCY2dBOjycSPRp 1lWkr1IRDXQemSRlLWGz4QSW9lC28gWZ88HZCx+xNGZd37q62AAKcDyLd42kQrOiHVr4 itGg== 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 25-20020a508e59000000b00468cd2ab847si3956769edx.172.2022.11.26.00.19.35; Sat, 26 Nov 2022 00:19:36 -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 4D09C68B6F0; Sat, 26 Nov 2022 10:19:31 +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 A4E8368A929 for ; Sat, 26 Nov 2022 10:19:24 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3E9F52406CF for ; Sat, 26 Nov 2022 09:19:24 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id isnshZu0jX8V for ; Sat, 26 Nov 2022 09:19:23 +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 898EA2400F5 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 4AE643A0102 for ; Sat, 26 Nov 2022 09:19:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 26 Nov 2022 09:18:59 +0100 Message-Id: <20221126081911.31275-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/13] fftools/ffmpeg: stop explicitly closing decoders 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: qJXqtN6L3hOL It serves no purpose, they will be closed and freed in avcodec_free_context() called from ist_free(). --- fftools/ffmpeg.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 3767ab444b..ba91af2c95 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -3908,13 +3908,6 @@ static int transcode(void) exit_program(1); } - /* close each decoder */ - for (ist = ist_iter(NULL); ist; ist = ist_iter(ist)) { - if (ist->decoding_needed) { - avcodec_close(ist->dec_ctx); - } - } - hw_device_free_all(); /* finished ! */ From patchwork Sat Nov 26 08:19:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39451 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013100pzb; Sat, 26 Nov 2022 00:19:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf6RPkgE9obXlQTwsAGWpcaLoUtpQOHhD6aSJVFlzLMv7Sep1pEyccUykwZM6DasdIS20K+t X-Received: by 2002:a05:6402:25c6:b0:461:b825:d7cb with SMTP id x6-20020a05640225c600b00461b825d7cbmr16180615edb.167.1669450787524; Sat, 26 Nov 2022 00:19:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450787; cv=none; d=google.com; s=arc-20160816; b=yIy37q7awBqPlp8vt1r6NBt2Dox/VRUtTaEdbX50QsDFIUOr+JJCy8jK2GAAj70qoj UbkmZUb1n0QFp1Xvijf3hcKC18gZuohKCbCbQtNE4ATalbwFA11CVQKgRucUOSXzBjjc p0qTVAEajfsTxZFkCdh+5xtGVERlHdJU9UcwArDt6bfMprLefwJLq2I+9hQNY+134wp/ CEO5NmkFAvX1wrCc79q97LmT74URKzO4EiAht5DDemayq6akfRuh2c1iJWFgmI862qQH 3fEfXrBVZToZbtVU7iA4QhGMdCwJKr9lPoVsZnaseY0kgYI6LpdWTWvT1vvDiR8P9IZ7 kQZQ== 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=noFfpeTiUqsPKrnA5CvlIHaPfOOO7FcL4MHlsjd/a3U=; b=q5uvNWrOGSpICQ03ATg7acbJqhl1xVU3Dke8OwE2A5RP05WdxGGfJP7/sHCszYRXFr BuNsUnx79GdG28eXeew8RAG3R7vF0p9KOfQwUgVK4C7z7y8k4KGP8YMB7Su5QN5kHGgM Qs7CMJUiuik3GdkQnz53+fuyU9zuMZjufJHkCMFjwqCCaj5GjLn8YB4mQXR7powfVK5m +IpUIDcdhr5AEY/keLPC9w7iPEzrs7UZleU5oLiTya2hQWTZxgJWotuGjlcIeQeKKOYR CHeyqUFaLznKQTqDkHe1XWZuuBbVZ/Aj7EaMInz4RZ1rTkIAr6fxWsmUCySCFc6z6a0V rbEw== 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 em7-20020a056402364700b004597671e0ddsi4878043edb.338.2022.11.26.00.19.47; Sat, 26 Nov 2022 00:19:47 -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 72FB968B721; Sat, 26 Nov 2022 10:19:32 +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 B08BE68B48E for ; Sat, 26 Nov 2022 10:19:24 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7D07A2400F5 for ; Sat, 26 Nov 2022 09:19:24 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XZro7c5hZvpS for ; Sat, 26 Nov 2022 09:19:23 +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 907F8240499 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 57CC53A040A 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:00 +0100 Message-Id: <20221126081911.31275-2-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 02/13] fftools/ffmpeg: move force-keyframe-related vars to a separate struct 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: LIXRStH68I5U There are 8 of them and they are typically used together. Allows to pass just this struct to forced_kf_apply(), which makes it clear that the rest of the OutputStream is not accessed there. --- fftools/ffmpeg.c | 92 +++++++++++++++++++-------------------- fftools/ffmpeg.h | 25 +++++++---- fftools/ffmpeg_mux.c | 7 +-- fftools/ffmpeg_mux_init.c | 8 ++-- 4 files changed, 68 insertions(+), 64 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ba91af2c95..3d10ffc3b2 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1042,52 +1042,49 @@ static void do_subtitle_out(OutputFile *of, } } -static enum AVPictureType forced_kf_apply(OutputStream *ost, +static enum AVPictureType forced_kf_apply(KeyframeForceCtx *kf, AVRational tb, const AVFrame *in_picture, int dup_idx) { - AVCodecContext *enc = ost->enc_ctx; double pts_time; - if (ost->forced_kf_ref_pts == AV_NOPTS_VALUE) - ost->forced_kf_ref_pts = in_picture->pts; + if (kf->ref_pts == AV_NOPTS_VALUE) + kf->ref_pts = in_picture->pts; - pts_time = (in_picture->pts - ost->forced_kf_ref_pts) * av_q2d(enc->time_base); - if (ost->forced_kf_index < ost->forced_kf_count && - in_picture->pts >= ost->forced_kf_pts[ost->forced_kf_index]) { - ost->forced_kf_index++; + pts_time = (in_picture->pts - kf->ref_pts) * av_q2d(tb); + if (kf->index < kf->nb_pts && + in_picture->pts >= kf->pts[kf->index]) { + kf->index++; goto force_keyframe; - } else if (ost->forced_keyframes_pexpr) { + } else if (kf->pexpr) { double res; - ost->forced_keyframes_expr_const_values[FKF_T] = pts_time; - res = av_expr_eval(ost->forced_keyframes_pexpr, - ost->forced_keyframes_expr_const_values, NULL); + kf->expr_const_values[FKF_T] = pts_time; + res = av_expr_eval(kf->pexpr, + kf->expr_const_values, NULL); ff_dlog(NULL, "force_key_frame: n:%f n_forced:%f prev_forced_n:%f t:%f prev_forced_t:%f -> res:%f\n", - ost->forced_keyframes_expr_const_values[FKF_N], - ost->forced_keyframes_expr_const_values[FKF_N_FORCED], - ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N], - ost->forced_keyframes_expr_const_values[FKF_T], - ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T], + kf->expr_const_values[FKF_N], + kf->expr_const_values[FKF_N_FORCED], + kf->expr_const_values[FKF_PREV_FORCED_N], + kf->expr_const_values[FKF_T], + kf->expr_const_values[FKF_PREV_FORCED_T], res); - ost->forced_keyframes_expr_const_values[FKF_N] += 1; + kf->expr_const_values[FKF_N] += 1; if (res) { - ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = - ost->forced_keyframes_expr_const_values[FKF_N] - 1; - ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = - ost->forced_keyframes_expr_const_values[FKF_T]; - ost->forced_keyframes_expr_const_values[FKF_N_FORCED] += 1; + kf->expr_const_values[FKF_PREV_FORCED_N] = kf->expr_const_values[FKF_N] - 1; + kf->expr_const_values[FKF_PREV_FORCED_T] = kf->expr_const_values[FKF_T]; + kf->expr_const_values[FKF_N_FORCED] += 1; goto force_keyframe; } - } else if (ost->forced_keyframes && - !strncmp(ost->forced_keyframes, "source", 6) && + } else if (kf->forced_keyframes && + !strncmp(kf->forced_keyframes, "source", 6) && in_picture->key_frame == 1 && !dup_idx) { goto force_keyframe; - } else if (ost->forced_keyframes && - !strncmp(ost->forced_keyframes, "source_no_drop", 14) && + } else if (kf->forced_keyframes && + !strncmp(kf->forced_keyframes, "source_no_drop", 14) && !dup_idx) { - ost->dropped_keyframe = 0; - if ((in_picture->key_frame == 1) || ost->dropped_keyframe) + kf->dropped_keyframe = 0; + if ((in_picture->key_frame == 1) || kf->dropped_keyframe) goto force_keyframe; } @@ -1223,7 +1220,7 @@ static void do_video_out(OutputFile *of, } } ost->last_dropped = nb_frames == nb0_frames && next_picture; - ost->dropped_keyframe = ost->last_dropped && next_picture && next_picture->key_frame; + ost->kf.dropped_keyframe = ost->last_dropped && next_picture && next_picture->key_frame; /* duplicates frame if needed */ for (i = 0; i < nb_frames; i++) { @@ -1243,7 +1240,7 @@ static void do_video_out(OutputFile *of, return; in_picture->quality = enc->global_quality; - in_picture->pict_type = forced_kf_apply(ost, in_picture, i); + in_picture->pict_type = forced_kf_apply(&ost->kf, enc->time_base, in_picture, i); ret = submit_encode_frame(of, ost, in_picture); if (ret == AVERROR_EOF) @@ -2751,14 +2748,14 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost) AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); } -static void parse_forced_key_frames(char *kf, OutputStream *ost, +static void parse_forced_key_frames(KeyframeForceCtx *kf, OutputFile *of, AVCodecContext *avctx) { - char *p; + const char *p; int n = 1, i, size, index = 0; int64_t t, *pts; - for (p = kf; *p; p++) + for (p = kf->forced_keyframes; *p; p++) if (*p == ',') n++; size = n; @@ -2766,7 +2763,7 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, if (!pts) report_and_exit(AVERROR(ENOMEM)); - p = kf; + p = kf->forced_keyframes; for (i = 0; i < n; i++) { char *next = strchr(p, ','); @@ -2774,7 +2771,6 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, *next++ = 0; if (!memcmp(p, "chapters", 8)) { - OutputFile *of = output_files[ost->file_index]; AVChapter * const *ch; unsigned int nb_ch; int j; @@ -2808,8 +2804,8 @@ static void parse_forced_key_frames(char *kf, OutputStream *ost, av_assert0(index == size); qsort(pts, size, sizeof(*pts), compare_int64); - ost->forced_kf_count = size; - ost->forced_kf_pts = pts; + kf->nb_pts = size; + kf->pts = pts; } static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base) @@ -2958,24 +2954,24 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) enc_ctx->field_order = AV_FIELD_TT; } - if (ost->forced_keyframes) { - if (!strncmp(ost->forced_keyframes, "expr:", 5)) { - ret = av_expr_parse(&ost->forced_keyframes_pexpr, ost->forced_keyframes+5, + if (ost->kf.forced_keyframes) { + if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) { + ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5, forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, - "Invalid force_key_frames expression '%s'\n", ost->forced_keyframes+5); + "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5); return ret; } - ost->forced_keyframes_expr_const_values[FKF_N] = 0; - ost->forced_keyframes_expr_const_values[FKF_N_FORCED] = 0; - ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_N] = NAN; - ost->forced_keyframes_expr_const_values[FKF_PREV_FORCED_T] = NAN; + ost->kf.expr_const_values[FKF_N] = 0; + ost->kf.expr_const_values[FKF_N_FORCED] = 0; + ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN; + ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN; // Don't parse the 'forced_keyframes' in case of 'keep-source-keyframes', // parse it only for static kf timings - } else if(strncmp(ost->forced_keyframes, "source", 6)) { - parse_forced_key_frames(ost->forced_keyframes, ost, ost->enc_ctx); + } else if(strncmp(ost->kf.forced_keyframes, "source", 6)) { + parse_forced_key_frames(&ost->kf, of, ost->enc_ctx); } } break; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 4b76b1d0d7..db1f00b259 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -487,6 +487,21 @@ typedef enum { MUXER_FINISHED = 2, } OSTFinished ; +typedef struct KeyframeForceCtx { + char *forced_keyframes; + + int64_t ref_pts; + + int64_t *pts; + int nb_pts; + int index; + + AVExpr *pexpr; + double expr_const_values[FKF_NB]; + + int dropped_keyframe; +} KeyframeForceCtx; + typedef struct OutputStream { int file_index; /* file index */ int index; /* stream index in the output file */ @@ -543,15 +558,7 @@ typedef struct OutputStream { AVRational frame_aspect_ratio; - /* forced key frames */ - int64_t forced_kf_ref_pts; - int64_t *forced_kf_pts; - int forced_kf_count; - int forced_kf_index; - char *forced_keyframes; - AVExpr *forced_keyframes_pexpr; - double forced_keyframes_expr_const_values[FKF_NB]; - int dropped_keyframe; + KeyframeForceCtx kf; /* audio only */ #if FFMPEG_OPT_MAP_CHANNEL diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 2b885f7ab0..7da29db8f4 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -667,11 +667,12 @@ static void ost_free(OutputStream **post) av_packet_free(&ost->pkt); av_dict_free(&ost->encoder_opts); - av_freep(&ost->forced_keyframes); - av_expr_free(ost->forced_keyframes_pexpr); + av_freep(&ost->kf.forced_keyframes); + av_freep(&ost->kf.pts); + av_expr_free(ost->kf.pexpr); + av_freep(&ost->avfilter); av_freep(&ost->logfile_prefix); - av_freep(&ost->forced_kf_pts); av_freep(&ost->apad); #if FFMPEG_OPT_MAP_CHANNEL diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 7aa2e030d8..bdec0744a9 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -202,7 +202,7 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o, ost->file_index = nb_output_files - 1; ost->index = idx; ost->st = st; - ost->forced_kf_ref_pts = AV_NOPTS_VALUE; + ost->kf.ref_pts = AV_NOPTS_VALUE; st->codecpar->codec_type = type; ret = choose_encoder(o, oc, ost, &enc); @@ -604,9 +604,9 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, Input } } - MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st); - if (ost->forced_keyframes) - ost->forced_keyframes = av_strdup(ost->forced_keyframes); + MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->kf.forced_keyframes, oc, st); + if (ost->kf.forced_keyframes) + ost->kf.forced_keyframes = av_strdup(ost->kf.forced_keyframes); MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st); 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; From patchwork Sat Nov 26 08:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39456 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013330pzb; Sat, 26 Nov 2022 00:20:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jfKWtk9VX5XjLaOsE6fRaKaH2gGI6NpD97vaaTqEr2rVb/q6hycyO7XQ1kqcqXrHoIYGp X-Received: by 2002:a05:6402:1118:b0:467:a8cb:10c9 with SMTP id u24-20020a056402111800b00467a8cb10c9mr24495955edv.123.1669450831820; Sat, 26 Nov 2022 00:20:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450831; cv=none; d=google.com; s=arc-20160816; b=fMuA1naOkYhD90pmrNc0WLxgYG+Yv17BHJ0mzflYhaQSNOisHbLsvYGS1mJjwosQ6o S8joz+ECDcD+i2CwkEP0LBwmfTOiPb6mp9vqAcZuTVoMCyN97giWKuQxt8kiMY4R/6Tj qaamq56c1W95aYjwKKP8PkV23LIyDSoeO4KUH4/Y0Lq/DggX2DwrFRse9cfHAJ3Z6TkC 96YJ9aZV+pb/CQUlkzzga09plGqRVS3Oggz7/V4Z+26mK5KCV3HktVZ1lQEk6pAFS40/ G4tZ6DPefbL0fJ9TmufAP9QWkhkXSH0RwawVleNDtIXoTr1FCAjAbShYWtdNyiJVgMnq wf3w== 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=a4c0JLJJRpb7LGD2IdG1SNQNAwXJ0VjfvhCDdFp8DNU=; b=Dh1JzsSL7lqjj2/iOMk7SVpVkiuMxOKayEbyul37xB8NDiTliSJG9oB7R/PVOESQvk im+GqNUwIJ9494xb/uhw8WmD5ib0w//LmsFhspNqv5hDM0eyiLIlZCjdlq22MI1CqfaL Xy/+ZcqOyw8bXfp0WP0/r8+wo+SRO4ABkPxmgXmqrt5tvw+UiWP+JoVu1iEAzcfCTKVi +WXnYZmcUvcNgpTcjyajaDseN+S3cyb59BGElL1vMJvmOiZyyoQLhCyciNj+YtzDCjFz iTx5cM27J0bX8F8dzOR+DhHtJTsQE7pteL221tGNqjchrmrKoqS3EYZYRb8+dM3/1cVF Ji4Q== 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 nd39-20020a17090762a700b0078dce2b1985si5762808ejc.134.2022.11.26.00.20.31; Sat, 26 Nov 2022 00:20:31 -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 4016C68B929; Sat, 26 Nov 2022 10:19:37 +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 E3F8668A929 for ; Sat, 26 Nov 2022 10:19:29 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DB2DF2405EC 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 6r8khqjEor27 for ; Sat, 26 Nov 2022 09:19:25 +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 9D2D5240591 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 6DB223A066C 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:02 +0100 Message-Id: <20221126081911.31275-4-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 04/13] fftools/ffmpeg: parse forced keyframes in of_open() 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: oWw083Ei7xuS Allows to remove the ugly of_get_chapters() wrapper. --- fftools/ffmpeg.c | 89 -------------------------------- fftools/ffmpeg.h | 2 - fftools/ffmpeg_mux.c | 8 --- fftools/ffmpeg_mux_init.c | 106 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 99 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 5d39d8f69b..12ce108cc6 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -113,15 +113,6 @@ const int program_birth_year = 2000; static FILE *vstats_file; -const char *const forced_keyframes_const_names[] = { - "n", - "n_forced", - "prev_forced_n", - "prev_forced_t", - "t", - NULL -}; - typedef struct BenchmarkTimeStamps { int64_t real_usec; int64_t user_usec; @@ -2590,11 +2581,6 @@ static int init_input_stream(InputStream *ist, char *error, int error_len) return 0; } -static int compare_int64(const void *a, const void *b) -{ - return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b); -} - static int init_output_stream_streamcopy(OutputStream *ost) { OutputFile *of = output_files[ost->file_index]; @@ -2748,61 +2734,6 @@ 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) -{ - const char *p; - int n = 1, i, size, index = 0; - int64_t t, *pts; - - for (p = kf->forced_keyframes; *p; p++) - if (*p == ',') - n++; - size = n; - pts = av_malloc_array(size, sizeof(*pts)); - if (!pts) - report_and_exit(AVERROR(ENOMEM)); - - p = kf->forced_keyframes; - for (i = 0; i < n; i++) { - char *next = strchr(p, ','); - - if (next) - *next++ = 0; - - if (!memcmp(p, "chapters", 8)) { - AVChapter * const *ch; - unsigned int nb_ch; - int j; - - ch = of_get_chapters(of, &nb_ch); - - if (nb_ch > INT_MAX - size || - !(pts = av_realloc_f(pts, size += nb_ch - 1, - sizeof(*pts)))) - report_and_exit(AVERROR(ENOMEM)); - t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; - - 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, - AV_TIME_BASE_Q) + t; - } - - } else { - av_assert1(index < size); - pts[index++] = parse_time_or_die("force_key_frames", p, 1); - } - - p = next; - } - - av_assert0(index == size); - qsort(pts, size, sizeof(*pts), compare_int64); - kf->nb_pts = size; - kf->pts = pts; -} - static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base) { InputStream *ist = ost->ist; @@ -2949,26 +2880,6 @@ static int init_output_stream_encode(OutputStream *ost, AVFrame *frame) enc_ctx->field_order = AV_FIELD_TT; } - if (ost->kf.forced_keyframes) { - if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) { - ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5, - forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, - "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5); - return ret; - } - ost->kf.expr_const_values[FKF_N] = 0; - ost->kf.expr_const_values[FKF_N_FORCED] = 0; - ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN; - ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN; - - // 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); - } - } break; case AVMEDIA_TYPE_SUBTITLE: enc_ctx->time_base = AV_TIME_BASE_Q; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index f5d51b90ec..bf2abf55ee 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -757,8 +757,6 @@ void of_close(OutputFile **pof); */ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof); int64_t of_filesize(OutputFile *of); -AVChapter * const * -of_get_chapters(OutputFile *of, unsigned int *nb_chapters); int ifile_open(const OptionsContext *o, const char *filename); void ifile_close(InputFile **f); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 7da29db8f4..de5facbdc0 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -736,11 +736,3 @@ int64_t of_filesize(OutputFile *of) Muxer *mux = mux_from_of(of); return atomic_load(&mux->last_filesize); } - -AVChapter * const * -of_get_chapters(OutputFile *of, unsigned int *nb_chapters) -{ - Muxer *mux = mux_from_of(of); - *nb_chapters = mux->fc->nb_chapters; - return mux->fc->chapters; -} diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index bdec0744a9..25e2ab8631 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1745,6 +1745,104 @@ finish: return ret; } +const char *const forced_keyframes_const_names[] = { + "n", + "n_forced", + "prev_forced_n", + "prev_forced_t", + "t", + NULL +}; + +static int compare_int64(const void *a, const void *b) +{ + return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b); +} + +static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux) +{ + const char *p; + int n = 1, i, size, index = 0; + int64_t t, *pts; + + for (p = kf->forced_keyframes; *p; p++) + if (*p == ',') + n++; + size = n; + pts = av_malloc_array(size, sizeof(*pts)); + if (!pts) + report_and_exit(AVERROR(ENOMEM)); + + p = kf->forced_keyframes; + for (i = 0; i < n; i++) { + char *next = strchr(p, ','); + + if (next) + *next++ = 0; + + if (!memcmp(p, "chapters", 8)) { + AVChapter * const *ch = mux->fc->chapters; + unsigned int nb_ch = mux->fc->nb_chapters; + int j; + + if (nb_ch > INT_MAX - size || + !(pts = av_realloc_f(pts, size += nb_ch - 1, + sizeof(*pts)))) + report_and_exit(AVERROR(ENOMEM)); + t = p[8] ? parse_time_or_die("force_key_frames", p + 8, 1) : 0; + + 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, + AV_TIME_BASE_Q) + t; + } + + } else { + av_assert1(index < size); + pts[index++] = parse_time_or_die("force_key_frames", p, 1); + } + + p = next; + } + + av_assert0(index == size); + qsort(pts, size, sizeof(*pts), compare_int64); + kf->nb_pts = size; + kf->pts = pts; +} + +static int process_forced_keyframes(Muxer *mux) +{ + for (int i = 0; i < mux->of.nb_streams; i++) { + OutputStream *ost = mux->of.streams[i]; + + if (!ost->kf.forced_keyframes) + continue; + + if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) { + int ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5, + forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, + "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5); + return ret; + } + ost->kf.expr_const_values[FKF_N] = 0; + ost->kf.expr_const_values[FKF_N_FORCED] = 0; + ost->kf.expr_const_values[FKF_PREV_FORCED_N] = NAN; + ost->kf.expr_const_values[FKF_PREV_FORCED_T] = NAN; + + // 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, mux); + } + } + + return 0; +} + static void validate_enc_avopt(const Muxer *mux, const AVDictionary *codec_avopt) { const AVClass *class = avcodec_get_class(); @@ -1961,6 +2059,14 @@ int of_open(const OptionsContext *o, const char *filename) exit_program(1); } + // parse forced keyframe specifications; + // must be done after chapters are created + err = process_forced_keyframes(mux); + if (err < 0) { + av_log(NULL, AV_LOG_FATAL, "Error processing forced keyframes\n"); + exit_program(1); + } + err = setup_sync_queues(mux, oc, o->shortest_buf_duration * AV_TIME_BASE); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error setting up output sync queues\n"); From patchwork Sat Nov 26 08:19:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39458 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013443pzb; Sat, 26 Nov 2022 00:20:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QuTQ5/G66wZsFlMlQ60fEkFpAHxBjXaVp3g62k94kMnNSoyKNckg8B0qL+Ejz53nb3cSL X-Received: by 2002:a17:906:3c04:b0:7ae:359a:965 with SMTP id h4-20020a1709063c0400b007ae359a0965mr19441137ejg.621.1669450848926; Sat, 26 Nov 2022 00:20:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450848; cv=none; d=google.com; s=arc-20160816; b=Dh9NYupSboNWwgb/Ucrcc/52iuuZdDhNeNgnIq5pEAajBGDk6GB3wQMINJ0QFyYnVD mGhhdZxcDjMVUZ7XPByZM4ZxMDjWG1YhAumeHKKiA6wOurceX0HEP4pB1Gu51lbEls0P h/YUZsEETxUsCqPb+YFdQJcD0VVmTEAgEDRKx6Phy3wBDrAIbiJ9nRAEmcSUeUjQ+6wU h0zEdyKK+lhQ0hkTIE50q47DtQRYy251tR4Al1l5cEpRdn4K0veC1xP1WJmvRjstEEIE Qa/xMEiloXEA6xUvr01w6y6U38YgtcP4lLBn04bUj6pJBpcjD2bVWSFHMxWmGfXsWhS4 8Wjw== 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=/BeETU9kb0BTlGkwOnQKad3aTAT271YabjJqsbj99dc=; b=yflRuU6HPzKdPKc9lQafjRcLAwUUOLtQvJx0OZd+j6rOs9DZ05JMJUpQjnCkFOaF+x 8CV92VWkP4bd7A7bszyNummIiMJ1n7pHgSS/Jz5FFpCschDWrm1P5dn5hBrrP5jaY+uZ ZWmAoNyXDK/LuMo3u5ZmjXVIqttLMi/lESw8rG+7eKQlBjpoT996TCpfgw/eY/QfsGYJ +ve8w6ECxXhFnjSAz37PxmdGn9GItpaTgIfYTHSopcaWy7luIGCcvo1yP+gcM+9IIJ7e 6uVB4yFKgNink7+yHLekOZ15QlGyllgPNtYdJfIFX9lcHEIQf43uL1FL3KEe3fd5vm4d P0vQ== 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 hs19-20020a1709073e9300b007ae743c61efsi6118579ejc.1002.2022.11.26.00.20.48; Sat, 26 Nov 2022 00:20:48 -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 13FBF68BA40; Sat, 26 Nov 2022 10:19:39 +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 0AE2568B8BE for ; Sat, 26 Nov 2022 10:19:30 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 2674A2406CA for ; Sat, 26 Nov 2022 09:19:27 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id NJCcaJQEBTwW for ; Sat, 26 Nov 2022 09:19:25 +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 A9B0A2405F9 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 792AA3A06F1 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:03 +0100 Message-Id: <20221126081911.31275-5-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 05/13] fftools/ffmpeg: avoid storing full forced keyframe spec 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: goEdvYisgyvz It is not needed after the spec is parsed. Also avoids ugly string comparisons for each video frame. --- fftools/ffmpeg.c | 7 ++----- fftools/ffmpeg.h | 7 ++++++- fftools/ffmpeg_mux.c | 1 - fftools/ffmpeg_mux_init.c | 35 ++++++++++++++++++++--------------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 12ce108cc6..44582e3568 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1067,13 +1067,10 @@ static enum AVPictureType forced_kf_apply(KeyframeForceCtx *kf, AVRational tb, kf->expr_const_values[FKF_N_FORCED] += 1; goto force_keyframe; } - } else if (kf->forced_keyframes && - !strncmp(kf->forced_keyframes, "source", 6) && + } else if (kf->type == KF_FORCE_SOURCE && in_picture->key_frame == 1 && !dup_idx) { goto force_keyframe; - } else if (kf->forced_keyframes && - !strncmp(kf->forced_keyframes, "source_no_drop", 14) && - !dup_idx) { + } else if (kf->type == KF_FORCE_SOURCE_NO_DROP && !dup_idx) { kf->dropped_keyframe = 0; if ((in_picture->key_frame == 1) || kf->dropped_keyframe) goto force_keyframe; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index bf2abf55ee..5527dbe49b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -487,8 +487,13 @@ typedef enum { MUXER_FINISHED = 2, } OSTFinished ; +enum { + KF_FORCE_SOURCE = 1, + KF_FORCE_SOURCE_NO_DROP = 2, +}; + typedef struct KeyframeForceCtx { - char *forced_keyframes; + int type; int64_t ref_pts; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index de5facbdc0..20524e5a28 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -667,7 +667,6 @@ static void ost_free(OutputStream **post) av_packet_free(&ost->pkt); av_dict_free(&ost->encoder_opts); - av_freep(&ost->kf.forced_keyframes); av_freep(&ost->kf.pts); av_expr_free(ost->kf.pexpr); diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 25e2ab8631..0280759b05 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -604,10 +604,6 @@ static OutputStream *new_video_stream(Muxer *mux, const OptionsContext *o, Input } } - MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->kf.forced_keyframes, oc, st); - if (ost->kf.forced_keyframes) - ost->kf.forced_keyframes = av_strdup(ost->kf.forced_keyframes); - MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st); ost->top_field_first = -1; @@ -1759,13 +1755,14 @@ static int compare_int64(const void *a, const void *b) return FFDIFFSIGN(*(const int64_t *)a, *(const int64_t *)b); } -static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux) +static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux, + const char *spec) { const char *p; int n = 1, i, size, index = 0; int64_t t, *pts; - for (p = kf->forced_keyframes; *p; p++) + for (p = spec; *p; p++) if (*p == ',') n++; size = n; @@ -1773,7 +1770,7 @@ static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux) if (!pts) report_and_exit(AVERROR(ENOMEM)); - p = kf->forced_keyframes; + p = spec; for (i = 0; i < n; i++) { char *next = strchr(p, ','); @@ -1812,20 +1809,24 @@ static void parse_forced_key_frames(KeyframeForceCtx *kf, const Muxer *mux) kf->pts = pts; } -static int process_forced_keyframes(Muxer *mux) +static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) { for (int i = 0; i < mux->of.nb_streams; i++) { OutputStream *ost = mux->of.streams[i]; + const char *forced_keyframes = NULL; + + MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_keyframes, mux->fc, ost->st); - if (!ost->kf.forced_keyframes) + if (!(ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && + ost->enc_ctx && forced_keyframes)) continue; - if (!strncmp(ost->kf.forced_keyframes, "expr:", 5)) { - int ret = av_expr_parse(&ost->kf.pexpr, ost->kf.forced_keyframes+5, + if (!strncmp(forced_keyframes, "expr:", 5)) { + int ret = av_expr_parse(&ost->kf.pexpr, forced_keyframes + 5, forced_keyframes_const_names, NULL, NULL, NULL, NULL, 0, NULL); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, - "Invalid force_key_frames expression '%s'\n", ost->kf.forced_keyframes+5); + "Invalid force_key_frames expression '%s'\n", forced_keyframes + 5); return ret; } ost->kf.expr_const_values[FKF_N] = 0; @@ -1835,8 +1836,12 @@ static int process_forced_keyframes(Muxer *mux) // 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, mux); + } else if (!strcmp(forced_keyframes, "source")) { + ost->kf.type = KF_FORCE_SOURCE; + } else if (!strcmp(forced_keyframes, "source_no_drop")) { + ost->kf.type = KF_FORCE_SOURCE_NO_DROP; + } else { + parse_forced_key_frames(&ost->kf, mux, forced_keyframes); } } @@ -2061,7 +2066,7 @@ int of_open(const OptionsContext *o, const char *filename) // parse forced keyframe specifications; // must be done after chapters are created - err = process_forced_keyframes(mux); + err = process_forced_keyframes(mux, o); if (err < 0) { av_log(NULL, AV_LOG_FATAL, "Error processing forced keyframes\n"); exit_program(1); From patchwork Sat Nov 26 08:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39452 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013128pzb; Sat, 26 Nov 2022 00:19:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf70SQ3YZlAVLwLqQhGZJshITAFHllIyxDnpB+1DOQlqGhTfd5gHER7PGjGFGNck5xL7cFK9 X-Received: by 2002:aa7:c3c9:0:b0:469:1342:2ad with SMTP id l9-20020aa7c3c9000000b00469134202admr28151144edr.180.1669450795757; Sat, 26 Nov 2022 00:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450795; cv=none; d=google.com; s=arc-20160816; b=OI+iV9bxcTDNqHHP5tgtOPOAS9pzXzKxK4laEMLnDmf0saJd5YgNy+sjYvv7RyV0LZ 13aOioyLqrX8o93YlmvIrIP7KpvD1o8twX9ggHE5fKTqKITF24CZFojBCMdTltTpVCB+ DQTfIuFQCgVSARY+DWrlaw7Y+zvR86Ksisc/jFQJPbgdJA5EX+C3sydA88ddch0IsGo6 koODBt7QAB2ruZl5WqO0v0W9vKDx8lMEHFYE1h9by1bUhUiXM/pTSBUVGwDCu20kB21r L8twugKovk1ebOgoEsWKpTdGqhf2Bi/Qnde+FzdBGeqfdsdccNP9xZd0fkWVwiDCTTz3 a51w== 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=BA9GB0EnVx9mAdHQW5ZQ5aSKmyaIxbasUByfJWOwPrU=; b=mS18VWPt8CEEfKXYuDe5bSubEHJpxEHP6yIff0euapM4rx2gQsTJ8LqhcFV+k9UWzq dxs4Lz/kFh1N4+1/6ZyeAGmyxUwuxP1zM1BHG+QHGfVUCPSfF4FG++0tSGgWLlA7zdix Z2SSHr6BnDnYj1/QMsZxKcDARRd7Mm2QaZrDR7L9NeJRZjaIRlvrMLk76IZ43HjOIXNR Ch+7L5M1evC0yf6XV3i+YKg1mpy14WE7uvSTOeVyQwwmRRhl6NAuOC46tfILO87YEIP4 uTQHYvVAUoeYIUMxHujyeDS2OkTCXKB+T4/UwjV5JilifaE+zEidBwCIVGdLk3dW6BVQ lcbw== 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 v25-20020a50d099000000b004637e16cfa4si4798483edd.599.2022.11.26.00.19.55; Sat, 26 Nov 2022 00:19:55 -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 703F668B5DA; Sat, 26 Nov 2022 10:19:33 +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 058FE68B48E for ; Sat, 26 Nov 2022 10:19:25 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BB77C240499 for ; Sat, 26 Nov 2022 09:19:24 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QLZ-GHE_6Xsb 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 95F5B2404F7 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 850373A0709 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:04 +0100 Message-Id: <20221126081911.31275-6-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 06/13] fftools/ffmpeg: move logging filtered frame timestamps 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: er9fblSq+9+K Do it right after the frame is received from the filtergraph. This is a more logical place for this and will simplify future commits. --- fftools/ffmpeg.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 44582e3568..263670d3f5 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -676,7 +676,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, AVFrame *frame) { double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision - int64_t orig_pts = AV_NOPTS_VALUE; AVCodecContext *enc = ost->enc_ctx; AVRational filter_tb = (AVRational){ -1, -1 }; if (!frame || frame->pts == AV_NOPTS_VALUE || @@ -690,7 +689,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, AVRational tb = enc->time_base; int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); filter_tb = av_buffersink_get_time_base(filter); - orig_pts = frame->pts; tb.den <<= extra_bits; float_pts = @@ -708,11 +706,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, early_exit: if (debug_ts) { - av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n", - frame ? av_ts2str(orig_pts) : "NULL", - frame ? av_ts2timestr(orig_pts, &filter_tb) : "NULL", - filter_tb.num, filter_tb.den); - av_log(NULL, AV_LOG_INFO, "filter -> pts:%s pts_time:%s exact:%f time_base:%d/%d\n", frame ? av_ts2str(frame->pts) : "NULL", (enc && frame) ? av_ts2timestr(frame->pts, &enc->time_base) : "NULL", @@ -1302,6 +1295,12 @@ static int reap_filters(int flush) AVRational tb = av_buffersink_get_time_base(filter); ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb, AV_TIME_BASE_Q); + + if (debug_ts) + av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n", + av_ts2str(filtered_frame->pts), + av_ts2timestr(filtered_frame->pts, &tb), + tb.num, tb.den); } switch (av_buffersink_get_type(filter)) { From patchwork Sat Nov 26 08:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39454 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013260pzb; Sat, 26 Nov 2022 00:20:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf6lPrL9eUAFVvno/Yf/wX9PPqw5PBJNQ7xteP9rxvu+ttXXBbVNqJjkIhpkA9fsNDiyOSFM X-Received: by 2002:a17:906:7f07:b0:7ad:b216:f1ce with SMTP id d7-20020a1709067f0700b007adb216f1cemr35170131ejr.419.1669450813505; Sat, 26 Nov 2022 00:20:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450813; cv=none; d=google.com; s=arc-20160816; b=aRW/1cTjZ+UM7BM++oEwQpA24NQQb8q+51TZdhnq/yIF5ZQvzS5SajKH+4N9M9MGZM P7RtYQTuhpqBoRxGz6kYmU7ka1IXYEAFMYvCxDgayS7jVh4/WcFreiE+YIB93dEyQYVv f0TQ65wuj9y9blkCKgVv07Svs5+UNpUyGjMaPrzpZGd3QFmoNIsc7EWiTu1WhD6myoqh cWw/w3EFhCY8AHS+fqvyK+bt5F1xyAFy4s3IQxLxcypLn+/hDED2nbPN4Pf7T66a5C3k I1BuIP0xUqUK7ZCXLk2d86Z+v9WOFFfJAEFPuP+60JLPSIEKAis9nFbjxDsbinOm3izN R5yg== 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=xpcnScGF6LN5/W0aHzegNTGZutsRYym61FIciw6vap4=; b=h8/3fea+NulOIBgx53UWnZ6UbgYZB4b7ZSNDJLXCyazwmc5lSNVzc+Y/pbr1OD0i3G fVB226kOHPJWRqQjYGSVHYxGBeqyO7dvclF/bM7IkZbNKFipUjVspyUAlXVqO9j9Tcsn FZSpV/ElQtnknvbsuT2AmpiCRuWLUdNq6cgdoexD++h2qfwaKWCod4UuEzBUHj69N2G2 v5jWxAPbP9utpd5UIvYhTx5xyPJloa+gf3rSKD6iZ7QtfX5msapUW15KRASAo13RZNZt t4a+I9yW60H4WdoBYApKZTNc9I8pmSoJ7TdV3QWNUBIWb3CsNNXM5fih5aiHCkAmkIUE TgRA== 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 gs12-20020a1709072d0c00b0078d78fbb88dsi3277649ejc.967.2022.11.26.00.20.13; Sat, 26 Nov 2022 00:20:13 -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 66E0368B8BE; Sat, 26 Nov 2022 10:19:35 +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 884F568B48E for ; Sat, 26 Nov 2022 10:19:25 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 47DC12404F8 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 6-EFpQSABrbp 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 A0B1C2405EC 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 9084F3A0CD6 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:05 +0100 Message-Id: <20221126081911.31275-7-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 07/13] fftools/ffmpeg: set AVFrame.time_base after filtering 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: 45AFbYjOg9mm Makes it easier to track what timebase are the frame timestamps in and allows to stop accessing filters in code that shouldn't deal with filtering. --- fftools/ffmpeg.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 263670d3f5..2ee40890a9 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -678,17 +678,14 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision AVCodecContext *enc = ost->enc_ctx; AVRational filter_tb = (AVRational){ -1, -1 }; - if (!frame || frame->pts == AV_NOPTS_VALUE || - !enc || !ost->filter || !ost->filter->graph->graph) + if (!frame || frame->pts == AV_NOPTS_VALUE || !enc) goto early_exit; { - AVFilterContext *filter = ost->filter->filter; - int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; AVRational tb = enc->time_base; int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); - filter_tb = av_buffersink_get_time_base(filter); + filter_tb = frame->time_base; tb.den <<= extra_bits; float_pts = @@ -701,6 +698,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, frame->pts = av_rescale_q(frame->pts, filter_tb, enc->time_base) - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); + frame->time_base = enc->time_base; } early_exit: @@ -1295,6 +1293,7 @@ static int reap_filters(int flush) AVRational tb = av_buffersink_get_time_base(filter); ost->last_filter_pts = av_rescale_q(filtered_frame->pts, tb, AV_TIME_BASE_Q); + filtered_frame->time_base = tb; if (debug_ts) av_log(NULL, AV_LOG_INFO, "filter_raw -> pts:%s pts_time:%s time_base:%d/%d\n", From patchwork Sat Nov 26 08:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39455 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013289pzb; Sat, 26 Nov 2022 00:20:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf7+XzUSAZhcSrDg6tF/KK00yyvhABTHqDRfvhkKVXaUSZmyzst0wFqKJ/a8e8rT1Rxrxq+s X-Received: by 2002:a05:6402:5510:b0:461:60e8:7ac3 with SMTP id fi16-20020a056402551000b0046160e87ac3mr22876818edb.80.1669450822803; Sat, 26 Nov 2022 00:20:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450822; cv=none; d=google.com; s=arc-20160816; b=Fq4NhfpzqK39qQq39StmqS3adcmxha3LRjMb9n3IVcZH6+sZOyj/9qbFlhGyrzFsNY smfiv2KPSvrLhiJ8w6qztKpXYv6DYs93L+lJzj9s3Jm1owMa6a03nM9AeCQbjzdxN9oZ AMpI5m+efeoO8IiVNwLwfLYrrOiQr7CFY10ESrMt0rpctCcpMExiPaPn/LsAw1r3Te1M iAWYQD9r8ylkPQdMmJg0o0R4QVrTK0/hw60jazJjDcOeZNv1xDm/aGXQTzSRCu9PV07o FFdJzxtlwH5Drrnesx1oxaXmzvAgIwhvevBMlewbq/9DiY7ZHKRObiA/VI2TxCNtkFjL RJGg== 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=8UFLo0hxLtt4kRzKQLYdiFXhik58IYkZC4q35RhN/Tg=; b=YSFr03Nt33XjQC6y16oMv58wBAck3H7PV4/8OBefSRial40Ww0VwGHKnE39Z1w+3Yf kgWd9XYzZnpgNz1WhhdoXfgrLHK/C5ubql09UEPOEwlY8fuXCepewddkZIuSogAMEB3j ZDSbQMtvf+02WFAE1LSIwfptth3vicgD3rdRW66B4AzY+57IKgTW2zmysxA3AGsXBtGF DkopfF+dva4scWwtc+KxaGszP9tA/u5PuzjbVmc3xlKxUITZBQqPlflzHUSW3rrQCo77 omyNFchVMKFdobGv9mknp8tOAYqwojToTY8jMvp7KtloHhtFXcMFNjyO3J/pU9lE1JYR LX8g== 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 s9-20020a056402164900b00461bff75d84si4684169edx.463.2022.11.26.00.20.22; Sat, 26 Nov 2022 00:20:22 -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 5A34A68B9DC; Sat, 26 Nov 2022 10:19:36 +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 EC3B868B83A for ; Sat, 26 Nov 2022 10:19:29 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 7468B240591 for ; Sat, 26 Nov 2022 09:19:26 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id WH6DX0M-S2iv for ; Sat, 26 Nov 2022 09:19:25 +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 AABF42406C7 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 9C3D33A0102 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:06 +0100 Message-Id: <20221126081911.31275-8-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 08/13] fftools/ffmpeg: stop calling adjust_frame_pts_to_encoder_tb() for audio 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: MTm+yCWwTSG8 Almost none of that function's complexity is useful for audio, it can be replaced by a simple av_rescale_q(). --- fftools/ffmpeg.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2ee40890a9..cb65f26100 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -933,15 +933,22 @@ static int submit_encode_frame(OutputFile *of, OutputStream *ost, static void do_audio_out(OutputFile *of, OutputStream *ost, AVFrame *frame) { + AVCodecContext *enc = ost->enc_ctx; int ret; - adjust_frame_pts_to_encoder_tb(of, ost, frame); - if (!check_recording_time(ost, ost->next_pts, ost->enc_ctx->time_base)) return; if (frame->pts == AV_NOPTS_VALUE) frame->pts = ost->next_pts; + else { + int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; + frame->pts = + av_rescale_q(frame->pts, frame->time_base, enc->time_base) - + av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); + } + frame->time_base = enc->time_base; + ost->next_pts = frame->pts + frame->nb_samples; ret = submit_encode_frame(of, ost, frame); From patchwork Sat Nov 26 08:19:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39457 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013393pzb; Sat, 26 Nov 2022 00:20:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7mojZ3gPLWkUZKem+tWiT9qNO2o7If6l6vJqTqSlM1FhEC4wikdi8pG1Eis+qxKdEVdb56 X-Received: by 2002:a17:906:f6c6:b0:78d:b367:20c1 with SMTP id jo6-20020a170906f6c600b0078db36720c1mr33730357ejb.530.1669450840942; Sat, 26 Nov 2022 00:20:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450840; cv=none; d=google.com; s=arc-20160816; b=cAoAYtTL4SUf3QurypIkoi1wFw37pOGqDiJtexn2Wq7ZBJvJE1fMMARLS4G7sreO+B sH3G45Fx23DaaaoVF51C7vzkZt0kJrq6T0zsss3S36LBE+c16LxcEMMaEIkgkhsdVj7u 1pctDObFHYbDj0DwQVlntz5HhROYyAozCDkzfUeNBAfRbsEKD+7rxM7KIpqmesPDSm4C CpSYaNVOo7eY8wvXsU/2uShBM4a+dJakbvwWSscyDqNC1iwddFkc+opxTPX7MfB1A1jX k+lS7KgrAK6qI2G6aFpPPa2syK3q7dr3i4fX7gAZiJeRqXD+E8FPN0/r6VMlE4WarzuU 2big== 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=f6Q5iqWYVhSKvScIhyYmYpn2iAaupm3VA6a7+YtKu78=; b=ZPCNyCNEkjojvysq3uSYTaVC40eJ23EbRJAbZg9KFOrlrBzhvRTTPtFMmKg7Cjymf0 f7Rb8i+hihdyTej0l4zrgIas4/5w9AQcVBKb98AjbXdeMh4hmBMgYbMjCex4MR3NGcYk vsB2mImWyXxTCcuEdHOI1mjfbk3KrF3pLwzmW7NWgoM+wqBlG7pkoGPllOcag9HTXiDu YeWzmC8heeuq8cTbLSArjAwEbl3FPk9V2oqhjXBSB/I5h9J43qmhicMLAZwIk71dBL85 Q/tqhFc0GgwPE3G9rFqTSiSBTsGnbvgEveqcThdYD+XF3BjHl/2kc1JMXLXy0LV/ZxVa rdGw== 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 t20-20020a170906179400b007ae86742c20si4013227eje.282.2022.11.26.00.20.40; Sat, 26 Nov 2022 00:20:40 -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 1438568BA06; Sat, 26 Nov 2022 10:19:38 +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 0331968B883 for ; Sat, 26 Nov 2022 10:19:29 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EE0CC2406C7 for ; Sat, 26 Nov 2022 09:19:26 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id eAtHhBjjU-qO for ; Sat, 26 Nov 2022 09:19:26 +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 B6A9A2406CA 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 A7F823A040A 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:07 +0100 Message-Id: <20221126081911.31275-9-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 09/13] fftools/ffmpeg: call check_recording_time() with actual frame pts 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: KAai/qHkRoO2 Not its estimated value that will not necessarily be used. --- fftools/ffmpeg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index cb65f26100..e56681a461 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -936,9 +936,6 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, AVCodecContext *enc = ost->enc_ctx; int ret; - if (!check_recording_time(ost, ost->next_pts, ost->enc_ctx->time_base)) - return; - if (frame->pts == AV_NOPTS_VALUE) frame->pts = ost->next_pts; else { @@ -949,6 +946,9 @@ static void do_audio_out(OutputFile *of, OutputStream *ost, } frame->time_base = enc->time_base; + if (!check_recording_time(ost, frame->pts, frame->time_base)) + return; + ost->next_pts = frame->pts + frame->nb_samples; ret = submit_encode_frame(of, ost, frame); From patchwork Sat Nov 26 08:19:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39459 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013496pzb; Sat, 26 Nov 2022 00:20:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf7dDcvo4eyxFYkjuGZ+TRWsbfaRIb/PW8+x6sJAVFSe8gtwCjgNMyi5WgdRh7tGrFy5hwDQ X-Received: by 2002:a50:fd0d:0:b0:469:c73c:e29a with SMTP id i13-20020a50fd0d000000b00469c73ce29amr24596833eds.423.1669450857059; Sat, 26 Nov 2022 00:20:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450857; cv=none; d=google.com; s=arc-20160816; b=qG8eSQomqr/A1os70DfauxKeOo5cASMu84XDe2Yjh4RqrqgnTpaj0/z4StZTEGy+bH ETI6FIAf+pJ+n7Xzd6p4LnNIf7orb1V6eQs9zBekU0fj4JtDRAkh/O/xGKZtQ4Bi2XQy GTcf5KvHvcaMIJX/K/+Sq8+mg2tRFM4jyjly8Lr6tx1vrJrcQWK8CUTBoEq71btca2Lc CeF0J7pLQoEuFgSzp8oUf0Yv8TqvFRv5pS6+o8QXdtDU/HonNYQgWf85bACVqDTdJLKy 2OJTE4ve1m7f0NYuQtX7Yn8LmoErc4iwVWrrsWWWBczgoNovVBj++Ifh8XwGNJ2Y1BVg nG6w== 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=CVuNYn0r596+QSPjkx+rv2OGRCBWUcRQNz8ataobEOc=; b=DbwfDkapnexm+3SjZIgrYDD2PqkIVcZFYBrvxYeDFI4Hg5wCFl8Bw+RoDkTOFypnV7 17pheFwG8E/eeYmAOGESNlCdhv2gGsMTkjTfRq+Smm4mfnUbeNyfMdbtoFT+OWPLVFiX +jC1eXRJV5fALgp+G9YU4ihOmV6e+OYe4KQOS14NkpSs4N+kVVFJYMw8dnb8lNsXpSt6 B2zbvdIj/n//njARNbO4Y8QUhJXhvLpXp7aetkhyRoZISREc7uQZWd0Er97pVKJD2sGy VST9evfXgE667XI3+Dgr4BJxsFBBKesR5m+Ono+/oxuNZDR7mADMghrK4pljz4hB6zgJ kQjA== 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 eb10-20020a0564020d0a00b00469c5cc855csi6212963edb.518.2022.11.26.00.20.56; Sat, 26 Nov 2022 00:20:57 -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 218B468BA6B; Sat, 26 Nov 2022 10:19:40 +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 764AE68B912 for ; Sat, 26 Nov 2022 10:19:30 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 72BF52405F9 for ; Sat, 26 Nov 2022 09:19:27 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QqAnijOcnFfy for ; Sat, 26 Nov 2022 09:19:27 +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 C11D02406CB 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 B33B03A0102 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:08 +0100 Message-Id: <20221126081911.31275-10-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 10/13] fftools/ffmpeg: only convert video frame pts if we have a 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: iPmTSuhv877O Calling adjust_frame_pts_to_encoder_tb() with a NULL frame does not perform a meaningful action. --- fftools/ffmpeg.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index e56681a461..8f27b5ca3f 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -678,7 +678,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision AVCodecContext *enc = ost->enc_ctx; AVRational filter_tb = (AVRational){ -1, -1 }; - if (!frame || frame->pts == AV_NOPTS_VALUE || !enc) + if (frame->pts == AV_NOPTS_VALUE || !enc) goto early_exit; { @@ -1092,12 +1092,10 @@ static void do_video_out(OutputFile *of, int64_t nb_frames, nb0_frames, i; double delta, delta0; double duration = 0; - double sync_ipts = AV_NOPTS_VALUE; InputStream *ist = ost->ist; AVFilterContext *filter = ost->filter->filter; init_output_stream_wrapper(ost, next_picture, 1); - sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture); frame_rate = av_buffersink_get_frame_rate(filter); if (frame_rate.num > 0 && frame_rate.den > 0) @@ -1121,6 +1119,7 @@ static void do_video_out(OutputFile *of, ost->last_nb0_frames[1], ost->last_nb0_frames[2]); } else { + double sync_ipts = adjust_frame_pts_to_encoder_tb(of, ost, next_picture); /* delta0 is the "drift" between the input frame (next_picture) and * where it would fall in the output. */ delta0 = sync_ipts - ost->next_pts; From patchwork Sat Nov 26 08:19:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39461 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013590pzb; Sat, 26 Nov 2022 00:21:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf5cn0pW3SJgAr8htdb8+WpxtoXaABY/aTbICs+hJiSV9ZAP70lu9ore4kmLsixZNph+WAeE X-Received: by 2002:a17:906:2810:b0:7b2:7b45:2bf6 with SMTP id r16-20020a170906281000b007b27b452bf6mr19551213ejc.467.1669450872516; Sat, 26 Nov 2022 00:21:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450872; cv=none; d=google.com; s=arc-20160816; b=HxMK1ox0Tsp4RbJi9BnPj7DvGmLHJHWsjJplMLPMVnK1n2gQEnmWf3qyZ1XyL/UDtT E+m21hmkCwrDJeqGyqC7wrOkLcRDgkMfRHU1/97Awrt+7BAa/iByVH8NAZP16WTk3K0p qm90TZfF1EMqz/JLBxU314Tikqifte3XGvHQLVARlRKhtcCEE5hLVk1bfHjhCyG8L5jt tTKizpSPzFeXEmPdWVnn3QhXsS7RV+R5t5vk15XRWJ0xY9SzhK5MLHs6poT1QC4FLzSW oO637mJC+YU1dJS8dLdXRDFF1L1rXNFdR1/+mCdCUctw4n+wPqtfGTPjQFa7K7md6iJK YjdQ== 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=OlwYQmKi4+mKNPI2fLZBP8VZfpU/s7vvIFckHtnSfDA=; b=D2Yh3wp2spRF7UDkg6LZwoqXIy7QnxxFjqDDhX+OfUx8QeEC40ezUQ1t4/oLAJbzwn IFXmK8XAgUJFtHZC9Q2LLW5Y4P70QXLpuj5KNtRUplrUfGZgd3ywH/O576CwS+O8i4MU nvk7jXvlnXJFsbB/Xe7G/qcNBPUyDlvx8zumAk0ydCmnT3So5JCnS81LcgtzhaHJ7cZw dcWg/DgnKor1y8Bd6IfFRExSGDsYmgYzrkk8awS60Lg1veST0dxxQytWXlIxOPKZB9ud E6sCNpNAj+3MigzBEAhqQ0AfPccJTBWEiUysi08nAE6lP2HAHw57zX4y8iB9iPXkRK8M BSvA== 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 z63-20020a509e45000000b0045c9904fdafsi5248716ede.74.2022.11.26.00.21.12; Sat, 26 Nov 2022 00:21:12 -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 2F56968BAC7; Sat, 26 Nov 2022 10:19:42 +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 82FD468B929 for ; Sat, 26 Nov 2022 10:19:30 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 296AD2406CD for ; Sat, 26 Nov 2022 09:19:28 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Dx4T3Y0bGC32 for ; Sat, 26 Nov 2022 09:19:27 +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 CC20B2406CC 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 BE6C73A05A8 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:09 +0100 Message-Id: <20221126081911.31275-11-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 11/13] fftools/ffmpeg: drop an always-false check 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: C1U7XMAISgL1 --- fftools/ffmpeg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 8f27b5ca3f..0128476f57 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -678,7 +678,7 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision AVCodecContext *enc = ost->enc_ctx; AVRational filter_tb = (AVRational){ -1, -1 }; - if (frame->pts == AV_NOPTS_VALUE || !enc) + if (frame->pts == AV_NOPTS_VALUE) goto early_exit; { From patchwork Sat Nov 26 08:19:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39460 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013548pzb; Sat, 26 Nov 2022 00:21:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4RG9dSGKui9hynOmmgwvkSRZYK2e73lh76TZ6S0s9LoXlbyczhn3Y9uTWL77VDzAWspnxd X-Received: by 2002:a05:6402:520a:b0:459:4c7b:e852 with SMTP id s10-20020a056402520a00b004594c7be852mr26782151edd.347.1669450864987; Sat, 26 Nov 2022 00:21:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450864; cv=none; d=google.com; s=arc-20160816; b=dQ8e5ZSIeLlelqaOTvlFTTHsod1Gy5L46RScAcTj+2hEoh0SancRxcPflIGVZXxrh1 eNLP71Oi7tSXGSTabK/YnXVRSvZ3OXdguzOVmecmdP1eagR34yB6YtYMis7flX8/Vylr 7qswVQbretkZpDu5OxoAsE7/5padPrIwl4vg3wxs8mYZSeD9JJZrLbnVQbNA8ARNpC34 W9FoArkE9Wzw/ZFUnsEXVLud85L9L1A6H6Jh2CoHxOGkH0ljjGz2PFnFrcybCmMUAMA5 5fVG58EcFjiY7gCdVT41lZibz/cXCSOcyC7Fff55xE4ovcaoT6+jFG/PDBK+QwDTaxjg fdAw== 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=RW/8+RW5pi74BJ7L/dF5yh1dPxsMXZzp+uyI6kBDIjQ=; b=CliCI0nChHyMoxbfb8v7qFqK4BTzIfj1AD0Ss8oDE9WQV4pyLThSTjFFyDaJ/5F4Za Y5RYVpmBqLwr4apWd7L5ZPaKuUBq66Hz7YaCbw0fshPbl+rKVsT2YhSkdNCKZMuVyHLV 0nLCSGoLaIYHNzx06DX6mv7CSSlm6YAhGczuXahMk0HYBJwM+6PVyV3/0DcbK7GDYDsM j9wIJcOa6F+WU7q6ou7ucw+XsYYKU4jaAAW3OUVsJKrJ1EoRT+PAGQamAe4w5XpGA9us 0niVUeO5g7yTPxrfnFaTd8EFka7rUsM4qYwBrkFg2cxFV273fnkn7gpFXrXCNYwCKYTT JFig== 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 z63-20020a509e45000000b004643d19e32esi5749284ede.618.2022.11.26.00.21.04; Sat, 26 Nov 2022 00:21: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 3F07068BA98; Sat, 26 Nov 2022 10:19:41 +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 7663768B914 for ; Sat, 26 Nov 2022 10:19:30 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 010582406CB for ; Sat, 26 Nov 2022 09:19:28 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id f0DD5kE0LTvh for ; Sat, 26 Nov 2022 09:19:27 +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 D6A252406CD 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 C91A53A0102 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:10 +0100 Message-Id: <20221126081911.31275-12-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 12/13] fftools/ffmpeg: remove a useless inner block 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: vkHZgebtKHO0 adjust_frame_pts_to_encoder_tb() is so small that this serves no useful purpose. --- fftools/ffmpeg.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 0128476f57..045cc609b9 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -676,17 +676,18 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, AVFrame *frame) { double float_pts = AV_NOPTS_VALUE; // this is identical to frame.pts but with higher precision - AVCodecContext *enc = ost->enc_ctx; - AVRational filter_tb = (AVRational){ -1, -1 }; + const int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? + 0 : of->start_time; + + AVCodecContext *const enc = ost->enc_ctx; + + AVRational tb = enc->time_base; + AVRational filter_tb = frame->time_base; + const int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); + if (frame->pts == AV_NOPTS_VALUE) goto early_exit; - { - int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; - AVRational tb = enc->time_base; - int extra_bits = av_clip(29 - av_log2(tb.den), 0, 16); - filter_tb = frame->time_base; - tb.den <<= extra_bits; float_pts = av_rescale_q(frame->pts, filter_tb, tb) - @@ -699,7 +700,6 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, av_rescale_q(frame->pts, filter_tb, enc->time_base) - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); frame->time_base = enc->time_base; - } early_exit: From patchwork Sat Nov 26 08:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39462 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6013648pzb; Sat, 26 Nov 2022 00:21:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf5tcW0B5Vn3rwt6DtWQBk5fA+MJU3/1grSeQE50IGp9zj8Ee/48Mw1vBwE8NtAOhA0YdFof X-Received: by 2002:a05:6402:4027:b0:468:fc39:e89 with SMTP id d39-20020a056402402700b00468fc390e89mr22356032eda.170.1669450880377; Sat, 26 Nov 2022 00:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669450880; cv=none; d=google.com; s=arc-20160816; b=wF4GITHxRXLfLnpt6vABM71Idm8tZQKrT3Eleym7l1M+fFAtuOzLmOR599bC7PGDhU vrnC98yLG5oiaL6TCa6WKv2ol+yNGTSMhQ8RGXkMNVGPFhsn69rmn7pmpYcVj/bgNtvS VDwhj7nq6BHOWsUhjNUih7hyQ/7GrvuuspqhARopiG1Nlar7GX7BccvJUDcfRFBQtld+ 85yfDKLQSIqYfZ9qTTiU8CmrwmFBurXNlBFj+Dq33tL+0xR8ToJxWkmS4CVxrNVLXCb/ AT/8EUkDx4BW/fWvCQ/4P/aOv+1vDEwCYDYl5m3FtzAbgZRmwJYwm5mAanhVVol2gcxO vY0g== 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=vBdQ7nv5lcxOn2qo4X7ZWkj420UhDj3stlkvRiqmOlY=; b=Nsm1YgZx5oYRibuxqmJJAm2cmn6ux4QlwxTeHR+7ELoiS3YxJj1tjgL9jbC3HfU9qT cqPIT7VXTJEH+zBj6NTt6zBz1Qsip4/ahFWsLTnXn1cFfp2lwcCxoOglTUbAV9BogZD3 3VQlqh4jRWXJ0pHaf2gUgfR24Ne/XXFcuQQ6hBvCHGAooCJRh2/lccqUOrve4Tqunwqn wRYhEtZqwHT/CA+dtK/wPrv2rB+ZLlviDOGrUDLifju4mY120g+6f/UV+Pbh8QyOCVxX TRSp5Unw/85cdYSBIuCu+SsCOyQq9PluzY8O1ibYy2eGm/Vgdyk2gyoYO4sCkWPocC8p lgzw== 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 k26-20020a056402049a00b0045d9a3adf48si5131741edv.591.2022.11.26.00.21.20; Sat, 26 Nov 2022 00:21:20 -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 3200768BA9D; Sat, 26 Nov 2022 10:19:43 +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 8702468B937 for ; Sat, 26 Nov 2022 10:19:30 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 80E5B2406CC for ; Sat, 26 Nov 2022 09:19:28 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id k08FB261PEOd for ; Sat, 26 Nov 2022 09:19:28 +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 E16D12406CE 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 D3E1C3A040A 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:11 +0100 Message-Id: <20221126081911.31275-13-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 13/13] fftools/ffmpeg: cosmetics 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: 0PRBWFNgwPSM Reindent after previous commit and break/split some lines as appropriate. --- fftools/ffmpeg.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 045cc609b9..771219f7df 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -688,18 +688,17 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, if (frame->pts == AV_NOPTS_VALUE) goto early_exit; - tb.den <<= extra_bits; - float_pts = - av_rescale_q(frame->pts, filter_tb, tb) - - av_rescale_q(start_time, AV_TIME_BASE_Q, tb); - float_pts /= 1 << extra_bits; - // avoid exact midoints to reduce the chance of rounding differences, this can be removed in case the fps code is changed to work with integers - float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); - - frame->pts = - av_rescale_q(frame->pts, filter_tb, enc->time_base) - - av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); - frame->time_base = enc->time_base; + tb.den <<= extra_bits; + float_pts = av_rescale_q(frame->pts, filter_tb, tb) - + av_rescale_q(start_time, AV_TIME_BASE_Q, tb); + float_pts /= 1 << extra_bits; + // avoid exact midoints to reduce the chance of rounding differences, this + // can be removed in case the fps code is changed to work with integers + float_pts += FFSIGN(float_pts) * 1.0 / (1<<17); + + frame->pts = av_rescale_q(frame->pts, filter_tb, enc->time_base) - + av_rescale_q(start_time, AV_TIME_BASE_Q, enc->time_base); + frame->time_base = enc->time_base; early_exit: