From patchwork Tue Oct 3 15:35:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 44122 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp2140806pzf; Tue, 3 Oct 2023 08:36:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGNelwxIGF+3qinQkxUrXrsbznIgU7lX+g7tZBJtLLaNDleLa/YzUTwIWvz3vFTwWYnAoJP X-Received: by 2002:a17:906:739b:b0:9ae:38d0:ef57 with SMTP id f27-20020a170906739b00b009ae38d0ef57mr13240501ejl.66.1696347414011; Tue, 03 Oct 2023 08:36:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696347413; cv=none; d=google.com; s=arc-20160816; b=iMNI1FoOlY0bx4ET3RH6tI5OmLT4KBD3T19kSekzpDVRoW6xKNWUuyzrgAznHBtrH6 sB7Mks6XWfD+y41y21X8iGAvNIeVTXWHjujLWhXw7aPGonlp8kdTA41kmeqLNV2GRT6I fJL4Y0YxAVn8VuIPDbA/fSgNT6pRgmzdHAdaffFxhjpC8knpbs/DvS6Fy8lwuTh+NSf9 g2TfdelJH8bHmNaMBOTnlODzFemMCgSbBalmLIeMkS1RwI/zvRBRFkYrpbWkcP1wpnNk e9bJ2pryNcBA4OSQKnT5RidlINvob1KnqrgMG8GMQ7De6sf2T9M5SpdKYrBV+NJ0fEbX tgGw== 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=OrYX6+Sxd5kfKi5psQ3v/Uny2ucFvxkvyIWxNeuYfl4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=D1lCE46MXd+ptjGLi+bpKV/VZdneMzw/LGn0dX6siiu4XObWrthJhHj1dgweSyXHNz sjcuBGOVHUSdgCQJYs5YiYDUv4lgX3g4F5PbBKW3oi/Gv3AyXIZvWCtDDQdO8kFAFelY t7XsIXugg5+JfGyoZhJBoMbYLwblUyrb3UpzlEw3tlHqkWUOoRcMjhJb8fdS7bhW/2G+ kA0xhTR1tIjIzRxq+/9oleRKw8SBJbO5IIgEjl6zYgb+XC7q9NyFJZOLikBExuhWw4e3 9MNcb8HZIXf7BAqItBK2wl8oBgeyb2/iGzHlW02vnUIYFxULdeyFwy3XYIVvD7F1IJy7 Awlw== 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 c20-20020a170906529400b0099318060d50si765715ejm.463.2023.10.03.08.36.53; Tue, 03 Oct 2023 08:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3DE4368CD3A; Tue, 3 Oct 2023 18:35:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3264568CB16 for ; Tue, 3 Oct 2023 18:35:47 +0300 (EEST) Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 1EE715296 for ; Tue, 3 Oct 2023 17:35:43 +0200 (CEST) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ejsyaNDrBdTV for ; Tue, 3 Oct 2023 17:35:42 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 416175292 for ; Tue, 3 Oct 2023 17:35:40 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3CEDB3A0772 for ; Tue, 3 Oct 2023 17:35:33 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Oct 2023 17:35:21 +0200 Message-Id: <20231003153526.19228-7-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231003153526.19228-1-anton@khirnov.net> References: <20231003153526.19228-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/12] fftools/ffmpeg_enc: merge -force_key_frames source/source_no_drop 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: ClQYVcDa4Xjz Always use the functionality of the latter, which makes more sense as it avoids losing keyframes due to vsync code dropping frames. Deprecate the 'source_no_drop' value, as it is now redundant. --- doc/ffmpeg.texi | 5 ----- fftools/ffmpeg.h | 3 +++ fftools/ffmpeg_enc.c | 5 +---- fftools/ffmpeg_mux_init.c | 6 +++++- tests/ref/fate/force_key_frames-source-drop | 22 ++++++++++----------- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index d2864ff37e..ea473e14e8 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -1060,7 +1060,6 @@ Deprecated see -bsf @item -force_key_frames[:@var{stream_specifier}] @var{time}[,@var{time}...] (@emph{output,per-stream}) @item -force_key_frames[:@var{stream_specifier}] expr:@var{expr} (@emph{output,per-stream}) @item -force_key_frames[:@var{stream_specifier}] source (@emph{output,per-stream}) -@item -force_key_frames[:@var{stream_specifier}] source_no_drop (@emph{output,per-stream}) @var{force_key_frames} can take arguments of the following form: @@ -1121,10 +1120,6 @@ starting from second 13: @item source If the argument is @code{source}, ffmpeg will force a key frame if the current frame being encoded is marked as a key frame in its source. - -@item source_no_drop -If the argument is @code{source_no_drop}, ffmpeg will force a key frame if -the current frame being encoded is marked as a key frame in its source. In cases where this particular source frame has to be dropped, enforce the next available frame to become a key frame instead. diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 2e8f1db9b6..eaa663e718 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -58,6 +58,7 @@ #define FFMPEG_OPT_ADRIFT_THRESHOLD 1 #define FFMPEG_OPT_ENC_TIME_BASE_NUM 1 #define FFMPEG_OPT_TOP 1 +#define FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP 1 enum VideoSyncMethod { VSYNC_AUTO = -1, @@ -484,7 +485,9 @@ typedef enum { enum { KF_FORCE_SOURCE = 1, +#if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP KF_FORCE_SOURCE_NO_DROP = 2, +#endif }; typedef struct KeyframeForceCtx { diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 42f64a4a49..b1cc60e350 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -1105,10 +1105,7 @@ static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, kf->expr_const_values[FKF_N_FORCED] += 1; goto force_keyframe; } - } else if (kf->type == KF_FORCE_SOURCE && - (in_picture->flags & AV_FRAME_FLAG_KEY) && !dup_idx) { - goto force_keyframe; - } else if (kf->type == KF_FORCE_SOURCE_NO_DROP && !dup_idx) { + } else if (kf->type == KF_FORCE_SOURCE && !dup_idx) { int dropped_keyframe = kf->dropped_keyframe; kf->dropped_keyframe = 0; if ((in_picture->flags & AV_FRAME_FLAG_KEY) || dropped_keyframe) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 9d6f442068..f35680e355 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2509,8 +2509,12 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) // parse it only for static kf timings } else if (!strcmp(forced_keyframes, "source")) { ost->kf.type = KF_FORCE_SOURCE; +#if FFMPEG_OPT_FORCE_KF_SOURCE_NO_DROP } else if (!strcmp(forced_keyframes, "source_no_drop")) { - ost->kf.type = KF_FORCE_SOURCE_NO_DROP; + av_log(ost, AV_LOG_WARNING, "The 'source_no_drop' value for " + "-force_key_frames is deprecated, use just 'source'\n"); + ost->kf.type = KF_FORCE_SOURCE; +#endif } else { int ret = parse_forced_key_frames(ost, &ost->kf, mux, forced_keyframes); if (ret < 0) diff --git a/tests/ref/fate/force_key_frames-source-drop b/tests/ref/fate/force_key_frames-source-drop index 99aa2ae826..220c0f0f88 100644 --- a/tests/ref/fate/force_key_frames-source-drop +++ b/tests/ref/fate/force_key_frames-source-drop @@ -9,14 +9,14 @@ 0, 2, 3, 1, 24, 0x589c06e0, F=0x0, S=1, 8 0, 3, 4, 1, 24, 0x4a700621, F=0x0, S=1, 8 0, 4, 5, 1, 24, 0x4f300661, F=0x0, S=1, 8 -0, 5, 6, 1, 24, 0x53f006a1, F=0x0, S=1, 8 -0, 6, 7, 1, 24, 0x58b006e1, F=0x0, S=1, 8 -0, 7, 8, 1, 24, 0x4a840622, F=0x0, S=1, 8 -0, 8, 9, 1, 24, 0x4f440662, F=0x0, S=1, 8 -0, 9, 10, 1, 24, 0x540406a2, F=0x0, S=1, 8 -0, 10, 11, 1, 24, 0x58c406e2, F=0x0, S=1, 8 -0, 11, 12, 1, 24, 0x4a980623, F=0x0, S=1, 8 -0, 12, 13, 1, 24, 0x4f580663, F=0x0, S=1, 8 -0, 13, 14, 1, 24, 0x541806a3, F=0x0, S=1, 8 -0, 14, 15, 1, 24, 0x58d806e3, F=0x0, S=1, 8 -0, 15, 16, 1, 24, 0x4aac0624, F=0x0, S=1, 8 +0, 5, 6, 1, 57, 0x7a110e90, S=1, 8 +0, 6, 7, 1, 24, 0x4f1c0660, F=0x0, S=1, 8 +0, 7, 8, 1, 24, 0x53dc06a0, F=0x0, S=1, 8 +0, 8, 9, 1, 24, 0x589c06e0, F=0x0, S=1, 8 +0, 9, 10, 1, 24, 0x4a700621, F=0x0, S=1, 8 +0, 10, 11, 1, 24, 0x4f300661, F=0x0, S=1, 8 +0, 11, 12, 1, 24, 0x53f006a1, F=0x0, S=1, 8 +0, 12, 13, 1, 24, 0x58b006e1, F=0x0, S=1, 8 +0, 13, 14, 1, 24, 0x4a840622, F=0x0, S=1, 8 +0, 14, 15, 1, 57, 0x88850f14, S=1, 8 +0, 15, 16, 1, 57, 0x7aa20e95, S=1, 8