From patchwork Sun Jun 20 19:48:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thilo Borgmann X-Patchwork-Id: 28588 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2042:0:0:0:0 with SMTP id z2csp1318116iod; Sun, 20 Jun 2021 12:48:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+hswkZd8F5cMERFwShP/AW1cE2E78gGB5EqYLFq1/j3kK6fU7nGqLc+XqJ3qp3SiMSd1a X-Received: by 2002:a17:906:2752:: with SMTP id a18mr22026621ejd.458.1624218522430; Sun, 20 Jun 2021 12:48:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624218522; cv=none; d=google.com; s=arc-20160816; b=VQbz5Jp+1fPADJ/XM9JgPUKlKetezk3P/FuRdwqG8TTQ/NiChziergXMSaxsFuW41w N7wuNIwyBoIvqPFAb7uHeHXeMGJnI9vzGUi6VF8syF/e3/dGVHfxmUpAz0xTnVo5r7ZN /yAdPWRRVFpgLW927kKEcaImN3E0rjD1H5OipPaB13AWzcoZNU0hKQEIaOyovXiFSuN1 1+Ar//XVHaMHdKnU8CMB6NcR1XtZB1Ww+gr/UVqyjWA4s1N4Nwn6sSzJ+g50+bhJjO27 RIqH0Kq2aP1ilOWzTrXH5aq3tygDbZWppXWQCmuLgRpipz1QU6w+2PL4tLvkVyF4n1sc +pdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:date:message-id:from:to :dkim-signature:delivered-to; bh=bL15vAWslI+XoYA6XraFgDmX8JL2xWVfI7fnGhsO518=; b=byTEQLWAjczhd6+RxBBvLObRkKIq3/9KlDggx3RzWEX4Dl39bIWGHErs0Y0IEIO/Pq ftzZqIAc8oJv4DymYHXRK1bVo6IfqFZ9kelR6U62ba+Zk69RkmrkGxrZ7hc9KF38wwMS b2gHZyxlFPeYeMPPPCJ3p65HguyEQL0ukAFOXa++5aerOiH9I4AL0sDADr8ZVLT037Ar 484GruG5Iu/duGay2MyBctGjtZ8jDmrt5QcIuxMXQGRy7k/FU891NpliBrG4NV3Iwv7I 5pMGP3ekE67zAto9GBdPXPcekjm7oI6fcYBM0C9ahdzod1PgSngRhCkt3jT/dD/F2fk5 CupQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=2Qrbsy5W; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s1si14533560edw.441.2021.06.20.12.48.41; Sun, 20 Jun 2021 12:48:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mail.de header.s=mailde202009 header.b=2Qrbsy5W; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mail.de Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 30C67689CCC; Sun, 20 Jun 2021 22:48:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from shout02.mail.de (shout02.mail.de [62.201.172.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7DD7C6809A6 for ; Sun, 20 Jun 2021 22:48:30 +0300 (EEST) Received: from postfix01.mail.de (postfix01.bt.mail.de [10.0.121.125]) by shout02.mail.de (Postfix) with ESMTP id EDD76C0225 for ; Sun, 20 Jun 2021 21:48:29 +0200 (CEST) Received: from smtp04.mail.de (smtp04.bt.mail.de [10.0.121.214]) by postfix01.mail.de (Postfix) with ESMTP id D41E1801B6 for ; Sun, 20 Jun 2021 21:48:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.de; s=mailde202009; t=1624218509; bh=V7n40YCdSJdDEmwztkU1Li4IAijsc8+cNy6sW8JRuE0=; h=To:From:Subject:Date:From; b=2Qrbsy5W8wgZNhfycr1Nqo9VI7ghOUjCjyLmvvCEVbliVUljk25wMUaUBpt7O9oM7 eIZqlweFBJHPIuaOHDdM2TZat1fhwDfmrDwFLtyUDghAVWgFNEJgL9cX08lwEFWaoA lyb8j10OmQ9cesRw7NkLpwHjLkR57bAduyQwIH+wp4FAghXAim1ZuUCTPcpw9rxiKq vjeq8PuugFJIjTaZ17qDxG0P4utQdtzDAJMKq5E5ZWfKzgc6cetyALbx7bjU2b/NZk 6CJvpQ+X7ACuJ7bMT/vISzTxkDEw3rbVMTBFzSMSPjyOTB1ufekZI1bwGp0SeEgmME l23jEin5pIyWQ== Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtp04.mail.de (Postfix) with ESMTPSA id 9A295C0063 for ; Sun, 20 Jun 2021 21:48:29 +0200 (CEST) To: FFmpeg development discussions and patches From: Thilo Borgmann Message-ID: <39c63a4d-10c2-df1d-c5ce-eb3eb35525b9@mail.de> Date: Sun, 20 Jun 2021 21:48:29 +0200 MIME-Version: 1.0 Content-Language: de-DE X-purgate: clean X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate-type: clean X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-purgate-size: 4870 X-purgate-ID: 154282::1624218509-00006678-C47A9FC8/0/0 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: Add new variant source_no_drop to the force_key_frames option 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: hhhmX0NpAHHo Hi, adds a new variant to the -force_key_frames option "source_no_drop" to make sure whenever a key frame in the source is dropped, we choose the next frame in the output stream as a key frame. -Thilo From b37c854e7d48b538537b2c9c5e9651ba2ead3e52 Mon Sep 17 00:00:00 2001 From: Keyun Tong Date: Sun, 20 Jun 2021 21:42:29 +0200 Subject: [PATCH] fftools/ffmpeg: Add new variant source_no_drop to the force_key_frames option Suggested-By: ffmpeg@fb.com --- doc/ffmpeg.texi | 7 +++++++ fftools/ffmpeg.c | 6 ++++++ fftools/ffmpeg.h | 1 + 3 files changed, 14 insertions(+) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 9feabe6..ab98a5c 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -996,6 +996,7 @@ 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: @@ -1057,6 +1058,12 @@ starting from second 13: 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. + @end table Note that forcing too many keyframes is very harmful for the lookahead diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 04ddc9e..57c46e4 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1287,6 +1287,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; /* duplicates frame if needed */ for (i = 0; i < nb_frames; i++) { @@ -1347,6 +1348,11 @@ static void do_video_out(OutputFile *of, && in_picture->key_frame==1 && !i) { forced_keyframe = 1; + } else if ( ost->forced_keyframes + && !strncmp(ost->forced_keyframes, "source_no_drop", 6) + && !i) { + forced_keyframe = (in_picture->key_frame == 1) || ost->dropped_keyframe; + ost->dropped_keyframe = 0; } if (forced_keyframe) { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index e9d30fb..3cfb4c4 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -504,6 +504,7 @@ typedef struct OutputStream { char *forced_keyframes; AVExpr *forced_keyframes_pexpr; double forced_keyframes_expr_const_values[FKF_NB]; + int dropped_keyframe; /* audio only */ int *audio_channels_map; /* list of the channels id to pick from the source stream */