From patchwork Wed May 31 14:54:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41910 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327425pzb; Wed, 31 May 2023 07:55:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58PKA2CTmF81T++BQMVuc1sO1IcQOwIkm5AiFrd/XAUq0TPoWU2HkV5AjoXg6nzrtY72Ee X-Received: by 2002:a05:6512:98b:b0:4f1:2f5d:8679 with SMTP id w11-20020a056512098b00b004f12f5d8679mr2386984lft.22.1685544948109; Wed, 31 May 2023 07:55:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544948; cv=none; d=google.com; s=arc-20160816; b=Bjwa5CTndU2Xb1hozjIJr3saic9+H8hV/OZsVQnAvWNZ8sT0nmhreNOSkXEHGJhqtp UuIof3y9kmgqR0wW4dhryoJpLa4phhEkMQ4yCJM6SqsPAjouMNL01q/OsK9Sg5JpO5z0 sAvwCzO8KGw60Km+RGXAyIE9eOSaB4BYln0Gn3fSU6P6tYMEJ8TGF0KO5ZY73k8MnZMh Ndf8/6g3iNodY4JnPQnkyo1sgC//itKQbwvT3hmwwgO4vgamHrxnVhWXwMjXdNJ7C42r K47TfQJQ9g+K5l99ujXby+h5IUNNIJWq/N8real8sIOWsZMAp+kS+1Gp8zrfWhBn1s/+ pqbA== 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=ZmhToMlpXPShv74qCdYF0DgaH6BeBUB44tn4nelommM=; b=vyZNTsCTyOlWZINF7oNL4oxaSiHok3YaFAjE3myn4wNsk+4YhHrV4/Grp6RP8iCJYn r+Xv+SDc1UG6J0OjaQcFEsdM14vRVn2AgmRnqA0nHisjxj5j+oUI1/sqm8IL+h8cu8W/ 7aw+OABKCj1ukG/0X9CWfmpHfI9Fsu5l9zwPfor98BbAPnp+YUNWwJrIApxqelOG/4No Wj4S3W0QAbFD3Oc9nndkQZNAjTrm2sUZbGge1HeT8BAw19BPD4Dk2vmtSB3IdQF9hhnq 9nYkNXuP7hrClTv6sjOZBeUfhiVXVTcVb3GoEd7R0IAmP3Z5pDXtrVaPnM5WA6nA04Sp hAhQ== 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 c8-20020aa7d608000000b0050c5241edc6si8155295edr.630.2023.05.31.07.55.47; Wed, 31 May 2023 07:55:48 -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 3E21B68C296; Wed, 31 May 2023 17:55:17 +0300 (EEST) 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 C780668C1CE for ; Wed, 31 May 2023 17:55:07 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9B5CE2404F5 for ; Wed, 31 May 2023 16:55:07 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 9ckN26hOGBMR for ; Wed, 31 May 2023 16:55:05 +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 mail0.khirnov.net (Postfix) with ESMTPS id 52A26240177 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C92943A0139 for ; Wed, 31 May 2023 16:54:59 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:31 +0200 Message-Id: <20230531145453.20994-1-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream 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: /QSuHpIAocfD --- The patchset is also available from branch 'ffmpeg_enc_tb' in git://git.khirnov.net/libav --- fftools/ffmpeg.c | 6 ++++-- fftools/ffmpeg.h | 6 +++--- fftools/ffmpeg_enc.c | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 36b4becaf2..bcda7570e9 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -119,8 +119,6 @@ typedef struct BenchmarkTimeStamps { static BenchmarkTimeStamps get_benchmark_time_stamps(void); static int64_t getmaxrss(void); -int64_t nb_frames_dup = 0; -int64_t nb_frames_drop = 0; unsigned nb_output_dumped = 0; static BenchmarkTimeStamps current_time; @@ -491,6 +489,7 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti int64_t pts = INT64_MIN + 1; static int64_t last_time = -1; static int first_report = 1; + uint64_t nb_frames_dup = 0, nb_frames_drop = 0; int hours, mins, secs, us; const char *hours_sign; int ret; @@ -536,6 +535,9 @@ static void print_report(int is_last_report, int64_t timer_start, int64_t cur_ti if (is_last_report) av_bprintf(&buf, "L"); + nb_frames_dup = ost->nb_frames_dup; + nb_frames_drop = ost->nb_frames_drop; + vid = 1; } /* compute min output value */ diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 966397270d..cef4b5d000 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -553,6 +553,9 @@ typedef struct OutputStream { Encoder *enc; AVCodecContext *enc_ctx; AVPacket *pkt; + + uint64_t nb_frames_dup; + uint64_t nb_frames_drop; int64_t last_dropped; /* video only */ @@ -707,9 +710,6 @@ extern int recast_media; extern FILE *vstats_file; -extern int64_t nb_frames_dup; -extern int64_t nb_frames_drop; - #if FFMPEG_OPT_PSNR extern int do_psnr; #endif diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 6c9cce252f..f3e291a9e4 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -1078,7 +1078,7 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) &nb_frames, &nb_frames_prev); if (nb_frames_prev == 0 && ost->last_dropped) { - nb_frames_drop++; + ost->nb_frames_drop++; av_log(ost, AV_LOG_VERBOSE, "*** dropping frame %"PRId64" at ts %"PRId64"\n", e->vsync_frame_number, e->last_frame->pts); @@ -1086,12 +1086,12 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) if (nb_frames > (nb_frames_prev && ost->last_dropped) + (nb_frames > nb_frames_prev)) { if (nb_frames > dts_error_threshold * 30) { av_log(ost, AV_LOG_ERROR, "%"PRId64" frame duplication too large, skipping\n", nb_frames - 1); - nb_frames_drop++; + ost->nb_frames_drop++; return; } - nb_frames_dup += nb_frames - (nb_frames_prev && ost->last_dropped) - (nb_frames > nb_frames_prev); + ost->nb_frames_dup += nb_frames - (nb_frames_prev && ost->last_dropped) - (nb_frames > nb_frames_prev); av_log(ost, AV_LOG_VERBOSE, "*** %"PRId64" dup!\n", nb_frames - 1); - if (nb_frames_dup > dup_warning) { + if (ost->nb_frames_dup > dup_warning) { av_log(ost, AV_LOG_WARNING, "More than %"PRIu64" frames duplicated\n", dup_warning); dup_warning *= 10; } From patchwork Wed May 31 14:54:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41919 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328244pzb; Wed, 31 May 2023 07:57:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cnY3VrR7zVa1XuW5q+l0bLPODfKJQGtw1zuv75iVz0UJrZjbLmRGnVkRBTKawpZH9iNSq X-Received: by 2002:a17:907:c09:b0:96a:649b:3972 with SMTP id ga9-20020a1709070c0900b0096a649b3972mr5887107ejc.0.1685545027925; Wed, 31 May 2023 07:57:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545027; cv=none; d=google.com; s=arc-20160816; b=gpWuzrkivUlV27pHYwXuOsVeFyUc8FyMMPSl6/Q0pOAuTE38DR5TK0JP7BVpg1mS2+ jaWXn+ITLJXew5OaFJ6ccr5M9IKuFzlVsXyu4rSXUxP69gQUWdIe7ad13/0ANEqfBS5U l1zRR8I9flK+6nBB0qXAmEgMkxWsWvejUyk49wiwt75RpCWWPgIYBuJbL6zWY3gnx+jH KA58lOfLm4GLF7+opkmZ/gPLY3yesLyPcmWi7CY/Q8T6ZP0/8MJqyjl4WphAM9I8msFr wWhyuBR6oU5AnrjJlmX0TGkCuYjAYtK+xj4jAfcHv1iRQByMePkS7m++RGf7bXMORlPN LXwA== 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=FS47k671esm9sOid63hXFJ8+RtMsFqW26botnh9RXWc=; b=hFs8QYPAyMjV9+PBz8Nf6RWW/IWZjO4aqA6YGb8NniQk0J8u4JARlNxsgNs30pkWJJ IN15xuIdkF0FHWNa4b409uJ9ffUCQ0yBnnDkijZZbs0pUiIocrGlVrR6WuS3XNe23ASH nHnV6i6BGtVuJosUtBr52ftAXBCqCrpinfgZi3+/2faDKWEZmuquhxz14Q2w/7f2aZxU eSkRL5An0pr8QnKUtRVFtoI4IiT5zsHjhL5p1fcvOGO4mpFPXQRCSoo3r0nskCKRdl7x 30BfqUVwBJGzcwWusN/YLwdI9S4KWNHANJudAG4LQ+5BG7J9lYA6lrq+mt7Zyl4RT8NZ V9ig== 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 i12-20020a170906264c00b00965cab180bbsi7140976ejc.520.2023.05.31.07.57.07; Wed, 31 May 2023 07:57:07 -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 41D0768C288; Wed, 31 May 2023 17:55:26 +0300 (EEST) 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 67EA068C25A for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id F24B32406CF for ; Wed, 31 May 2023 16:55:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ecUD2DeJO8Bc for ; Wed, 31 May 2023 16:55:11 +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 mail0.khirnov.net (Postfix) with ESMTPS id 288AC2404EC for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D5A0F3A03F3 for ; Wed, 31 May 2023 16:54:59 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:32 +0200 Message-Id: <20230531145453.20994-2-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/23] fftools/ffmpeg_mux: set stream duration after the timebase is certainly known 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: tFKgRb3J2kNB Stop assuming the encoder knows the muxing timebase, which does not always have to hold (e.g. due to bitstream filters). --- fftools/ffmpeg_enc.c | 4 ---- fftools/ffmpeg_mux.c | 5 +++++ fftools/ffmpeg_mux.h | 3 +++ fftools/ffmpeg_mux_init.c | 10 ++++++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f3e291a9e4..fab71ca0c0 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -445,10 +445,6 @@ int enc_open(OutputStream *ost, AVFrame *frame) if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 1}); - // copy estimated duration as a hint to the muxer - if (ost->st->duration <= 0 && ist && ist->st->duration > 0) - ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - ost->mux_timebase = enc_ctx->time_base; ret = of_stream_init(of, ost); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index feb014ca31..121796a55a 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -666,6 +666,11 @@ int of_stream_init(OutputFile *of, OutputStream *ost) if (ret < 0) return ret; + if (ms->stream_duration) { + ost->st->duration = av_rescale_q(ms->stream_duration, ms->stream_duration_tb, + ost->st->time_base); + } + ost->initialized = 1; return mux_check_init(mux); diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index 7e0454dfba..bee7addd6a 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -69,6 +69,9 @@ typedef struct MuxStream { * used for making up missing dts values */ int64_t last_mux_dts; + int64_t stream_duration; + AVRational stream_duration_tb; + // audio streamcopy - state for av_rescale_delta() int64_t ts_rescale_delta_last; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 4fc6f0fb46..33c93e40f2 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -914,10 +914,6 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost) ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); } - // copy estimated duration as a hint to the muxer - if (ost->st->duration <= 0 && ist->st->duration > 0) - ost->st->duration = av_rescale_q(ist->st->duration, ist->st->time_base, ost->st->time_base); - if (!ms->copy_prior_start) { ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ? 0 : mux->of.start_time; @@ -1283,6 +1279,12 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, exit_program(1); } + // copy estimated duration as a hint to the muxer + if (ost->ist && ost->ist->st->duration > 0) { + ms->stream_duration = ist->st->duration; + ms->stream_duration_tb = ist->st->time_base; + } + return ost; } From patchwork Wed May 31 14:54:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41918 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328147pzb; Wed, 31 May 2023 07:56:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Ie46b3TUvCk7VToufeWCIAYO11FWKdEaGifwkqP6YW33kjTCGdZLw/Zr/OJbX3xzyeURZ X-Received: by 2002:a17:907:360d:b0:94e:8559:b5c5 with SMTP id bk13-20020a170907360d00b0094e8559b5c5mr5506354ejc.64.1685545018878; Wed, 31 May 2023 07:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545018; cv=none; d=google.com; s=arc-20160816; b=sS7oDFmQzTbssjU5BLa+O5KBtvyugYjRAjZ/JA5yr7/obLh4f8xo7hWdmXayvDU93U cZavHq4oEwLebLpIsSSMZB8MiM3iyY1quu53QNoTXJupJF/BKVSqospzQ2X3dpWkuBZe DTN4DUYTHmSsIfwF3hbceZY/Q/duR8HSfwPbbnnRywEiXjwuF6uiZAd8Wat6cdgdHRiG cT6X04l1UOjtYYsUtAs6MVPS82/BmyNhENmiKyhaPZGm/JtPS1t5mya8OJ3bcD40FWY/ jEUiv+fdS8HFH9xWNV4YCfuyKoKs2nirP8xy2DEMuqJTVwLmRLIAUybU/pxroCgywSh7 aRbw== 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=8TYiWhzYotoCAh2dL458Zx6PAHwN0pu1La5B2ocKgw0=; b=hn3Dz9BORKMTZuE9TQLnXSM7SGpOjAiBwRfMNqfe0fb5IgjZtEQU7LsT8Qahi3Zc37 3dDdb/cz5/wCdimK3c4T0WvmN7Wgk3bNAAWlFc4lRoLOeYFS9SFP9SY7OYKvemY8+5H4 uKDTJtXSmOXwIiQTpZ8tn+NuH01YFfDtN0MwwH5DQTi6oX13rOP4qJRrbkKMLuhXxnB3 qaj6XRfV47GOMkPQVYIem9kxTX+0J+H77ngXI5Wm3ee7NF1aLqnXHiKq9yFFrmmaTXKE dzcRxn9uftDHTS74ot6JbOu4CwysipTbLyn5ReFvPaV1q/Yb3YKzYVR8bamy9uEDz+lw bwyw== 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 w19-20020a1709067c9300b00961aff9c3bcsi643473ejo.680.2023.05.31.07.56.58; Wed, 31 May 2023 07:56:58 -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 4A1F268C2ED; Wed, 31 May 2023 17:55:25 +0300 (EEST) 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 676C268C255 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 32A4A2404EC for ; Wed, 31 May 2023 16:55:12 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 0ROR8rkoU7uu for ; Wed, 31 May 2023 16:55:11 +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 mail0.khirnov.net (Postfix) with ESMTPS id 309BB240D03 for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E0C753A04D0 for ; Wed, 31 May 2023 16:54:59 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:33 +0200 Message-Id: <20230531145453.20994-3-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/23] fftools/ffmpeg_filter: drop a write-only variable 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: SvHbeDKHyT+q --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_filter.c | 1 - 2 files changed, 2 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index cef4b5d000..0e9ad5f9f7 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -296,7 +296,6 @@ typedef struct OutputFilter { /* desired output stream properties */ int width, height; - AVRational frame_rate; int format; int sample_rate; AVChannelLayout ch_layout; diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index c3075ef854..287b1e6f9d 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -654,7 +654,6 @@ void ofilter_bind_ost(OutputFilter *ofilter, OutputStream *ost) switch (ost->enc_ctx->codec_type) { case AVMEDIA_TYPE_VIDEO: - ofilter->frame_rate = ost->frame_rate; ofilter->width = ost->enc_ctx->width; ofilter->height = ost->enc_ctx->height; if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) { From patchwork Wed May 31 14:54:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41928 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3329018pzb; Wed, 31 May 2023 07:58:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7JBlnLrBc6xUb7acc32dVtDswcViflXDxzCNaS0AlOsSHfz1zzUOuMMmFZbhOCKtnqO4Dl X-Received: by 2002:a17:907:94cf:b0:96f:a39c:86d6 with SMTP id dn15-20020a17090794cf00b0096fa39c86d6mr5353845ejc.8.1685545106559; Wed, 31 May 2023 07:58:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545106; cv=none; d=google.com; s=arc-20160816; b=iQC4MFAzHlvhyWfqzVN3iQ+YefxEMdcfRwQh6cLo7h74Ry3nO4BMujjjXJUx1wWknh EfGGU4p8DkRdI5oKlbJasNliJr/wAinCTfwNuvZTH/YkFcmoOD7H4rfqfanQE2dQ8XYl u1o4z8y6zjgZbtfRGIocpayIxoTrBGD8aZPjj29maDxUWTHRFQltnIYOo9yTQxwcQ7wY d232FHtiYOlYW39W7H3Pu+L/vlJn14aUzn0q0y5ZxYScmGrKzOl9NM4u5oW68N4MN5eU JdrlLgAGNeWjDMF5rGF2jMESQt5/j0FYGtzVA1e9nSfvvtJGi+91OSdyneidMUXklQW9 L1nw== 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=2DDUUmAjGSQFm2g/e7WzP6le34ib0R6ZoICkYz2yiKA=; b=J2EK35zs6nNT3GaCkoQqdn/2e+KhyvhLOlB8rIL6d840zmsv4QpUMgCORoY+4GnQAw FIj60qhBMFXNiVFSxJiO2u7zsFZkAbdfS3huBQBaOJJFDBivubxLroaWkz+1W4X1bYS/ BDsG0s275tBqbuqLkWv0N+o8r795LWOZ6dM1rJqqqr1jP0HyWeF/YVaaRcFvaaUGd6qF jZ4wZQ4CbyO2SIqulv4jThsxr91hvXl2w2JhizeRLTN4gRB6a7XIONt1RE4kuOFBB4/n S9+XNCBAHUSQHzdB83POHr4r2zm2sZob29rd8N2cxhtTPBQ2XRzk2W+eiwsQj5XejF7d z7mQ== 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 fc10-20020a1709073a4a00b00965a46dd290si10104741ejc.199.2023.05.31.07.58.26; Wed, 31 May 2023 07:58:26 -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 CBFA468C31B; Wed, 31 May 2023 17:55:34 +0300 (EEST) 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 8154B68C288 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 9F94A2404EE for ; Wed, 31 May 2023 16:55:12 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id a9bZs1JoPrYP for ; Wed, 31 May 2023 16:55:12 +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 mail0.khirnov.net (Postfix) with ESMTPS id 36A74240D1A for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id EC5B53A0570 for ; Wed, 31 May 2023 16:54:59 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:34 +0200 Message-Id: <20230531145453.20994-4-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/23] fftools/ffmpeg_filter: drop a block disabled since 2012 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: TIeFNHzTczRl --- fftools/ffmpeg_filter.c | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 287b1e6f9d..1150f6fc65 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1075,26 +1075,6 @@ static int configure_output_video_filter(FilterGraph *fg, OutputFilter *ofilter, pad_idx = 0; } - if (ost->frame_rate.num && 0) { - AVFilterContext *fps; - char args[255]; - - snprintf(args, sizeof(args), "fps=%d/%d", ost->frame_rate.num, - ost->frame_rate.den); - snprintf(name, sizeof(name), "fps_out_%d_%d", - ost->file_index, ost->index); - ret = avfilter_graph_create_filter(&fps, avfilter_get_by_name("fps"), - name, args, NULL, fg->graph); - if (ret < 0) - return ret; - - ret = avfilter_link(last_filter, pad_idx, fps, 0); - if (ret < 0) - return ret; - last_filter = fps; - pad_idx = 0; - } - snprintf(name, sizeof(name), "trim_out_%d_%d", ost->file_index, ost->index); ret = insert_trim(of->start_time, of->recording_time, From patchwork Wed May 31 14:54:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41926 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328838pzb; Wed, 31 May 2023 07:58:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55ylemrcdXNjXh/wlnNqgiB3g/q8ZD8UbozP42563VND/xskwl03xrqqEk6UAUUEcZqEXe X-Received: by 2002:a05:6512:21aa:b0:4f3:8223:eb81 with SMTP id c10-20020a05651221aa00b004f38223eb81mr2559259lft.6.1685545088769; Wed, 31 May 2023 07:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545088; cv=none; d=google.com; s=arc-20160816; b=Y/2JEtiyCSt0MTTTkRyKi+nZ5BhjELkqigwXHHFcElpKPGCSKLYBwZdP9i8bLVld19 /AYmznHt3IErTbOTGlwSm6nQRcbC01FmMKzXZ6Fdj1enUAsi7uXESFLsRQ3nWM1/xD7Y e52zFIE0PamEF84djWJC9r88G4QH/+GtDVwwD7WE7q5FyWbft5vSkE6+5S7xcftFNOXr 9DstA+NxGaZxxvnChzwsvGXgZpeOBJvdU2Kf3xw7NWGN/Nc5sySASbZ+Cf6/81y4mQmK Bom6vyfN4tZuDsr7B9nKk31Kmv7FkJKp7GxvAok8rCSPWi281rU6UALWf7oDfOE2NKNC +PCg== 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=LtHQCNKzjFBcxTpjdYt6bAHxct2PPzovToWPCaulFJk=; b=x8xa4xC+gRpAG1YJH6frngqfC8pz799qLBT+C+7KO+I3KLdTS+WwKqUEK4QxJmtq5B C+Umt/u0Hukn6RFZvWFtoIpHosqt7GyI02/7MefFpssvusGPFktHEfqBavcs20GV6fpy fR6XXUg+be45LLTeCKUonI4+Vcljstpb4O/vxYaRI+bhT57CWExBTFQdZ1Gbwfqhw0wA SerO4OXRAk9NljKoAmGRsAqWJV7zN4+FLBBrof7WnACOiGAMsmMzcaWLaZJyUi6WMbkd UoSO4EkNPn5GlQYsj8NV+ao3LRCAcuTOKez7GYDx0C/4ijWRVGfTF4x0i+JNpOaEJGv/ GmDg== 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 f5-20020a056402150500b00514b2458135si2593498edw.284.2023.05.31.07.58.08; Wed, 31 May 2023 07:58:08 -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 EE7AE68C312; Wed, 31 May 2023 17:55:32 +0300 (EEST) 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 72D5C68C2B2 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6DC9F240706 for ; Wed, 31 May 2023 16:55:12 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id R6LXRymLgtmy for ; Wed, 31 May 2023 16:55:12 +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 mail0.khirnov.net (Postfix) with ESMTPS id 38491240D1B for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 02EAD3A0586 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:35 +0200 Message-Id: <20230531145453.20994-5-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/23] fftools/ffmpeg_demux: do not set AVCodecContext.framerate 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: tP4fqxJ6eKPP For decoding, this field is used by the decoder to export information to the caller; it does not make sense for the caller to set it. --- fftools/ffmpeg_demux.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 5c15b8bad3..5e5f106368 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1194,9 +1194,6 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d) switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: - // avformat_find_stream_info() doesn't set this for us anymore. - ist->dec_ctx->framerate = st->avg_frame_rate; - MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st); if (framerate && av_parse_video_rate(&ist->framerate, framerate) < 0) { From patchwork Wed May 31 14:54:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41907 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327143pzb; Wed, 31 May 2023 07:55:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7nibN0naNHDTx+EgODyZnwwLqWPwgHzAhvGhxPtDMWO8rAxS26XTaf5SWaSqx16s2V9xEO X-Received: by 2002:a17:907:7f8d:b0:96b:6fb:38d6 with SMTP id qk13-20020a1709077f8d00b0096b06fb38d6mr6074033ejc.65.1685544918484; Wed, 31 May 2023 07:55:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544918; cv=none; d=google.com; s=arc-20160816; b=DLj1cGtJ4+/DsVa3WLmlXnlxPpQCm9XSpf8GuKtfMPhd8jAsf3BUS3RpwDuqjX1Qwp CbWBYZL3G9UBgDeBInKX28Gj9OmBDb46A8+hsVZZbrzGkCjAVPOObcyuTAH9oajjyLJj NkLA3uC91EpcY9jU4iSwFJNS/QmYDy9vcSpcOyG43K4c32GzhgDdt431x7cEr6Y9ddo5 MFnWmGazkq2w8WRrXNW1Laj6oh2IuT5YaUqQhfRR/XVtmpolZ+z+HhVLbel5ftb7KzPO JWyhbAA1TlUfPHHG1lVKq3veJJNBvFmEqW6TjMKF2jR1XV/Hm/Kw/RCNTokSBbkEo25d cN7Q== 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=GPtjv75PqUAEBkXPt8eiiKHnUBSnTxes6Q4EoeNkhmA=; b=tXk0mS+X3nhUe19pVbkHrvqG7tjA6BuProHOeHa4dWkz6bDIWTQjTsAHEjGpDJ9Whv fN8sMhyH6nuUMDjxNPLSrsI5k9fpIt7qI2taZVl+16SkS/YXTi2vYhdauYfQxGsop1JK Umf+hLBrSfK0PUExLcDq1LCs8IoXz48N+boJuClHzDXrjCGgJfZ0cY1NlgI7/8eTfb4j QAKSOJ10ZOjfxerlkP0og76lLl12wU96yNIx/nBiTKyrO8p80sOsQpNc4/7GRhar5f2L AtBXN4Qd8isOojTraoo8uKIuEeh49dDZ4hB51GNCNgwOTCGwF5IymNeR15qjfUHSDSyT tHRg== 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 qt20-20020a170906ecf400b0096b06ea4e84si5064264ejb.702.2023.05.31.07.55.17; Wed, 31 May 2023 07:55:18 -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 0C26868C260; Wed, 31 May 2023 17:55:14 +0300 (EEST) 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 DCCB968B649 for ; Wed, 31 May 2023 17:55:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1F0CE240706 for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id XSand4GjI_Au for ; Wed, 31 May 2023 16:55:05 +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 mail0.khirnov.net (Postfix) with ESMTPS id 6EA8E2404EC for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0E10C3A058B for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:36 +0200 Message-Id: <20230531145453.20994-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/23] fftools/ffmpeg_enc: avoid breaking exactly integer timestamps in vsync code 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: unYcK5MhEUr3 The code will currently add a small offset to avoid exact midpoints, but this can cause inexact results when a float timestamp is exactly representable as an integer. Fixes off-by-one in the first frame duration in multiple FATE tests. --- fftools/ffmpeg_enc.c | 6 ++++-- tests/ref/fate/apng-osample | 2 +- tests/ref/fate/film-cvid | 2 +- tests/ref/fate/filter-concat-vfr | 2 +- tests/ref/fate/gif-gray | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index fab71ca0c0..d390e384ed 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -888,9 +888,11 @@ static double adjust_frame_pts_to_encoder_tb(OutputFile *of, OutputStream *ost, 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 + // when float_pts is not exactly an integer, + // avoid exact midpoints 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); + if (float_pts != llrint(float_pts)) + 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); diff --git a/tests/ref/fate/apng-osample b/tests/ref/fate/apng-osample index c91dd5284d..6cf74a99ee 100644 --- a/tests/ref/fate/apng-osample +++ b/tests/ref/fate/apng-osample @@ -3,7 +3,7 @@ #codec_id 0: rawvideo #dimensions 0: 116x135 #sar 0: 0/1 -0, 0, 0, 2, 62640, 0x31eb581d +0, 0, 0, 3, 62640, 0x31eb581d 0, 3, 3, 3, 62640, 0x29e11b82 0, 6, 6, 3, 62640, 0x207ed588 0, 9, 9, 3, 62640, 0x3845c906 diff --git a/tests/ref/fate/film-cvid b/tests/ref/fate/film-cvid index 60bbc192d8..428cb6e9f0 100644 --- a/tests/ref/fate/film-cvid +++ b/tests/ref/fate/film-cvid @@ -3,7 +3,7 @@ #codec_id 0: rawvideo #dimensions 0: 320x224 #sar 0: 0/1 -0, 0, 0, 1, 215040, 0x067c5362 +0, 0, 0, 2, 215040, 0x067c5362 0, 2, 2, 2, 215040, 0xd9eacb98 0, 4, 4, 2, 215040, 0x3c8a4cbd 0, 6, 6, 2, 215040, 0xbdf996e1 diff --git a/tests/ref/fate/filter-concat-vfr b/tests/ref/fate/filter-concat-vfr index 66e9007da8..3d984a4968 100644 --- a/tests/ref/fate/filter-concat-vfr +++ b/tests/ref/fate/filter-concat-vfr @@ -8,7 +8,7 @@ #codec_id 1: pcm_s16le #sample_rate 1: 44100 #channel_layout_name 1: mono -0, 0, 0, 199999, 230400, 0x88c4d19a +0, 0, 0, 200000, 230400, 0x88c4d19a 1, 0, 0, 1024, 2048, 0xb3f10192 1, 1024, 1024, 1024, 2048, 0xb340fe4e 1, 2048, 2048, 1024, 2048, 0x0a5f0111 diff --git a/tests/ref/fate/gif-gray b/tests/ref/fate/gif-gray index aa3969212d..c246d8a670 100644 --- a/tests/ref/fate/gif-gray +++ b/tests/ref/fate/gif-gray @@ -3,7 +3,7 @@ #codec_id 0: rawvideo #dimensions 0: 480x360 #sar 0: 0/1 -0, 0, 0, 4, 691200, 0xef6c0f3d +0, 0, 0, 5, 691200, 0xef6c0f3d 0, 5, 5, 2, 691200, 0xc18b32de 0, 7, 7, 2, 691200, 0x2395a3d7 0, 9, 9, 2, 691200, 0x81dc3cf2 From patchwork Wed May 31 14:54:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41909 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327347pzb; Wed, 31 May 2023 07:55:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QbwwhUyY+uh06YPxNXgX2Oo8lqAW6RlApPE/buwmG6i8OyFOhPhN81vMG9gPp+boge7wM X-Received: by 2002:a05:6402:b23:b0:514:8fdd:fc41 with SMTP id bo3-20020a0564020b2300b005148fddfc41mr4490002edb.15.1685544939003; Wed, 31 May 2023 07:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544938; cv=none; d=google.com; s=arc-20160816; b=FZ/pAUbLGxKzXaIapiIphijjSQZ7Gz9Vc+VKadDuF1bIF2FwhDpBvVvyX1eA4UGTtk OcbVIeBydp2oYvMhAqpnbuKhHB9lRNH92zudGKk8FwwdDPzu0EDtjFLWN4Q7VxBIamDW m4OiyEnEN6YKHp0rVe8Tpw0sKl/Keucguk4XmR7YyetlWM6HbZxkOm61vim92ro5ZsrW PeNoXsQIY49hSUyQXdBBH6IsAxFGW4hkpNoX6ktP3bYiGzFPe8/tb84YSVtVBFj9BRRH Man7AXFHzly2ujRDf3WZIXBykiQm84aoJcqCdRaTAu6ohO0oF/DDcY/bd9KcpmeoF12R DmcQ== 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=e2P/BHYpfWMe7DQz7VrAtBJ5qOk9gFZL0Ljthh0sW8w=; b=cyPH5KRrll5FmkAvJAF0gyGY0dm+bN49Q4fmb2e9vHFKP0YWkUgIMWPgCXrYq64M2S zi/lveJ1/Xlp3jwYbCd1nOcCA+iipZj+j3lcPSbVLGG3Z+3tFiKhLb4Dvf4HfX1naI68 ZR5/6B5daIcCgH/5JiLrK423W4pqSG2a5XQ4sTTBF0JJ4nuspCHMcQSCmeq/Cs01vc8C JSvr4atSFB+Q9Tc+kiCQLbxsuDcn8QFuFTThQrHcxlEciseTkmCX5UW8YkR5xzylx5Zs vfFQhXWWoClzmIpRKqOVNRtBrnuNMlQwV4Cj2jK0JgRSb84f6mY691Ry5JOCxzXrf7qG wecg== 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 c8-20020a056402120800b00514b3b9977bsi1981116edw.297.2023.05.31.07.55.38; Wed, 31 May 2023 07:55:38 -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 4496E68C26F; Wed, 31 May 2023 17:55:16 +0300 (EEST) 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 65D5168C1CE for ; Wed, 31 May 2023 17:55:07 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 333FE2404EE for ; Wed, 31 May 2023 16:55:07 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id eS1-bbYN7QoB for ; Wed, 31 May 2023 16:55:06 +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 mail0.khirnov.net (Postfix) with ESMTPS id A3C062404F5 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 196D03A05CB for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:37 +0200 Message-Id: <20230531145453.20994-7-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for streamcopy 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: resehAr8zuab The values currently written into it are not used after streamcopy_init(), so it is better to confine them to that function. --- fftools/ffmpeg_mux_init.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 33c93e40f2..b5295ad445 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -861,6 +861,9 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost) AVCodecContext *codec_ctx = NULL; AVDictionary *codec_opts = NULL; + + AVRational fr = ost->frame_rate; + int ret = 0; codec_ctx = avcodec_alloc_context3(NULL); @@ -893,11 +896,11 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost) par->codec_tag = codec_tag; - if (!ost->frame_rate.num) - ost->frame_rate = ist->framerate; + if (!fr.num) + fr = ist->framerate; - if (ost->frame_rate.num) - ost->st->avg_frame_rate = ost->frame_rate; + if (fr.num) + ost->st->avg_frame_rate = fr; else ost->st->avg_frame_rate = ist->st->avg_frame_rate; @@ -908,8 +911,8 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost) // copy timebase while removing common factors if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) { - if (ost->frame_rate.num) - ost->st->time_base = av_inv_q(ost->frame_rate); + if (fr.num) + ost->st->time_base = av_inv_q(fr); else ost->st->time_base = av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1}); } From patchwork Wed May 31 14:54:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41908 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327258pzb; Wed, 31 May 2023 07:55:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ58y9DDOZT6fSABMVLHjiJDuU4PS0wtnR0xZ4pcWCW8GVwcsrl1YWz2sTjWpaw2v1o7hzsn X-Received: by 2002:aa7:c144:0:b0:514:9e81:9070 with SMTP id r4-20020aa7c144000000b005149e819070mr4011941edp.15.1685544929271; Wed, 31 May 2023 07:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544929; cv=none; d=google.com; s=arc-20160816; b=HaVHJ8dn9hA5T/Ui+ajmP0eer6EVxaY7wUHt/GymV2XEZ32SPXwjTJ/eFzP0jtR1+l 8NsbmWZ0mLjO6ZfsGS56EqnhDtMHm/L6B/XrUzyXYz+ClD4XOMZQj8KwznGUcGN6aj8V 6jSZfRdM+lkvfVQxZvsb/UpNmRLJ9PAgI0YTHPBD0amomMXUYDzbZ28n4ui/6Jhp3k68 jdePftetlJU31THFCS6BHRCFsHh47wf5VEySe8XAGj+/EvYst7zJfzXo15dv5ZemnYsB ccxaiaQcdKBxoFVPCSw+6ORWfNFRBSJBTya6Erne2dgbMbqW1wv2ubml9BSWxKi5SX2T YkHw== 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=fBoZ/sIV9s+2/nO8v3klx8a2BQNpwaxHat0W00Emgvw=; b=w1uskSNmfwepX1jojTtRtJ5gi7l/dVndrIcHjFL0fwoFoiRnl7NF1tFrzRhdxvPbIv v898N+lokZrynoPzvyOQNFiDfULiS5wu57DVhZpM2NaYJLs6ArqprIwzk4Ngkad6TbWm UJoETXdPJf4Z3X0jZjIwDZ/DKfE6yo8uc3CiOaEwRMLPD495/oaC0VSeXRD0htVHgl8a 4CapRPt/2a95P0C+phHzuotjvXo7r8MLTSXdW3U4MFwz+PzvsNAD+wdvbx99+FQel0Du yR/rG0wpDxR79kOZd2oS+nbBej/xHh2ZCu+CB4CfHW/GeWYjw0EhPSY+huxeejEVieWC iKAQ== 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 v5-20020aa7d9c5000000b0050c9581ffa0si2239325eds.192.2023.05.31.07.55.28; Wed, 31 May 2023 07:55:29 -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 2127A68C24A; Wed, 31 May 2023 17:55:15 +0300 (EEST) 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 E03F668C1CE for ; Wed, 31 May 2023 17:55:06 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A465B240D1D for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id PjYdFq_8YrUP for ; Wed, 31 May 2023 16:55:06 +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 mail0.khirnov.net (Postfix) with ESMTPS id 9A17E2404EE for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 242EA3A0664 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:38 +0200 Message-Id: <20230531145453.20994-8-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/23] fftools/ffmpeg_enc: merge two adjacent video-specific blocks 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: 7eyCBpRAyBC/ There is no meaningful reason for them to be separated. --- fftools/ffmpeg_enc.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index d390e384ed..07928b3557 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -219,7 +219,24 @@ int enc_open(OutputStream *ost, AVFrame *frame) dec_ctx = ist->dec_ctx; } - if (enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { + switch (enc_ctx->codec_type) { + case AVMEDIA_TYPE_AUDIO: + enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter); + enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter); + ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout); + if (ret < 0) + return ret; + + if (ost->bits_per_raw_sample) + enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; + else if (dec_ctx && ost->filter->graph->is_meta) + enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, + av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3); + + init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate)); + break; + + case AVMEDIA_TYPE_VIDEO: if (!ost->frame_rate.num) ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter); if (!ost->frame_rate.num && !ost->max_frame_rate.num) { @@ -245,26 +262,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) av_reduce(&ost->frame_rate.num, &ost->frame_rate.den, ost->frame_rate.num, ost->frame_rate.den, 65535); } - } - switch (enc_ctx->codec_type) { - case AVMEDIA_TYPE_AUDIO: - enc_ctx->sample_fmt = av_buffersink_get_format(ost->filter->filter); - enc_ctx->sample_rate = av_buffersink_get_sample_rate(ost->filter->filter); - ret = av_buffersink_get_ch_layout(ost->filter->filter, &enc_ctx->ch_layout); - if (ret < 0) - return ret; - - if (ost->bits_per_raw_sample) - enc_ctx->bits_per_raw_sample = ost->bits_per_raw_sample; - else if (dec_ctx && ost->filter->graph->is_meta) - enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, - av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3); - - init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate)); - break; - - case AVMEDIA_TYPE_VIDEO: init_encoder_time_base(ost, av_inv_q(ost->frame_rate)); if (!(enc_ctx->time_base.num && enc_ctx->time_base.den)) From patchwork Wed May 31 14:54:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41921 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328392pzb; Wed, 31 May 2023 07:57:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ysob5dpf3s4Fy6SsWv43wWV49fLiYVAQqzkDmvvIKZyWMjWpRG6Bk9jgxBjSmeAHldCem X-Received: by 2002:a17:907:c0c:b0:93b:5f2:36c with SMTP id ga12-20020a1709070c0c00b0093b05f2036cmr6189893ejc.61.1685545044820; Wed, 31 May 2023 07:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545044; cv=none; d=google.com; s=arc-20160816; b=AvPjehGUMSS6nKCLJYWqgyTTXD5i/lz1o1mbsPNfLFmmauBafVkAI79JwcAIqEz/hT 932H+lXH1GKGGrBxgBgLfxLx+YImeWWscr34f7+bupgpR8ttvvQIvbO3iRP1aWz633ZR SxLmN4KjxzH7+j75NnnW+sEZt24KePQuWU/GJR+IFnFHdZdiV/OHVGpVA52avm7epMHR 6BUnRlD7EFTjKUdqmNf/UIGo1QQabDZEtbw/+bezVzJ8OsU+x9EjbpBQvrRqfN/hfLkf rKY2qnUGnAJBZz4SGIYGHfqhD+izt07jNoagI2RZyff8sBTvzhOsGa2ZUOLcWl6t30JR Vv7w== 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=hmOqGXVaqKzSPYXnre8wJB5Xvm1AKivqMDa5+zsQSGI=; b=PR4IW6wZVAI6PUDPn9U931G4wCEXDRO5HcWuK8bHwMj6+or58opU21DiQJRG5LCi2w GCDjXXYnd66DNvL3FABGk2TvSepPOB92v0EdTXVgsBP5OKUJYD59n7j3oi39TsGDkx0d sc92y91aUbjs95fh9WltmiOuNnWVipvqANwqZK1w55GsMFaEkD2psc3dF3g/fZipK6JR sv3sRtBaLujIrNE5nfc+uP7lt06dL5CFTwlxCUsDmtxBYGH2sYGZmJqiZH/iK4BCct+H qmDEfkrV9AOYqcnsQjMhJq+cdVoj7f86Elbs9A1ZBiyyT8SR5HmDTakYPdc0545MH2jL k4xw== 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 ss8-20020a170907c00800b009618d4710f6si1646869ejc.552.2023.05.31.07.57.24; Wed, 31 May 2023 07:57:24 -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 360D568C236; Wed, 31 May 2023 17:55:28 +0300 (EEST) 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 277D868C267 for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id A6A112405B5 for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id VrBQEQaXd5BG for ; Wed, 31 May 2023 16:55:08 +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 mail0.khirnov.net (Postfix) with ESMTPS id C78A52405EC for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 2F4AC3A07D2 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:39 +0200 Message-Id: <20230531145453.20994-9-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/23] fftools/ffmpeg_mux_init: only process -enc_time_base if the stream is encoded 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: eMGuFSJfCs54 It has no effect otherwise. --- fftools/ffmpeg_mux_init.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index b5295ad445..d0b89cd188 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1073,6 +1073,7 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, AVIOContext *s = NULL; char *buf = NULL, *arg = NULL, *preset = NULL; const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL; + const char *enc_time_base = NULL; ost->encoder_opts = filter_codec_opts(o->g->codec_opts, enc->codec_id, oc, st, enc->codec); @@ -1139,6 +1140,17 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, if (ret < 0) exit_program(1); } + + MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st); + if (enc_time_base) { + AVRational q; + if (av_parse_ratio(&q, enc_time_base, INT_MAX, 0, NULL) < 0 || + q.den <= 0) { + av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base); + exit_program(1); + } + ost->enc_timebase = q; + } } else { ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL); } @@ -1162,17 +1174,6 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, st->time_base = q; } - MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st); - if (time_base) { - AVRational q; - if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 || - q.den <= 0) { - av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base); - exit_program(1); - } - ost->enc_timebase = q; - } - ms->max_frames = INT64_MAX; MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st); for (i = 0; inb_max_frames; i++) { From patchwork Wed May 31 14:54:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41911 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327492pzb; Wed, 31 May 2023 07:55:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hn7XDmCW5sU5tXUDlu/fHe41T0Z/0I1oSXOFM+XCj6Wjqhq/KDhELI5XO5JvCbkD52Y5I X-Received: by 2002:a2e:9583:0:b0:2a7:8150:82c1 with SMTP id w3-20020a2e9583000000b002a7815082c1mr2777006ljh.38.1685544957939; Wed, 31 May 2023 07:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544957; cv=none; d=google.com; s=arc-20160816; b=IDJsGqaiWNCRE+9EB3BjXDYxGlQLzsCsIhA9t2hoPg6Yv5zNd3EcroK/O/aHVS8+za uOquiLcOAc2gTOQwWqVGjZJy1pgyliACrxEzkjYB7vn0d0n6DCg/meBOA0dzCLZcPbbS O+isQKP8IIconcRvA/G3UXBsii+aVyAtFUyyEQVRl43DeHUpA5NfbHg+KS/jrY7raVzI so9EINnzlFO4gTwlwMLasafUorfMYqycSH41ate+5Kcl0uL6PYEcrw57PqjtvRL7E/xL 4gmukFqsRVyMv3lJ+n+mY7DXew2SLtOLUIGSzctnnWSdvlMYU7Scm7BoSvFFfV4jszUy wl2g== 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=JLDGjGJxybi9/NoEhmV7Wtpk5gn0W5uy3HnbeUJ0k5U=; b=i6LKc0pSg9SAVrdjUnfVOTESiQ27az/eIzqbSqPJ4l6+5+Qqf+CSd7sAHheQ7VQRTR 8zZUfEaSSoFszlNbpl/d916rWqZJ+ptzhsyl9Nn0hhGFgiBtl2VIYiALUTqR6jPKT7aJ fLu+uHi0FHOuMg1Mq0jm142myVhdpa5HC8oOWV7oKT7I6eEuTdUFmF/Uphvm07HyKar1 WP2TvM6CGwFgl254LKW1xfuGD+bPsmp7K8JvGFpWfwn8c9iYdYxh+AFesTsdPVAClprT XcHvxABTbwvfMjGMVQhVhy0FyRkVkoBxd8ha+SThOJGS5P8rITaxDBjAhGMJORtKEH4D /CZA== 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 q6-20020a170906a08600b0096b15e5cb9asi311603ejy.607.2023.05.31.07.55.57; Wed, 31 May 2023 07:55:57 -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 3BE6C68C2AB; Wed, 31 May 2023 17:55:18 +0300 (EEST) 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 EE30A68B649 for ; Wed, 31 May 2023 17:55:07 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C40E6240177 for ; Wed, 31 May 2023 16:55:07 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Ky8KJJv2d2vb for ; Wed, 31 May 2023 16:55:07 +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 mail0.khirnov.net (Postfix) with ESMTPS id ADD212404F8 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3ADBE3A07F4 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:40 +0200 Message-Id: <20230531145453.20994-10-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/23] fftools/ffmpeg: handle -enc_time_base -1 during stream creation 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: LLwfIqKSovG2 There is no reason to postpone it until opening the encoder. Also, abort when the input stream is unknown, rather than disregard an explicit request from the user. --- fftools/ffmpeg_enc.c | 11 ----------- fftools/ffmpeg_mux_init.c | 9 +++++++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 07928b3557..04d2c3c201 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -179,7 +179,6 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost) static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base) { - InputStream *ist = ost->ist; AVCodecContext *enc_ctx = ost->enc_ctx; if (ost->enc_timebase.num > 0) { @@ -187,16 +186,6 @@ static void init_encoder_time_base(OutputStream *ost, AVRational default_time_ba return; } - if (ost->enc_timebase.num < 0) { - if (ist) { - enc_ctx->time_base = ist->st->time_base; - return; - } - - av_log(ost, AV_LOG_WARNING, - "Input stream data not available, using default time base\n"); - } - enc_ctx->time_base = default_time_base; } diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index d0b89cd188..c49f906dc7 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1149,6 +1149,15 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base); exit_program(1); } + if (q.num < 0) { + if (!ost->ist) { + av_log(ost, AV_LOG_FATAL, + "Cannot use input stream timebase for encoding - " + "no input stream available\n"); + exit_program(1); + } + q = ost->ist->st->time_base; + } ost->enc_timebase = q; } } else { From patchwork Wed May 31 14:54:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41915 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327859pzb; Wed, 31 May 2023 07:56:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qglWanHPETrb54v4oFzqm5z3n+6AuMBV8ubJJpV8RGQq3x8fjh3Qq6ySAOtTP+2GTnSEz X-Received: by 2002:aa7:d687:0:b0:515:4043:476f with SMTP id d7-20020aa7d687000000b005154043476fmr824927edr.36.1685544993426; Wed, 31 May 2023 07:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544993; cv=none; d=google.com; s=arc-20160816; b=r41Q+fwb2xRxdkendXYItaFXdqd9gtOCR0L5hUMe7dkTRhwo4jfHWNEBJPmq60SzN6 525TO339nLP+/c4llhh5ccy6HFr/JpUpradc/Pf3Sr0oi5bQFQNMByeGxa3hD3le//OO PMLiwky7x9dt+MqTU5KE3ifqIGfkktYVZjQvBrWWx1xr41ApJwLievFa0sBigSlEYBnd zaB8mlSXK9gp9532qULO/NaJkmDutaK1RhpfbBxBh3wXl6YQKmPbzaPpnlWlEE+HgIyJ wGTGZbFkILeXfRe8EM8rQltXrH8GVupyErKOrAji2WcW+hL4QCSmxK3UCpGliTcJHGiK U3AQ== 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=yYgjCFODFpfiMNRGb4zP1lmAy4Yv9ZHFAC+TjZAjVSM=; b=wvatsVTsVVUMFbUFOV1aUnixZeYXvBhf8e/Z2Q0rl/y1EgDkjYvme5P4WQZKzh92Dn v89bffLBqRnJV+VxMtNYNwVUh6xlR4WQxBx6Q8ZCs999Uf4xu8p8sieqoBmeZ4K1hTaV 0wt1dQPNMlWePkiENUT/3bGqb6PBuplj7Bmv07WcvjpTTp2SBC6t7OxkExDHsKaDXVey bb3p07NooDfkKcioAjAXGwZTWOPZ04cyRlqeQ1Ndybmdb1FGaAQIikPziZv5yKLnWlYm Kp6J7gJX0nRmDrebLzAAHuO6u4hD8g171lN4DyEuDJTb8Io6Sv9Lqofcyi23jizhF+8x KB1Q== 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 c10-20020aa7d60a000000b00510b57f17casi2067222edr.348.2023.05.31.07.56.33; Wed, 31 May 2023 07:56:33 -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 572BA68C2DC; Wed, 31 May 2023 17:55:22 +0300 (EEST) 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 3AC1268C255 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id DE79D2406CE for ; Wed, 31 May 2023 16:55:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1WhVSMttT73i for ; Wed, 31 May 2023 16:55:10 +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 mail0.khirnov.net (Postfix) with ESMTPS id F39152406D0 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 46B5D3A082C for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:41 +0200 Message-Id: <20230531145453.20994-11-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/23] fftools/ffmpeg_enc: inline init_encoder_time_base() into its callers 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: 1aetzjgkROON The function now reduces to a ternary operator, so it is shorter and clearer to eliminate it. --- fftools/ffmpeg_enc.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 04d2c3c201..4a5ae3aa1b 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -177,18 +177,6 @@ static void set_encoder_id(OutputFile *of, OutputStream *ost) AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_OVERWRITE); } -static void init_encoder_time_base(OutputStream *ost, AVRational default_time_base) -{ - AVCodecContext *enc_ctx = ost->enc_ctx; - - if (ost->enc_timebase.num > 0) { - enc_ctx->time_base = ost->enc_timebase; - return; - } - - enc_ctx->time_base = default_time_base; -} - int enc_open(OutputStream *ost, AVFrame *frame) { InputStream *ist = ost->ist; @@ -222,7 +210,8 @@ int enc_open(OutputStream *ost, AVFrame *frame) enc_ctx->bits_per_raw_sample = FFMIN(dec_ctx->bits_per_raw_sample, av_get_bytes_per_sample(enc_ctx->sample_fmt) << 3); - init_encoder_time_base(ost, av_make_q(1, enc_ctx->sample_rate)); + enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase : + av_make_q(1, enc_ctx->sample_rate); break; case AVMEDIA_TYPE_VIDEO: @@ -252,7 +241,8 @@ int enc_open(OutputStream *ost, AVFrame *frame) ost->frame_rate.num, ost->frame_rate.den, 65535); } - init_encoder_time_base(ost, av_inv_q(ost->frame_rate)); + enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase : + av_inv_q(ost->frame_rate); if (!(enc_ctx->time_base.num && enc_ctx->time_base.den)) enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter); From patchwork Wed May 31 14:54:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41920 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328318pzb; Wed, 31 May 2023 07:57:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/nt83XgulqGgSyM701gRI3fQVbIfyUyB4sCrJY3X6MtpO3yPZbEaykRV2bEIGpX+uZydA X-Received: by 2002:a05:6402:54c:b0:514:a655:d240 with SMTP id i12-20020a056402054c00b00514a655d240mr3922011edx.21.1685545036164; Wed, 31 May 2023 07:57:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545036; cv=none; d=google.com; s=arc-20160816; b=NeCnqqjwYiPv7gYpDRIrRW67AzyhWT8uV0j58Nh5p9VkD8PuSaqb8yaNqFpzMpksOl PTVrCn56WL0ECN0+MujN4jqOmLFa0oyJ8eKq+wY5GXScDlZyLlaBZOTz0YeK7zJrexwA UC1PLIB+10GTBUUA7wZcSGGR7Eq9kIBOTuut3YMdBfSK3arXYbnvHRRnLB+QLM1ou/yG KUKuFZqrRe+TdzH+S3kSQcTasdcbrnv+vm51y9smmMCGE1/pON4JbbmpH2A/alsVkErS 1/azkECWomvnjkD+M86bYdqQ4qhIxwqd4BQymWdT5Yl5a8bqLYGcXkdiQdi2C88P5C5N 3lFw== 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=Dixsg2O22FBrl8gJWIxDZHqFZVNBUKkIdjIQHtcrrpc=; b=HU/Eg7qo2lOgwQHfs3OER8PHi+79AnjwS3V3JoWphbgNqH+ClQor6tf838qH49A2Wn x27/pGXcY6/KnGeWYSqq1clRqSNRUxOTSonCCo8HvJ0HICODAzGB+2IGmq+6GzDb1Qy9 3TCgIiWiHBjl8tf0Cl9nQaE8E+I+rBdJFS+aPdTwCxF0/hLXjOPeG5cKt4v8hd2T8WOM E2zzA8kNqo23+5tvhQSGL30LAFDgTu0JYZiWy5Tgj/FN6uxOXgWDYHpYhrfmKV0cLTXL +3ZNldXDHCVhXzIRHwa6afBspCPNcMLsFwFMazdxr6RrOPsrZJcqlbIvEB47DRBtObCf AtaA== 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 d24-20020aa7d698000000b005069976f799si2659524edr.401.2023.05.31.07.57.15; Wed, 31 May 2023 07:57:16 -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 37BF368C2F9; Wed, 31 May 2023 17:55:27 +0300 (EEST) 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 20AC368C27A for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 1E12C2404F8 for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id p-tJHHgUKZbQ for ; Wed, 31 May 2023 16:55:07 +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 mail0.khirnov.net (Postfix) with ESMTPS id BAE46240591 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 523B73A08D4 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:42 +0200 Message-Id: <20230531145453.20994-12-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/23] fftools/ffmpeg_enc: do not guess frame durations from output framerate 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: stnKFJi7Knem There is no reason to expect input frame durations to match output framerate. --- fftools/ffmpeg_enc.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 4a5ae3aa1b..5be6e9332a 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -1042,9 +1042,6 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) if (frame) duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base)); - if (duration <= 0 && ost->frame_rate.num) - duration = FFMIN(duration, 1/(av_q2d(ost->frame_rate) * av_q2d(enc->time_base))); - frame_rate = av_buffersink_get_frame_rate(filter); if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0) duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base)); From patchwork Wed May 31 14:54:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41912 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327618pzb; Wed, 31 May 2023 07:56:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6D3xxQSwGo33YE06WP0jMUTv0r+u1mPri0aX+BhYzKIuvvLzsiMCh7yiJSjNoGYYwQWuqU X-Received: by 2002:aa7:d044:0:b0:50d:9e7c:264d with SMTP id n4-20020aa7d044000000b0050d9e7c264dmr4350726edo.8.1685544967327; Wed, 31 May 2023 07:56:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544967; cv=none; d=google.com; s=arc-20160816; b=jPTIDt/Z2VrM8asf/kKyS//Kpwa69mJaymgulQiIGEGRI8Bnt+4Z70lvkGp3phvCYE tdtdHzbOo55Ey5a7CKTIp0RJWugC5Py/o6nrLTe4UUvDYKpJdDiEoMYlENCQOXtbXE+i r2vY7FMMssbKMa9NV0RzNaUZQkgIQmKve11bD812P5wAiecLTQG7ycDuJ/xsZv27rI3g AmkSNaHjecHwq6fuHYS6I+3yP/PUd+LWubzGf9vrGuPfG2okBsR0BzwrEnlFBth9XPYb Ppoi0XJzUDnyOyMf0rmyf8wVeaerxDrGd9gDpQYbttmQdveHdtnQZOm2teNNPQEwxuT6 ddZg== 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=l7yc1JaI518IEuFoTizcC1HQeex3cHdA90OuWw9rZhA=; b=wLOBix+yWX/TrIF9Au0iZy0dSan3nWbwxiLw+zTqE6AqsRre4X4LOG9XQTGotcuuXo 9s8yT4Lxg+kPqjlqB8cIsGLV7xoEhtK3tsWdEN3tK+RVxfOuIDzX6UA28bhzk4sS8Z18 TqbFVPLkGh+p07U+AxxnivqUSAoeoJqXE1GYMFSinYsHElEjEJwB4+hTFsBRb7s0uhD+ Qmo7wozXMd7nQv8oZve6PZ3thTSNzf8CqmmCDBC+uFi723H2AZsc+4qrlE+N0zeE+1p8 IeuKKDCHKny0SslAONl5EoTPZAcgC/C/IjZoDRuJ5oHjytoU7wvVmLEm+BHE3jknLTES Tzog== 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 h24-20020aa7de18000000b00514bd211792si1066599edv.416.2023.05.31.07.56.06; Wed, 31 May 2023 07:56:07 -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 3ACA168C2A8; Wed, 31 May 2023 17:55:19 +0300 (EEST) 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 1C98568C23F for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id C570C2406CB for ; Wed, 31 May 2023 16:55:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id s0UXf-dyyLtV for ; Wed, 31 May 2023 16:55:09 +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 mail0.khirnov.net (Postfix) with ESMTPS id EA0A12406CD for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5E3403A09B3 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:43 +0200 Message-Id: <20230531145453.20994-13-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/23] fftools/ffmpeg_mux_init: do not overwrite OutputStream.frame_rate for encoding 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: b4ksxdGFUUlr The values currently written into it are not used after enc_open(), so it is better to confine them to that function. --- fftools/ffmpeg_enc.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 5be6e9332a..1b0410ae74 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -214,11 +214,13 @@ int enc_open(OutputStream *ost, AVFrame *frame) av_make_q(1, enc_ctx->sample_rate); break; - case AVMEDIA_TYPE_VIDEO: - if (!ost->frame_rate.num) - ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter); - if (!ost->frame_rate.num && !ost->max_frame_rate.num) { - ost->frame_rate = (AVRational){25, 1}; + case AVMEDIA_TYPE_VIDEO: { + AVRational fr = ost->frame_rate; + + if (!fr.num) + fr = av_buffersink_get_frame_rate(ost->filter->filter); + if (!fr.num && !ost->max_frame_rate.num) { + fr = (AVRational){25, 1}; av_log(ost, AV_LOG_WARNING, "No information " "about the input framerate is available. Falling " @@ -227,22 +229,22 @@ int enc_open(OutputStream *ost, AVFrame *frame) } if (ost->max_frame_rate.num && - (av_q2d(ost->frame_rate) > av_q2d(ost->max_frame_rate) || - !ost->frame_rate.den)) - ost->frame_rate = ost->max_frame_rate; + (av_q2d(fr) > av_q2d(ost->max_frame_rate) || + !fr.den)) + fr = ost->max_frame_rate; if (enc->supported_framerates && !ost->force_fps) { - int idx = av_find_nearest_q_idx(ost->frame_rate, enc->supported_framerates); - ost->frame_rate = enc->supported_framerates[idx]; + int idx = av_find_nearest_q_idx(fr, enc->supported_framerates); + fr = enc->supported_framerates[idx]; } // reduce frame rate for mpeg4 to be within the spec limits if (enc_ctx->codec_id == AV_CODEC_ID_MPEG4) { - av_reduce(&ost->frame_rate.num, &ost->frame_rate.den, - ost->frame_rate.num, ost->frame_rate.den, 65535); + av_reduce(&fr.num, &fr.den, + fr.num, fr.den, 65535); } enc_ctx->time_base = ost->enc_timebase.num > 0 ? ost->enc_timebase : - av_inv_q(ost->frame_rate); + av_inv_q(fr); if (!(enc_ctx->time_base.num && enc_ctx->time_base.den)) enc_ctx->time_base = av_buffersink_get_time_base(ost->filter->filter); @@ -277,9 +279,9 @@ int enc_open(OutputStream *ost, AVFrame *frame) enc_ctx->chroma_sample_location = frame->chroma_location; } - enc_ctx->framerate = ost->frame_rate; + enc_ctx->framerate = fr; - ost->st->avg_frame_rate = ost->frame_rate; + ost->st->avg_frame_rate = fr; // Field order: autodetection if (frame) { @@ -307,6 +309,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) } break; + } case AVMEDIA_TYPE_SUBTITLE: enc_ctx->time_base = AV_TIME_BASE_Q; if (!enc_ctx->width) { From patchwork Wed May 31 14:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41923 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328579pzb; Wed, 31 May 2023 07:57:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MUjeL71LNDt7gMG8cqGyDhlevGvCHREMlNeqib28RXwiviU0Ss9GX1crrcfuTSx9pVCvk X-Received: by 2002:a17:907:a426:b0:96f:c988:93b with SMTP id sg38-20020a170907a42600b0096fc988093bmr5502927ejc.35.1685545062016; Wed, 31 May 2023 07:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545062; cv=none; d=google.com; s=arc-20160816; b=V75pYTt/Zxfld9sB/IX4sWatTJt8kypvh3x5CElihNSo8W9xoDnb1lU9hnphG8OWJx mR7bG8NWXdOfnhvUdb/yq2D07IQVgQ6xU7PQu+2OddB22szKQRyanxhpmpOBc3ZrR70Q m6bj+PZDYPeCoAbQ0vkg3mSUZNh0QLZ87XHqGXzGDzy86clkn0JopV+oQeGgf6APVSEd yVIBh0LAzx1FJjJBWGcPPlYoKtCFrgIPULbpakiJg3bu7f5YsQnX08CRWOhs138cDE5o jY6mqQWUQfFoLkTS7gPDP/zT5HzZpRonGRK4Pjbp4ajKSY/PKvxYI3o3ZEiHuWD8XuC5 GY4Q== 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=yDOSwV2f3J0YRq5BEdsIW2PRxVSSiDXti7tUF2vwLLI=; b=nl8b2jZwAsnlUuUp+96ADHTcwuaAzc04JeNEgD00wjVN/ZzAtLFibTK7v6t7M1FCKB uKBCcI4W6xvz11lgDJOYg4CzEBwRrNzAOy5V/xQnE7YkDCkv05ZVDJaOag0346J6YknK 3eaDQslm1Rd1uMZQ99uRGq2g2OsD0xCaOrUM/542APMZdr/rDMR5A/s/EXugXYo9sjhI VqjSEnDCK9yLbBirhshf9zRcVO+HSyO54hFyNV4Q+EFeSK3Ll5Gx+pVPGbZAP64ElOHr BAyXdJyASAAf0T0HiUYIkl32Hwbe26lw1bm8eYfjCiPXhsTeGb73Jslg7kfKhkmOPBx3 OWwg== 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 w17-20020a17090652d100b0096f818bfb47si3162495ejn.1009.2023.05.31.07.57.41; Wed, 31 May 2023 07:57: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; 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 2309068C2B2; Wed, 31 May 2023 17:55:30 +0300 (EEST) 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 2551068C28D for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5CA70240591 for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 949nfy7b3xfF for ; Wed, 31 May 2023 16:55:07 +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 mail0.khirnov.net (Postfix) with ESMTPS id C45812405B5 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 69AB63A0BC6 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:44 +0200 Message-Id: <20230531145453.20994-14-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/23] fftools/ffmpeg: convert timestamps inside the muxer 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: +ktGRGb17kSl Packets submitted to the muxer now have their timebase attached to them, so the muxer can do conversion to muxing timebase and avoid exposing it to callers. --- fftools/ffmpeg_enc.c | 17 ++--------------- fftools/ffmpeg_mux.c | 6 ++++++ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 1b0410ae74..f6431b29d1 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -512,8 +512,8 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub) } av_shrink_packet(pkt, subtitle_out_size); - pkt->time_base = ost->mux_timebase; - pkt->pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, pkt->time_base); + pkt->time_base = AV_TIME_BASE_Q; + pkt->pts = sub->pts; pkt->duration = av_rescale_q(sub->end_display_time, (AVRational){ 1, 1000 }, pkt->time_base); if (enc->codec_id == AV_CODEC_ID_DVB_SUBTITLE) { /* XXX: the pts correction is handled here. Maybe handling @@ -735,19 +735,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); } - av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase); - pkt->time_base = ost->mux_timebase; - - if (debug_ts) { - av_log(ost, AV_LOG_INFO, "encoder -> type:%s " - "pkt_pts:%s pkt_pts_time:%s pkt_dts:%s pkt_dts_time:%s " - "duration:%s duration_time:%s\n", - type_desc, - av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &enc->time_base), - av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &enc->time_base), - av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &enc->time_base)); - } - if ((ret = trigger_fix_sub_duration_heartbeat(ost, pkt)) < 0) { av_log(NULL, AV_LOG_ERROR, "Subtitle heartbeat logic failed in %s! (%s)\n", diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 121796a55a..dc2d189ff0 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -334,6 +334,12 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) if (!eof && pkt->dts != AV_NOPTS_VALUE) ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q); + /* rescale timestamps to the muxing timebase */ + if (!eof) { + av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase); + pkt->time_base = ost->mux_timebase; + } + /* apply the output bitstream filters */ if (ms->bsf_ctx) { int bsf_eof = 0; From patchwork Wed May 31 14:54:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41914 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327766pzb; Wed, 31 May 2023 07:56:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Wf0NVpKbp0a28Mj3MaJCf2U2Qqd2CG7o89sPCYlCi80+v6jef/3o8ZC9Fql35hV2d6pQg X-Received: by 2002:a17:907:6d1f:b0:974:1eeb:1ad6 with SMTP id sa31-20020a1709076d1f00b009741eeb1ad6mr5242075ejc.30.1685544985087; Wed, 31 May 2023 07:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544985; cv=none; d=google.com; s=arc-20160816; b=dt9lFWXY5lKg5c+QmhhI3qWrWeiwK6vsUko6MOiH7g9DgNKbjcyiZpXzFVp5WrWLDY Nkn4arBA+Y0Righ5AiWUyjupsrtIeYLZGuFe39VcHg3gFofoWDNfeDv+zdlDuKMEG2OI 1twX1cN766k7V00Un9iuUkIujFw8WhUXFl4ig3mqb2xwsd57qZqtY+nKPXK3uwv9OkFq 9VVkuVlIp8I5iFJjdnDWpaU2e2Wti2ei5ukjg742M42M5pItDyVplhwrusFvUA3KWGs9 eRVz174Q5DDt4YHFof9ByKAtw2LPz3pcMRdBxG+oIUQXXO34dC375CC+no28YNZmFW/9 Zxdw== 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=RUSJYfs9boRKH/08v4glkW5tCCu8nyl6/HovvWZkrTw=; b=Rw2QelJ62TBJi/Wb3uHGKPRsk7wS0TG8alYu0InXDXG+DKr+iwD4tNZ9irhEJAL9Xk uQmRkxu6Abv9xlbWQdRwSgpbuxE3bqQjlqlphG2B5uvdtnnx9y2P23R3vr9TQ79OSNSn Zv9Q7NAREE1wcNuDvCp3B6kaVaD/3/K1Rv19U3v5vizqgzgLlPJ2tQ3CVhuPl4XFCwBm 1fZ498buVvBCeKgKCQ6oSCszZwIs1zcWGnsTemxgqyYfOk2Iloxg1RuecjUFFkiFwzY7 Oj4kpJpwopgpOvlKoiJWDL5Sir97NmxgPAY5S/f/dJNb49fZhucKor85QTABbB5o4iOe Ys5g== 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 a15-20020aa7d74f000000b00514a6ae120fsi3632438eds.258.2023.05.31.07.56.24; Wed, 31 May 2023 07:56:25 -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 576E468C258; Wed, 31 May 2023 17:55:21 +0300 (EEST) 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 3697168B649 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 577F12406CC for ; Wed, 31 May 2023 16:55:10 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id k3JP1ozvIZzj for ; Wed, 31 May 2023 16:55:09 +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 mail0.khirnov.net (Postfix) with ESMTPS id F117B2406CE for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 755383A0BDC for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:45 +0200 Message-Id: <20230531145453.20994-15-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/23] fftools/ffmpeg: factor out attaching FrameData to 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: T0otSFmy1Tjx Will be useful in following commits. --- fftools/ffmpeg.c | 11 +++++++++++ fftools/ffmpeg.h | 6 ++++++ fftools/ffmpeg_dec.c | 5 ++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index bcda7570e9..9997881572 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -431,6 +431,17 @@ InputStream *ist_iter(InputStream *prev) return NULL; } +FrameData *frame_data(AVFrame *frame) +{ + if (!frame->opaque_ref) { + frame->opaque_ref = av_buffer_allocz(sizeof(FrameData)); + if (!frame->opaque_ref) + return NULL; + } + + return (FrameData*)frame->opaque_ref->data; +} + void remove_avoptions(AVDictionary **a, AVDictionary *b) { const AVDictionaryEntry *t = NULL; diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 0e9ad5f9f7..6f71e85658 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -737,6 +737,12 @@ int init_complex_filtergraph(FilterGraph *fg); int copy_av_subtitle(AVSubtitle *dst, const AVSubtitle *src); +/** + * Get our axiliary frame data attached to the frame, allocating it + * if needed. + */ +FrameData *frame_data(AVFrame *frame); + int ifilter_send_frame(InputFilter *ifilter, AVFrame *frame, int keep_reference); int ifilter_send_eof(InputFilter *ifilter, int64_t pts, AVRational tb); int ifilter_sub2video(InputFilter *ifilter, const AVSubtitle *sub); diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 30959c64b7..799be63215 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -499,12 +499,11 @@ int dec_packet(InputStream *ist, const AVPacket *pkt, int no_eof) FrameData *fd; av_assert0(!frame->opaque_ref); - frame->opaque_ref = av_buffer_allocz(sizeof(*fd)); - if (!frame->opaque_ref) { + fd = frame_data(frame); + if (!fd) { av_frame_unref(frame); report_and_exit(AVERROR(ENOMEM)); } - fd = (FrameData*)frame->opaque_ref->data; fd->pts = frame->pts; fd->tb = dec->pkt_timebase; fd->idx = dec->frame_num - 1; From patchwork Wed May 31 14:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41922 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328464pzb; Wed, 31 May 2023 07:57:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ncwECqyVwzMafP9VFZtgtwl1vuCeGYkbtPdtZGsYyjYAFr93eeOjwGQ0oIyHXW4Lmk3i+ X-Received: by 2002:a17:907:16a1:b0:973:93e3:bc9a with SMTP id hc33-20020a17090716a100b0097393e3bc9amr5826781ejc.6.1685545053456; Wed, 31 May 2023 07:57:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545053; cv=none; d=google.com; s=arc-20160816; b=jSDfA2LPCXlqoOGlVM9OmKrHk9bkc7VLHkN7fcYD0qz49gBqAwAGa3dxvXsr5ubnzB 0T7D0M7TMDwkvyDf8u/NkuSGFvpqje/8z4VEzQq29b6KbS+SHKlPkYxImtyEhVfqoN4c iPJIDnmGZq3W93FIu76FQ7gyLkCSkoH6112S2kXvk/7e9FRl8rvzTBF4ZNnXvd1V/ISO T+V2WwR1f7s8NvJskaUSA7COntTGMxUX/3RgdjnABgUdukDty9RWrk/ppf7+ZBsdOwQh 2gLFLQ/sztxQeXI4SOg6jnt/GVn7YKU0xEOOM47ZYFwqNXanOX6cWVIoNYdh6rKmx0Mp 8zwA== 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=506dCbj7GJonew0H0Mgt31Z1Shs9Ba3gsqizWHrnmXg=; b=nVUPfwil3IyRLbAp8JWYdzmXBhH/QkN0XPp2zyvvXdYOOshJt5V6veX1429S8EzhAy JW+WYmzKRnx1peBMLs5uFpQXTAk3rec+IdYBQ3GnyJiHFxgOQVMXdLpzGhjqM7iCbhq2 GvUKktcnLLGCZuLG2HGdnEdYV2ki5m6A87SutabFLj6eysiOv2CUOx/KwNcBL+tSY4Q0 9CwwPf/GZ/leRj+eKyqH1arVdk1WaAySlIlMV0oK94DQ4ws3ghs/LJ6ZIGlvHppVhQSB ghBSzWk6jwNy/DYe4eDO3W50/t9ojRPHMVr2UcDgy5KeHto73LeqrQDM2/tpwnFc6IN1 +l4g== 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 z1-20020a1709067e4100b0096f61c20399si2954142ejr.689.2023.05.31.07.57.33; Wed, 31 May 2023 07:57:33 -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 1C48368C300; Wed, 31 May 2023 17:55:29 +0300 (EEST) 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 2AC7668C236 for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id E1E772405EC for ; Wed, 31 May 2023 16:55:08 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id B6fWTpB4NCAo for ; Wed, 31 May 2023 16:55:08 +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 mail0.khirnov.net (Postfix) with ESMTPS id CA6962405F9 for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 812DD3A0C42 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:46 +0200 Message-Id: <20230531145453.20994-16-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/23] fftools/ffmpeg: attach filter framerate to frames 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: M8Hg8NYNNV1G This way the encoder does not need to reach backward into the filter. --- fftools/ffmpeg.h | 2 ++ fftools/ffmpeg_enc.c | 19 +++++++++++-------- fftools/ffmpeg_filter.c | 10 ++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6f71e85658..49c07ede95 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -655,6 +655,8 @@ typedef struct FrameData { uint64_t idx; int64_t pts; AVRational tb; + + AVRational frame_rate_filter; } FrameData; extern InputFile **input_files; diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f6431b29d1..cd2faccf4e 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -217,8 +217,10 @@ int enc_open(OutputStream *ost, AVFrame *frame) case AVMEDIA_TYPE_VIDEO: { AVRational fr = ost->frame_rate; - if (!fr.num) - fr = av_buffersink_get_frame_rate(ost->filter->filter); + if (!fr.num && frame) { + FrameData *fd = frame_data(frame); + fr = fd->frame_rate_filter; + } if (!fr.num && !ost->max_frame_rate.num) { fr = (AVRational){25, 1}; av_log(ost, AV_LOG_WARNING, @@ -1024,17 +1026,18 @@ static void do_video_out(OutputFile *of, OutputStream *ost, AVFrame *frame) int ret; Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; - AVRational frame_rate; int64_t nb_frames, nb_frames_prev, i; double duration = 0; - AVFilterContext *filter = ost->filter->filter; - if (frame) + if (frame) { + FrameData *fd = frame_data(frame); + duration = lrintf(frame->duration * av_q2d(frame->time_base) / av_q2d(enc->time_base)); - frame_rate = av_buffersink_get_frame_rate(filter); - if (duration <= 0 && frame_rate.num > 0 && frame_rate.den > 0) - duration = 1/(av_q2d(frame_rate) * av_q2d(enc->time_base)); + if (duration <= 0 && + fd->frame_rate_filter.num > 0 && fd->frame_rate_filter.den > 0) + duration = 1 / (av_q2d(fd->frame_rate_filter) * av_q2d(enc->time_base)); + } video_sync_process(of, ost, frame, duration, &nb_frames, &nb_frames_prev); diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 1150f6fc65..a2b45a14b8 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1711,6 +1711,16 @@ int reap_filters(int flush) tb.num, tb.den); } + if (ost->type == AVMEDIA_TYPE_VIDEO) { + FrameData *fd = frame_data(filtered_frame); + if (!fd) { + av_frame_unref(filtered_frame); + report_and_exit(AVERROR(ENOMEM)); + } + + fd->frame_rate_filter = av_buffersink_get_frame_rate(filter); + } + enc_frame(ost, filtered_frame); av_frame_unref(filtered_frame); } From patchwork Wed May 31 14:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41917 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328055pzb; Wed, 31 May 2023 07:56:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hYWjsQ9fRAZ4Ezy6ujt7NpZkqgh3kZX56V3KYesYKjLUz6pXUz1jphezhtPoi0ZXicS4m X-Received: by 2002:a17:907:5ce:b0:973:f72f:dfac with SMTP id wg14-20020a17090705ce00b00973f72fdfacmr4957987ejb.67.1685545010637; Wed, 31 May 2023 07:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545010; cv=none; d=google.com; s=arc-20160816; b=uNs8uoeY2834BmhpJpibxHVm2QotQ6FZyYyeSsPH0NBVNELmi4YJfnFgO58ibnSDPC wVPC9SZWXY9LMZ3tDw4WYO//ofFK1st+MH3nUhLxyVR6LG/7ZnuCu17bjdNAIpMg9AcS EDefLVkBnMf2Oyuj6/NUwuDnXb6p0vXr7jM6FfQ+f1YZYAvx2qzMWNbEpdfnyogeqWtr KuurBpSmMgA/aZYziMTGDJywx9SfKj1A4VdfahjdFwYdS/O4FHpr9wEMuxMhyjjJXYvj laLzH2Nj297VnlNBay/3bkTOGedckY46F+qQcaqx54pG5Sb8DirkEtvGbHHo/wPd73fu 3gwg== 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=FR0/Auvt8bKaJC5cCLlqShiZWv+GWCymdynsY91VnVw=; b=yZRSo0u6OQr/MEM/nXnp6Q6vqB6wjRkCd0OzyR4YirX3YXOUj9CnQ86IB1zs5pSQbA K/7gbz1wQwUSmuSNxxUlBS1z0zj4+ZvceGTro17r2DnGXarsAaUUXZR/fs243n7EOSDa ygG/Ohq2RSsZ7iJQm12etmiylD/zAHarKUWvnrAOe/qcDXX6OvEMDmpb2az9joBg8rfw MGweKUkckb9o7BUQa1koaZjwBciuyzhNmhW/FIAu+GFq2xng3OHED4Ff40HU3wUn3UIG adcDlW9jjX/UUE4pz08hj8vIIHWeXLcmr24ZRIu/E6E0pr0aSzMBzTIsO0jZRKfqJkXq Tydw== 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 fy39-20020a1709069f2700b0096f67a4e421si9214961ejc.64.2023.05.31.07.56.50; Wed, 31 May 2023 07:56:50 -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 417A468C2E5; Wed, 31 May 2023 17:55:24 +0300 (EEST) 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 580A168B649 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id B36EA240705 for ; Wed, 31 May 2023 16:55:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id adAFoOzfrwVn for ; Wed, 31 May 2023 16:55:10 +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 mail0.khirnov.net (Postfix) with ESMTPS id F130E2406CF for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8D07C3A0CDD for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:47 +0200 Message-Id: <20230531145453.20994-17-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/23] fftools/ffmpeg_enc: stop using OutputStream.initialized 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: Mes84PwpJ8IO It is set by the muxing code, which will not be synchronized with encoding code after upcoming threading changes. Use an encoder-private variable instead. --- fftools/ffmpeg_enc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index cd2faccf4e..1515ca971f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -62,6 +62,8 @@ struct Encoder { // number of packets received from the encoder uint64_t packets_encoded; + + int opened; }; static uint64_t dup_warning = 1000; @@ -187,7 +189,7 @@ int enc_open(OutputStream *ost, AVFrame *frame) OutputFile *of = output_files[ost->file_index]; int ret; - if (ost->initialized) + if (e->opened) return 0; set_encoder_id(output_files[ost->file_index], ost); @@ -362,6 +364,8 @@ int enc_open(OutputStream *ost, AVFrame *frame) return ret; } + e->opened = 1; + if (ost->sq_idx_encode >= 0) { e->sq_frame = av_frame_alloc(); if (!e->sq_frame) @@ -1123,6 +1127,7 @@ void enc_flush(void) } for (OutputStream *ost = ost_iter(NULL); ost; ost = ost_iter(ost)) { + Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; OutputFile *of = output_files[ost->file_index]; @@ -1131,7 +1136,7 @@ void enc_flush(void) // Try to enable encoding with no input frames. // Maybe we should just let encoding fail instead. - if (!ost->initialized) { + if (!e->opened) { FilterGraph *fg = ost->filter->graph; av_log(ost, AV_LOG_WARNING, From patchwork Wed May 31 14:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41924 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328682pzb; Wed, 31 May 2023 07:57:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+BcqMQakfyHdurBmzw1ugWWoPH93c1zAABuQNgLBUC44D4rw4p+DxajmAGRz3gJBYfmzx X-Received: by 2002:a17:907:1b09:b0:961:a67:29c with SMTP id mp9-20020a1709071b0900b009610a67029cmr4801080ejc.70.1685545070755; Wed, 31 May 2023 07:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545070; cv=none; d=google.com; s=arc-20160816; b=pVe8hmx/dyHlp4Kp3b32YGvAoRSAtzJjWWUH7RC1D7+TOsrkBxNbVc5lQamXVKun4g Gf1xW1ykA8C7VqD2eJCOspSyMheWUloWtsqfiCih+mc/Qk5DUrrffxI6lEFSZZPt5RU5 KuGsEq8dP4NqPVOkr+Oo4qoAKKIaXrTzNxpqOpSztgyVa3nhQZVMBZYG0P5jpChto2ur 4TWfwGB4E50AokcQUBvu4ntBYJ6HFlAYDOfPFLsZE1LstxNlkDgq4f71nas9U4iJVSx8 Ui9YXvR2D43Sr75q4v29SU51nSBtxRth+3sqHdHEwyU9id4FZ87S2baZN+ROtATVOaEW TIxw== 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=MpZthtuYGh3MaCDYUPpTANxM+zJAwDVeaIKQrPAusO0=; b=fQjJE1dL0VPCE91g0pEq2RVW56YuJxaGttjVIXo4CrgC1bOsqoxdptlwkUTgc+5AGi tBvt1gSGeHMaDE95ukEVU9sAJk1UuG5WY6wNTG0ZO/ApLX/OHIBVNFWPeYhZ55e0C8OW PeBEXlISxT085kcHjUyCcZNDbR6/YnPy5VpernhCk2pY9jdj0582myLq7ELuBeKOVf/d akoM5Zb31dep/SCaXoh5V1CIA7rTBbiZpJ9nQCGf5pOB/aeMA43RsVeHYKE7KX2gBgdW Ep4KpZW3z/ovBg3/qGRIVFnAiuCSqMUb/zgpT1IIswsUrfbacysFTLAMHGtGaxCIbYao 8fRA== 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 qu13-20020a170907110d00b0096f5dc867f4si6723058ejb.203.2023.05.31.07.57.50; Wed, 31 May 2023 07:57:50 -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 1D93768C301; Wed, 31 May 2023 17:55:31 +0300 (EEST) 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 9D37A68C2A3 for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3207C2405F9 for ; Wed, 31 May 2023 16:55:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id VKg5DVGXtzzn for ; Wed, 31 May 2023 16:55:08 +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 mail0.khirnov.net (Postfix) with ESMTPS id D26AB2406CA for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 98A353A0CE0 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:48 +0200 Message-Id: <20230531145453.20994-18-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/23] fftools/ffmpeg: simplify handling input -t for streamcopy 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: +hcCiGCcnsgz Output stream will be closed implicitly after a NULL packet is sent to it, there is no need to explicitly call close_output_stream(). --- fftools/ffmpeg.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 9997881572..7d2a25f2bf 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -785,7 +785,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo int64_t dts_est = AV_NOPTS_VALUE; int ret = 0; int eof_reached = 0; - int duration_exceeded; if (ist->decoding_needed) ret = dec_packet(ist, pkt, no_eof); @@ -797,7 +796,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo dts_est = pd->dts_est; } - duration_exceeded = 0; if (f->recording_time != INT64_MAX) { int64_t start_time = 0; if (copy_ts) { @@ -805,7 +803,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo start_time += start_at_zero ? 0 : f->start_time_effective; } if (dts_est >= f->recording_time + start_time) - duration_exceeded = 1; + pkt = NULL; } for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { @@ -813,11 +811,6 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo if (ost->enc || (!pkt && no_eof)) continue; - if (duration_exceeded) { - close_output_stream(ost); - continue; - } - of_streamcopy(ost, pkt, dts_est); } From patchwork Wed May 31 14:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41916 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327982pzb; Wed, 31 May 2023 07:56:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cF+XTA/uMc/O68ehnKQE7mbktrr82DdFWqj8KtdwN7T03WxrRTnMmlBiSdxZko1spgRJU X-Received: by 2002:aa7:c04e:0:b0:514:a454:175b with SMTP id k14-20020aa7c04e000000b00514a454175bmr6080177edo.6.1685545002111; Wed, 31 May 2023 07:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545002; cv=none; d=google.com; s=arc-20160816; b=QgTK5RVSW+LRdcwzHMheVyQQ3RRk+8hJl5Xb3HEoiSjzYxFqI2A6ObJEVEGnZZuth1 vih0SqbCFL23/pDk7wFRH/xTiXpYePOi/5C+Mh3OMcUWFs06vBPmz0ufaq98S5XX/6jh m/+4uujEv5lHa0d4YD6TV0FSE2mLyJTcTlSwXAC6X9uAu+zpP7Wb9iXcd1P50vmVEhnx t3MN8dD+IhWjVF38rbaIUYhAa9ub1FKKjU7DBesx7TYsNvAKzES7MA24WOjOPdkD8Bzy KyroKrgpoMkyldcgq7X8D0Bx5xkn/CbZXmA/Ge7f95rlSiwJ7wb1pZX0Pcz+xmFwUPgx kJTQ== 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=4UHqIsaWikfmlhvP1AZT85MEQdzgZtUKFYhbzs5fMLg=; b=iTxgJOq87Cwh2RJImBhwEWAV7FaxODcEFA0eRoteLma1bndBbUamPa9jZNgahQ4Wes TfPCMKMQLBoRGKiVNUFcWwbyh9hRJcO3FqIXJzq9UfUmOpw4U7WsdI0qSIqwf5iPhOQj nDCqODXGxG2aXNu7eCm/lvhkibciinacIal9GGj5uK8paILGkEwJvBJ3PN1aYA8HIs8V JI8RJAJWRhelVC9QzUqS8uHjaFhYpgdLTgOOWs1jySaC6yRCIyGKaZWf22UT4iGiS5+g lhPU8WfD7CoEXPX2Hm0fXTy3LCxr1LrIrPUxJS+vr4C8Sv5h9XqQ+dpUjwaz75Xp4oi3 eIvA== 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 y18-20020aa7d512000000b0050bc94fe05csi3516955edq.117.2023.05.31.07.56.41; Wed, 31 May 2023 07:56: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; 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 4226168C2D6; Wed, 31 May 2023 17:55:23 +0300 (EEST) 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 5817B68C253 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 5DAD82406D0 for ; Wed, 31 May 2023 16:55:11 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1ECFoSFIDl-8 for ; Wed, 31 May 2023 16:55:10 +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 mail0.khirnov.net (Postfix) with ESMTPS id 0CD06240705 for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A44593A0D13 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:49 +0200 Message-Id: <20230531145453.20994-19-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/23] fftools/ffmpeg: stop explicitly closing output streams on input EOF 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: mauyAONDMc38 Sending an empty packet already does that implicitly. --- fftools/ffmpeg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 7d2a25f2bf..462365ed02 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1104,7 +1104,6 @@ static int process_input(int file_index) for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { OutputStream *ost = ist->outputs[oidx]; OutputFile *of = output_files[ost->file_index]; - close_output_stream(ost); of_output_packet(of, ost->pkt, ost, 1); } } From patchwork Wed May 31 14:54:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41925 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328751pzb; Wed, 31 May 2023 07:57:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uPwWaKUaMi71tGv+OXQmmA7BSFW5gWt7UbOKGhjW9Okk+vmfW106lvLei5Q1Ud9i/Os70 X-Received: by 2002:a17:907:7ba7:b0:974:1f8f:89d7 with SMTP id ne39-20020a1709077ba700b009741f8f89d7mr5865251ejc.31.1685545079569; Wed, 31 May 2023 07:57:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545079; cv=none; d=google.com; s=arc-20160816; b=oUmyBm+FvexKkkzBqWtsQW6MSKzR9cQKSsGMIaF380kxplYuLjKI7krWC13zwQnX4a ihsqofWywPiTAdYXSQf+6QiDyIoG3lm3bfFaeBAHO1OYNLpOkSDQcs/BoDRu35PYM4Wv DyIVd2LdJK1jL8oMGfPxfYHYt+0eOIoWoN2HKVYv0IEseruwe/lffhg/O8McW+s+xjvL x6ICy9IusFv/5Ra5VUxbRwXavSQB++VK1841wnWBmt5YCdektQuziDdolrFEu5iD2Kze 3mHFvWMrnRKZU2DIwFgTHCXAyNBtnAuf73um5oVvElCSOqdnIbHgToyCpnfwX1wm02Hz uN1g== 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=SS0pqJrB0R9FeUpW5YcMWRkV3oK4taA4M8+5fIl0xew=; b=Ng6ZOhtduqOUU2TqeBYgW8V2ARpTxjchjRLHgm6jBMMf80GsQxgrLRR1P3YMMAAHPw vKpOJsH3GgRyoJzVg+QE7TQ0bNAU3Na9Zg6sfJpbDIjGpESLlCWFwbvw0w/0aSDdO1zF msUHW3q47+sO1jUMoCHskgc56VdGkR7lYqzuDM7NCLVAZf9twv8h116Eoio/g2JFxBSQ ZEUyN6pl24loHbMbJWlLOwDicT7KLCwsP05UsfYpsI9cFJzBu0QdPLOLoPgn3UuChNhn 3fdGuWRT4PtKc4IXEOypPRXTLVbaZlJ7RnJD3Q5NSw+jttt5IOKkk8IkU/mY+WHMJOZ2 AUDw== 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 w6-20020a170906480600b0096f51d88e5fsi7503717ejq.825.2023.05.31.07.57.59; Wed, 31 May 2023 07:57:59 -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 079F468C30E; Wed, 31 May 2023 17:55:32 +0300 (EEST) 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 A967B68C28F for ; Wed, 31 May 2023 17:55:12 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 6D9EC2406CA for ; Wed, 31 May 2023 16:55:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xMhxJSFMbZsv for ; Wed, 31 May 2023 16:55:08 +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 mail0.khirnov.net (Postfix) with ESMTPS id DD97C2406CB for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B019A3A0D6F for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:50 +0200 Message-Id: <20230531145453.20994-20-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output 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: 8bTQhGcpaIhA Currently of_output_packet() reuses the input packet, which requires its callers to submit blank packets even on EOF, which makes the code more complex. --- fftools/ffmpeg_mux.c | 9 +++++++-- fftools/ffmpeg_mux.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index dc2d189ff0..485f499971 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -351,7 +351,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) } while (!bsf_eof) { - ret = av_bsf_receive_packet(ms->bsf_ctx, pkt); + ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt); if (ret == AVERROR(EAGAIN)) return; else if (ret == AVERROR_EOF) @@ -361,7 +361,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) goto fail; } - ret = submit_packet(mux, bsf_eof ? NULL : pkt, ost); + ret = submit_packet(mux, bsf_eof ? NULL : ms->bsf_pkt, ost); if (ret < 0) goto mux_fail; } @@ -656,6 +656,10 @@ static int bsf_init(MuxStream *ms) return ret; ost->st->time_base = ctx->time_base_out; + ms->bsf_pkt = av_packet_alloc(); + if (!ms->bsf_pkt) + return AVERROR(ENOMEM); + return 0; } @@ -856,6 +860,7 @@ static void ost_free(OutputStream **post) avcodec_parameters_free(&ost->par_in); av_bsf_free(&ms->bsf_ctx); + av_packet_free(&ms->bsf_pkt); av_packet_free(&ost->pkt); av_dict_free(&ost->encoder_opts); diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index bee7addd6a..ad7b1df8a7 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -44,6 +44,7 @@ typedef struct MuxStream { AVFifo *muxing_queue; AVBSFContext *bsf_ctx; + AVPacket *bsf_pkt; EncStats stats; From patchwork Wed May 31 14:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41929 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3329100pzb; Wed, 31 May 2023 07:58:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5safCN12j9D0seKMubTOs6kBQgbynaGs1+Zw7wr3Lg63ZS8Suz9ZcvzmSBclYKvNpf+xzJ X-Received: by 2002:a17:907:6d12:b0:95f:969e:dc5a with SMTP id sa18-20020a1709076d1200b0095f969edc5amr12491425ejc.30.1685545114948; Wed, 31 May 2023 07:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545114; cv=none; d=google.com; s=arc-20160816; b=yaWWgSSh5JgwcSbTiZdQUD3wHzm2aZo7i2yOlsHUzMArGxmQ+LRT7oEIWbzl/E/TBP x/5mYJtYvRLkf0bnYg2qF91tskKfeJ+Oniy8gAoUORSPLfLgGCsNzxPyhnelXMUP3XMQ +roJOSFcP1oXner7mjDNe+P2Hm01MT1zRuNLnSvAFeNajFik/FpkZOFNnBtvFlAkOgh4 RjMqGFE+hwngLvBmhLemN6lxZJvaclS+SW1dd9n0OL8sq+xUZC3ZAkulKPrlFu+GR8Yl vAYQuKduoctA+J8i0kXPXU4SjaAFcvFOBP77Kr0mEahb/5/8fWkX90FcNXHwGrI7j1sE y3oQ== 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=awiPIlPBZ/AVc0cbyjNc+3ub1z3ARcGzc1FhqcAxRHo=; b=yMjoLuElsJPwODx77ZWu4CdOWiXl/BW3qrr2maNLAguP4Ti0S0KaL1vMBORedEwMDV GCzxmOd85k82E4iSq+Y6uEYopa++GC2SYKGUDK+Uc2wpWp3ddg18+uXJsR6C0c46wJhW 0QMKplb2n9VLYx9cXhgc3xFHWW5TXfn+CcdlGNjQE84ZQ/rUCkJZDtebSikruGUQyKuN WnCouH0satlA+BK9Ha5Y5xhq4M8jXp9eU4N6RjWi1Y51K0dxUByxnWT0hOKSjDSd5iDj lhzrEsmaj1b/uJj+B3TJbefE7nYuk77LgKLH3Jrfiub0r5XpNlcRKNciEnCjuM7ndKpD uzHA== 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 wj4-20020a170907050400b0096fc165a359si10435351ejb.497.2023.05.31.07.58.34; Wed, 31 May 2023 07:58:34 -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 AB64068C326; Wed, 31 May 2023 17:55:35 +0300 (EEST) 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 85D8068C2B4 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 481BD240177 for ; Wed, 31 May 2023 16:55:13 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ylGoT8BtB10C for ; Wed, 31 May 2023 16:55:12 +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 mail0.khirnov.net (Postfix) with ESMTPS id 35275240D0E for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id BBA6D3A0D86 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:51 +0200 Message-Id: <20230531145453.20994-21-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 21/23] fftools/ffmpeg_mux: simplify calling of_output_packet() 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: sSAyngW2dax+ Use NULL packets to signal EOF instead of a separate variable. This is made possible by the previous commit. --- fftools/ffmpeg.c | 2 +- fftools/ffmpeg.h | 13 +------------ fftools/ffmpeg_enc.c | 6 +++--- fftools/ffmpeg_mux.c | 14 +++++++------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 462365ed02..79baceb1fc 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -1104,7 +1104,7 @@ static int process_input(int file_index) for (int oidx = 0; oidx < ist->nb_outputs; oidx++) { OutputStream *ost = ist->outputs[oidx]; OutputFile *of = output_files[ost->file_index]; - of_output_packet(of, ost->pkt, ost, 1); + of_output_packet(of, ost, NULL); } } diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 49c07ede95..890081edb4 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -844,18 +844,7 @@ void of_close(OutputFile **pof); void of_enc_stats_close(void); -/* - * Send a single packet to the output, applying any bitstream filters - * associated with the output stream. This may result in any number - * of packets actually being written, depending on what bitstream - * filters are applied. The supplied packet is consumed and will be - * blank (as if newly-allocated) when this function returns. - * - * If eof is set, instead indicate EOF to all bitstream filters and - * therefore flush any delayed packets to the output. A blank packet - * must be supplied in this case. - */ -void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof); +void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt); /** * @param dts predicted packet dts in AV_TIME_BASE_Q diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 1515ca971f..8dd8104cea 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -531,7 +531,7 @@ void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub) } pkt->dts = pkt->pts; - of_output_packet(of, pkt, ost, 0); + of_output_packet(of, ost, pkt); } } @@ -718,7 +718,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) av_assert0(frame); // should never happen during flushing return 0; } else if (ret == AVERROR_EOF) { - of_output_packet(of, pkt, ost, 1); + of_output_packet(of, ost, NULL); return ret; } else if (ret < 0) { av_log(ost, AV_LOG_ERROR, "%s encoding failed\n", type_desc); @@ -752,7 +752,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) e->packets_encoded++; - of_output_packet(of, pkt, ost, 0); + of_output_packet(of, ost, pkt); } av_assert0(0); diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 485f499971..879a291ba9 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -324,18 +324,18 @@ static int submit_packet(Muxer *mux, AVPacket *pkt, OutputStream *ost) return 0; } -void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) +void of_output_packet(OutputFile *of, OutputStream *ost, AVPacket *pkt) { Muxer *mux = mux_from_of(of); MuxStream *ms = ms_from_ost(ost); const char *err_msg; int ret = 0; - if (!eof && pkt->dts != AV_NOPTS_VALUE) + if (pkt && pkt->dts != AV_NOPTS_VALUE) ost->last_mux_dts = av_rescale_q(pkt->dts, pkt->time_base, AV_TIME_BASE_Q); /* rescale timestamps to the muxing timebase */ - if (!eof) { + if (pkt) { av_packet_rescale_ts(pkt, pkt->time_base, ost->mux_timebase); pkt->time_base = ost->mux_timebase; } @@ -344,7 +344,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) if (ms->bsf_ctx) { int bsf_eof = 0; - ret = av_bsf_send_packet(ms->bsf_ctx, eof ? NULL : pkt); + ret = av_bsf_send_packet(ms->bsf_ctx, pkt); if (ret < 0) { err_msg = "submitting a packet for bitstream filtering"; goto fail; @@ -366,7 +366,7 @@ void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof) goto mux_fail; } } else { - ret = submit_packet(mux, eof ? NULL : pkt, ost); + ret = submit_packet(mux, pkt, ost); if (ret < 0) goto mux_fail; } @@ -399,7 +399,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) // EOF: flush output bitstream filters. if (!pkt) { - of_output_packet(of, opkt, ost, 1); + of_output_packet(of, ost, NULL); return; } @@ -453,7 +453,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) } } - of_output_packet(of, opkt, ost, 0); + of_output_packet(of, ost, opkt); ms->streamcopy_started = 1; } From patchwork Wed May 31 14:54:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41913 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3327683pzb; Wed, 31 May 2023 07:56:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7KmBKuEq00/muQjhUQoSH+YQoplUq4FJlkGb+CUrqoIJLNmRlxSQWYO56uoOTzqUnR0tk/ X-Received: by 2002:a17:906:6a18:b0:96a:30b5:cfac with SMTP id qw24-20020a1709066a1800b0096a30b5cfacmr5156704ejc.28.1685544976210; Wed, 31 May 2023 07:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685544976; cv=none; d=google.com; s=arc-20160816; b=t8T6on/b9j1DZT+QFZ5J6ItBeQ8RmwBlH0B+HakK+Sw+7EEFKvHpw7iqq+mzS7eLSZ 1v7tZirSj1d/CYOA2eQiWt1BRylwitu9KqBuvcMOV/lgVii69JpnWAUet4qzl5rR3COg Uk+octe5xkGB6mB3bPSKhevQgVT1pzHg52HFBWJxDDUN3kalp57TiTgqGOh8OReRh7D8 B4oUrgnppXz/mUbfVPl0zgEDSYdyXGSNsc3AwrhD0kJryh2rJFqbThBuj/+FH6ySgcO8 k1e6UR0iFJBkUrwYWT5XjCxZVzhA5CByKDqe8kNKHCeyKqdoucHAd2djyff1xuMsREWt 0Thw== 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=QQmBDG4yPRHUkV5AAldUgAsoT/5GkEQZsOiMkwE1CKQ=; b=wVqXZVP9+JyZSe30nxFCEe980R0ji44XLJLJ18Qzd+SMQf5lkMjNJbiZAKBA8DCeWI KvW3QhYhyGoGxWUXxCOggGn0nMwIr4bCiqyU0pqEeh7jCcJzeA2cPplzZUqrVuTFZ66l 0p+EeNSi1GEhUVNoGfb3oB/UpK2wx507wyQ5e88iHaVGEVKJ/vk/BTvqRD9Cpm7Wnu/c ccb3SaVwhZ6mjFo5gQc/f6oLhoWkBHiR1zRkluKBs/E0yw4qntg+azRXWVfL6rdZnMYE BH5wI18PPJOGlm55DIk9JzAllVmU6USy+cjTOODK7rLd44KL7qURbQNbOrLeZ6gPpS7N NyWg== 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 s18-20020a1709064d9200b0096a7839c72bsi1134708eju.700.2023.05.31.07.56.15; Wed, 31 May 2023 07:56:16 -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 3C3C068C299; Wed, 31 May 2023 17:55:20 +0300 (EEST) 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 1CD3168C253 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id EF8902406CD for ; Wed, 31 May 2023 16:55:09 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id C9uQRIoNymUa for ; Wed, 31 May 2023 16:55:09 +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 mail0.khirnov.net (Postfix) with ESMTPS id E52442406CC for ; Wed, 31 May 2023 16:55:05 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C766F3A0D97 for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:52 +0200 Message-Id: <20230531145453.20994-22-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 22/23] fftools/ffmpeg_enc: use a private AVPacket instance for encoding 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: cLgGad65Qm57 The code currently uses OutputStream.pkt, which complicates its ownership semantics. --- fftools/ffmpeg_enc.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 8dd8104cea..2bf4782a9f 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -57,6 +57,9 @@ struct Encoder { AVFrame *sq_frame; + // packet for receiving encoded output + AVPacket *pkt; + // combined size of all the packets received from the encoder uint64_t data_size; @@ -78,6 +81,8 @@ void enc_free(Encoder **penc) av_frame_free(&enc->last_frame); av_frame_free(&enc->sq_frame); + av_packet_free(&enc->pkt); + av_freep(penc); } @@ -97,6 +102,10 @@ int enc_alloc(Encoder **penc, const AVCodec *codec) goto fail; } + enc->pkt = av_packet_alloc(); + if (!enc->pkt) + goto fail; + *penc = enc; return 0; @@ -454,10 +463,11 @@ static int check_recording_time(OutputStream *ost, int64_t ts, AVRational tb) void enc_subtitle(OutputFile *of, OutputStream *ost, AVSubtitle *sub) { + Encoder *e = ost->enc; int subtitle_out_max_size = 1024 * 1024; int subtitle_out_size, nb, i, ret; AVCodecContext *enc; - AVPacket *pkt = ost->pkt; + AVPacket *pkt = e->pkt; int64_t pts; if (sub->pts == AV_NOPTS_VALUE) { @@ -669,7 +679,7 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame) { Encoder *e = ost->enc; AVCodecContext *enc = ost->enc_ctx; - AVPacket *pkt = ost->pkt; + AVPacket *pkt = e->pkt; const char *type_desc = av_get_media_type_string(enc->codec_type); const char *action = frame ? "encode" : "flush"; int ret; From patchwork Wed May 31 14:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 41927 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp3328925pzb; Wed, 31 May 2023 07:58:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4WQTMFZjit4Qd77h9PU1UJj3bx/O1IwYAlZb0cew8ZbZdoHbN0RtFd3d/n5vANfUJkxMBH X-Received: by 2002:aa7:c902:0:b0:514:95ce:fb24 with SMTP id b2-20020aa7c902000000b0051495cefb24mr3883685edt.40.1685545097831; Wed, 31 May 2023 07:58:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545097; cv=none; d=google.com; s=arc-20160816; b=BwJlTHVjttt73U8bqmtgMTiGc4UMJGab6jvZ7FSN7ezocLfRDyZ99CgtEIj+3nzhN1 7AXZFSf5wV3AjpjkJiU4UZX7x+r+aeDU0qESZFXwf/3aTEQMMZPcmrHp8su3V4pQtICS e7WqvSfNyCyfRWN8xF8UYFZkdM1xqS7cVnAiJzCnpjR+/aCe263DwI2zju7vMLRwaMU3 4XarVSVC0AqHYvAThiqpSD9RJNfw1mbLi4ilN0xNPnYqSdBjo5i6Zl7S4QikYHkrYw7o HgBlp2x45riBXrXXnyHG9YkolMIitUINK3AV4cAL2SH1WGT6XUeQWwA60IMgxzF7ATYX w9uA== 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=TW6kS2odAN8S2QtjKf9j6IfGy4e9x7L+XDX2rte1XK4=; b=0hvS8OXxtxsYQXVGRXMpSlKrmvGvyBT5Pw9rE4QxbibPljZsORAFgL/Va1sajfWjHY Z9f1zlF/Z7ryHMR7/xW/2pMqERr7ZUjAkSOvMVozAx4eKXkFpIknYfHXMIBRvmIMRcry 4AKEJuVS4yh4m78QaMYjcBymsa6kY+UcFgQ4npKsILndGhafoPkrvvhLcdQq/Nil1q1J 6tq47REzKLnfDYmiFs4sH2z2NvgyN57WmU5XqlK+6CVEt+5ym9VFK0URthUrhiE2J0Pv tqZDCwfbXnys8wKMP3/HXoCgrlDpAGZ+wK9RvD9mep4Uzk0mtzV7HgtVdgzIu8qVLrUu STUQ== 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 o26-20020a056402039a00b0051494c50054si2383196edv.537.2023.05.31.07.58.17; Wed, 31 May 2023 07:58:17 -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 CA5D268C319; Wed, 31 May 2023 17:55:33 +0300 (EEST) 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 81BDA68C2A6 for ; Wed, 31 May 2023 17:55:13 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 05D622404F5 for ; Wed, 31 May 2023 16:55:13 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id M56D7C8Nc3xc for ; Wed, 31 May 2023 16:55:12 +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 mail0.khirnov.net (Postfix) with ESMTPS id 4011E240D1C for ; Wed, 31 May 2023 16:55:06 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D32D53A0DAB for ; Wed, 31 May 2023 16:55:00 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 May 2023 16:54:53 +0200 Message-Id: <20230531145453.20994-23-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230531145453.20994-1-anton@khirnov.net> References: <20230531145453.20994-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 23/23] fftools/ffmpeg_mux: make OutputStream.pkt private 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: FbEG8ioqcJty It is no longer used outside of muxing code. --- fftools/ffmpeg.h | 1 - fftools/ffmpeg_mux.c | 4 ++-- fftools/ffmpeg_mux.h | 2 ++ fftools/ffmpeg_mux_init.c | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 890081edb4..88e3516243 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -551,7 +551,6 @@ typedef struct OutputStream { Encoder *enc; AVCodecContext *enc_ctx; - AVPacket *pkt; uint64_t nb_frames_dup; uint64_t nb_frames_drop; diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 879a291ba9..66b2324bb3 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -389,7 +389,7 @@ void of_streamcopy(OutputStream *ost, const AVPacket *pkt, int64_t dts) MuxStream *ms = ms_from_ost(ost); int64_t start_time = (of->start_time == AV_NOPTS_VALUE) ? 0 : of->start_time; int64_t ost_tb_start_time = av_rescale_q(start_time, AV_TIME_BASE_Q, ost->mux_timebase); - AVPacket *opkt = ost->pkt; + AVPacket *opkt = ms->pkt; av_packet_unref(opkt); @@ -862,7 +862,7 @@ static void ost_free(OutputStream **post) av_bsf_free(&ms->bsf_ctx); av_packet_free(&ms->bsf_pkt); - av_packet_free(&ost->pkt); + av_packet_free(&ms->pkt); av_dict_free(&ost->encoder_opts); av_freep(&ost->kf.pts); diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h index ad7b1df8a7..7f34b86548 100644 --- a/fftools/ffmpeg_mux.h +++ b/fftools/ffmpeg_mux.h @@ -46,6 +46,8 @@ typedef struct MuxStream { AVBSFContext *bsf_ctx; AVPacket *bsf_pkt; + AVPacket *pkt; + EncStats stats; int64_t max_frames; diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index c49f906dc7..a18320fa9b 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -1064,8 +1064,8 @@ static OutputStream *ost_add(Muxer *mux, const OptionsContext *o, else av_assert0(0); av_log(ost, AV_LOG_VERBOSE, "\n"); - ost->pkt = av_packet_alloc(); - if (!ost->pkt) + ms->pkt = av_packet_alloc(); + if (!ms->pkt) report_and_exit(AVERROR(ENOMEM)); if (ost->enc_ctx) {