From patchwork Sat Dec 4 17:41:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31964 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp2275670iog; Sat, 4 Dec 2021 09:42:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyt7XTLDoRaVswEAhvhrishyJroAHjLGmrrN/3trIQQOrI+mF3rR4f1IA8c1CUVWxhLWB+i X-Received: by 2002:a05:6402:5194:: with SMTP id q20mr37143196edd.123.1638639739110; Sat, 04 Dec 2021 09:42:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638639739; cv=none; d=google.com; s=arc-20160816; b=q+LGueTK3oIO9yLzbcsjp6+dfn5Wyyy402ISoCBedladfKI+4mqPLGJ0jdp+/N0894 yRHQddtcrdO0mFAGvnDJHwXRXQTObjxwIyIk9FWRZ870MLDTE+8lbKrRDVpskPMp/J2b KbBARlxWo8FKbdSLJby6T6wcKkVcKc2yxSfxrkM6CVOMw4b8kd/u38atfJ7afiRh5xvb TtTKcXzFYegng9CStC56x2dP/YGJGFnCt49EeqriB6QT1p+COWkUE2LTcFrJ1E8jl+3D 691hSrf6wb4pexKh8IifEca6GlofyWe5zGkJGQok86ptDb8K6KWW6J/0WtEdHOC6cE/E kkvQ== 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=MDbN5T/BPZ7S16YLxl8xqw3D5i63RlgnoYZo99IKHn0=; b=iZ4T0/jxtakZDdAbYcTL+fXo9VReCq7XBrEhs/6/EjBf+KFmKdAUQkkLo5Z1dIfqdG K9/8hpTz+EtbMy1ps0MepT0JCVZyvKsUgdn/GI/RAcW40AUjDV1YukhA9NVgMD6pm/MQ ssTuvxeq2GGpeJvhT7T/gOlKnLKgmu6VgfjubfGyiK+Nk9VAC3uVYXMsWFr7ZYIc5oG1 0EZI3kjonIUhDzaq/xU21bEvMtmSdbl3Ch+VToK+ZtJaGYjPfCLQTMG+3APABlVvbqp8 6b8fqvOSy63tjCiZuy0mSRsxK8GVuPDeqp+BOVA0YmM5p19tFqKbLevDplxXPRdTxVCJ YLkg== 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 gs18si7946459ejc.679.2021.12.04.09.42.18; Sat, 04 Dec 2021 09:42:19 -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 E09C068AE7A; Sat, 4 Dec 2021 19:41:51 +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 29AF968A807 for ; Sat, 4 Dec 2021 19:41:44 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9A19F24017C for ; Sat, 4 Dec 2021 18:41:43 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Rwz5R2ed84T5 for ; Sat, 4 Dec 2021 18:41:43 +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 33B1124017E for ; Sat, 4 Dec 2021 18:41:41 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 3533A3A0746; Sat, 4 Dec 2021 18:41:41 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 4 Dec 2021 18:41:17 +0100 Message-Id: <20211204174118.19085-5-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211204174118.19085-1-anton@khirnov.net> References: <20211204174118.19085-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/6] ffmpeg: move setting video sync method to new_video_stream() 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: Zo5hhPp8m+74 do_video_out() is the wrong place for it, since the necessary information is already known when creating the stream and its value should never change. --- fftools/ffmpeg.c | 25 +++---------------------- fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index b1549a1096..1936367463 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1143,7 +1143,6 @@ static void do_video_out(OutputFile *of, AVFrame *next_picture) { int ret; - enum VideoSyncMethod format_video_sync; AVPacket *pkt = ost->pkt; AVCodecContext *enc = ost->enc_ctx; AVRational frame_rate; @@ -1190,28 +1189,10 @@ static void do_video_out(OutputFile *of, nb0_frames = 0; // tracks the number of times the PREVIOUS frame should be duplicated, mostly for variable framerate (VFR) nb_frames = 1; - format_video_sync = video_sync_method; - if (format_video_sync == VSYNC_AUTO) { - if(!strcmp(of->ctx->oformat->name, "avi")) { - format_video_sync = VSYNC_VFR; - } else - format_video_sync = (of->ctx->oformat->flags & AVFMT_VARIABLE_FPS) ? ((of->ctx->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR; - if ( ist - && format_video_sync == VSYNC_CFR - && input_files[ist->file_index]->ctx->nb_streams == 1 - && input_files[ist->file_index]->input_ts_offset == 0) { - format_video_sync = VSYNC_VSCFR; - } - if (format_video_sync == VSYNC_CFR && copy_ts) { - format_video_sync = VSYNC_VSCFR; - } - } - ost->is_cfr = (format_video_sync == VSYNC_CFR || format_video_sync == VSYNC_VSCFR); - if (delta0 < 0 && delta > 0 && - format_video_sync != VSYNC_PASSTHROUGH && - format_video_sync != VSYNC_DROP) { + ost->vsync_method != VSYNC_PASSTHROUGH && + ost->vsync_method != VSYNC_DROP) { if (delta0 < -0.6) { av_log(NULL, AV_LOG_VERBOSE, "Past duration %f too large\n", -delta0); } else @@ -1221,7 +1202,7 @@ static void do_video_out(OutputFile *of, delta0 = 0; } - switch (format_video_sync) { + switch (ost->vsync_method) { case VSYNC_VSCFR: if (ost->frame_number == 0 && delta0 >= 0.5) { av_log(NULL, AV_LOG_DEBUG, "Not duplicating %d initial frames\n", (int)lrintf(delta0)); diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 83e37cbed7..9b200b806a 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -485,6 +485,7 @@ typedef struct OutputStream { /* video only */ AVRational frame_rate; AVRational max_frame_rate; + enum VideoSyncMethod vsync_method; int is_cfr; int force_fps; int top_field_first; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a2a880e8e3..a7bf4c0c00 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1905,6 +1905,30 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->top_field_first = -1; MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st); + ost->vsync_method = video_sync_method; + if (ost->vsync_method == VSYNC_AUTO) { + if (!strcmp(oc->oformat->name, "avi")) { + ost->vsync_method = VSYNC_VFR; + } else { + ost->vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ? + ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ? + VSYNC_PASSTHROUGH : VSYNC_VFR) : + VSYNC_CFR; + } + + if (ost->source_index >= 0 && ost->vsync_method == VSYNC_CFR) { + const InputStream *ist = input_streams[ost->source_index]; + const InputFile *ifile = input_files[ist->file_index]; + + if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0) + ost->vsync_method = VSYNC_VSCFR; + } + + if (ost->vsync_method == VSYNC_CFR && copy_ts) { + ost->vsync_method = VSYNC_VSCFR; + } + } + ost->is_cfr = (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR); ost->avfilter = get_ost_filters(o, oc, ost); if (!ost->avfilter)