From patchwork Wed Mar 6 11:03:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46837 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313145pzb; Wed, 6 Mar 2024 03:06:00 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXXcPnzlgU4iaJwLg4HRvB6mz8ohM/K+r8L00WcG2NaLIzIR04gFTCcUZtk17pJPdYw1YTRn106yvO9BEfTowiMVWUVPvbYvQdHrA== X-Google-Smtp-Source: AGHT+IHgjRFuT1eyl/1BPICfcGaStyPPiZPFFKv08nOtTzT/B96fRQIavy60yG4p673zWbtv9NNw X-Received: by 2002:a17:906:1d5a:b0:a44:48c5:85f6 with SMTP id o26-20020a1709061d5a00b00a4448c585f6mr10397440ejh.43.1709723160044; Wed, 06 Mar 2024 03:06:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723160; cv=none; d=google.com; s=arc-20160816; b=OsQ74fjwOW/kqKXumJsE9ZdZR2jUzIHmUzBbi8C1n5imSR0QULZ5CxzOQlys6GLsCl rrmAeLEvU9PnbxNru5qWVklnS6GqaH7BFcNJIA+YzNdnJwYojDCWQ+Py+OUB9CdNJqXN 3kX470rTaW9aBWZwVafj4YAnTAFW1qBqGDCDLdh4b9bwmWle+zSheNKS4Szlyzz9c8Rw qfd521bDWCxLVW4PwClqqStdNlQ/8ZMzyrsPAV30bXZDE6wGjuBU3E1raN8KSKmCXWXV VzT3dEDd8CVqsj2SZkqhqja8uBx4ijgR7xr+aIzdouwJ+JeqOK+ue6eNDi5we54nQaje 0YqQ== 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 :dkim-signature:delivered-to; bh=A0rhVNVHU6m2tWQCiWm7edDhyszkCcODltkmvuQesFo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cL2X5uqnIKRxhpuWTCjv3NGHcc1osTXQtht/07HY5RLiBSDX+uglBG5PEJPyQ3edpZ ow6vDBdsQBESgRcQ5bodTD8n7oIOAMDvQ8J19xBP1yiuEdO/Wtiz0kBapVWDAWnHZb4Q i9Lr9E2cxnA4x4HLRLKGO8+eFk1sFsILLrEja1fFTuov69EvlKP6kvTgj4uf4Ijp0qWi TP/kkdVhlFscbOr5HhuYAUE72GHNrg9IFu5r/rep7umpsItqg+cO7Ut39RNpS650dPsp s9IXiwLfXiu2LbrlZ5Qr7ZgvO1svmbq2ixBjccsSIRWXq+lZdYgJ/a03jCb4j7imSsVl 1LCw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=sXN1ICLy; 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 i20-20020a170906265400b00a3e82455348si5981810ejc.858.2024.03.06.03.05.59; Wed, 06 Mar 2024 03:06:00 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=sXN1ICLy; 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 3C21068C462; Wed, 6 Mar 2024 13:05:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1105168BC64 for ; Wed, 6 Mar 2024 13:05:25 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=sXN1ICLy; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id B4CD44D44 for ; Wed, 6 Mar 2024 12:05:24 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id oMZ5Rb_ZbIjU for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=q/fnpy1q3qKyM30/4PNnI0in/Nsiz56cseX65o93XgI=; h=From:To:Subject:Date:From; b=sXN1ICLylHXzZMH7z0ClXrVKqRckBPcOSh/d5kI26rEfgHrtSXCVlyaV2/r/gz+4r aDtLiQGQdrrK1cjgRzsIOa4FOvxYEmPiS4OVtPEvVL1HtXFLTNKOBOCk0x/u7EAceA O7M2S52rLs6bLZgbBPmw2VunHz2W3CW38jVgeL4E2bFpaFwsGDWnkXTaEZdrWEytas W6df1j+AaZhlIaiOX6+t9XekX3zpq9FqWBoVgCHmNJAhXz1nPmU7aahu8NsYDHKDtC WCSlPXpKPAAVwesgIc676gskucpBWEN8s42BIN4EQBOVV/83O8v/0YNE1j6xGXbvkX QReJU0O6s3atQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id AFCA54D41 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8097B3A0357 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:02 +0100 Message-ID: <20240306110319.17339-1-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/18] fftools/cmdutils: fix printing group name in split_commandline() 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: Z47SpApTzkHZ --- fftools/cmdutils.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 008949a39d..8efec942bd 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -793,7 +793,7 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[], while (optindex < argc) { const char *opt = argv[optindex++], *arg; const OptionDef *po; - int ret; + int ret, group_idx; av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt); @@ -822,14 +822,15 @@ do { \ } while (0) /* named group separators, e.g. -i */ - if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) { + group_idx = match_group_separator(groups, nb_groups, opt); + if (group_idx >= 0) { GET_ARG(arg); - ret = finish_group(octx, ret, arg); + ret = finish_group(octx, group_idx, arg); if (ret < 0) return ret; av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n", - groups[ret].name, arg); + groups[group_idx].name, arg); continue; } From patchwork Wed Mar 6 11:03:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46840 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313453pzb; Wed, 6 Mar 2024 03:06:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUsspQxlRxBY+qJGE8URSxFjQWD7el0Mmk91piaZAj0lwBNzXaVyUZENxZyRSyrioS+CbWbOTiLAZY9hvaES6IVdIcj1yvk2bdUXQ== X-Google-Smtp-Source: AGHT+IG8MopW4BqzW7qFwzFHITe1vbEohZzczShN0x1O5qAAC3Fu2D5DU+f/fj2gyYJEaIl9KTKb X-Received: by 2002:a17:906:d9c3:b0:a45:b30c:1aee with SMTP id qk3-20020a170906d9c300b00a45b30c1aeemr1764612ejb.41.1709723191828; Wed, 06 Mar 2024 03:06:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723191; cv=none; d=google.com; s=arc-20160816; b=E2KK5dm3O5FHxR8Z/DuV0uLrRp2/9dj8YqhOVWOuFRkArLIqdSsFhyOxZ9T7MFyo+x STrMjuTo0vEwYOmfh4F6nqFQA7PLt14DH+hCCgMcZJSp4t74y9tekRCRb3sngisbyUkk LaYNFaSxEvGAhLxoXdMK1XkiC9obL78ZVh0KX1vTNRXHFjdkKAMj6vTfEZPLdM+IEqdW HCktGYL00CBuGVieXoWLitEFep636AWcnVoHM+bhIUnzAZYVEiiUBbeF5oLx34HxMvQJ VdMZbBy4IFXRTTTI5V+zDmzYUPshGs9ENALc2dCcktXz3szxrKRyZRXhcEBYDczwIt6i I3hA== 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:dkim-signature:delivered-to; bh=jTQDlLvI65DtOz7ehr5Ml5dOfcHcS/35Rh3w+Kc17a8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=vi8gRIUh/eSAJqCduuS5ePW+DZwq3ZotwtBKkuFUhi6LDAJGMIqU291G/lonwc9vTI fZOZMutnWgnvOtDpjgLCYf4N1RyUM00PnZYUD5lEZHekOCkqkMzyqfgeQSyf6GyKtdna AcD+XaqB65M16c6bCvI/rjrGfA36Os0CHIvS/6KA1A42gj62qO869RAtihZP9HXkUTKf JEzaNjqBhHnE5roNmf19YkWOWpfH9uN6uzVgvYDSp5t9JQf31cfZPQOItcc0cWPh+vu7 IsLuQgVRV+A2Xb0aa21W7IB/WoNGHJQk4mwGL9TUSVNrUDU84wIC79Ye5qnLWR2c3q/k pfyA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=apFl5YRa; 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 ht14-20020a170907608e00b00a44dd8b250csi4192647ejc.253.2024.03.06.03.06.31; Wed, 06 Mar 2024 03:06:31 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=apFl5YRa; 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 AA98F68BE7C; Wed, 6 Mar 2024 13:05:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 920AF68C97D for ; Wed, 6 Mar 2024 13:05:25 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=apFl5YRa; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3F5124D49 for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id wEugiLWhRnrY for ; Wed, 6 Mar 2024 12:05:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=sZMq5NIXSrqk0AkVhN3pFa8e3+cHUfIROKCCJYs1T5c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=apFl5YRa6krY+0kDn/7+k9AH5pHpzv8UqZgk2sDyVO1Gvwyw8vXFkbaRBHQXjt57M OyM4o67HXia7lpfqAPw2mzxpPehJySzDXjq2KSw/3jBRCeb9Vy1K9xBreFKx+k9IKf p62U2AD67ssKxRlwpq42u5gV4rcr1TKwNqx37MxAgZkf5xZR+4LP1ckGB2Rha7mzc6 EvUqQvQmHWxbxpuyzkdpz/ID3S47143IwbQ31IGY2AthCuKeK3O0nnpy+1UWzA2REj FPNyD7WYbXdx/zx3QXebTdn4nIX/FStfSMvJwiXw6R0lNk6PFraBOryMwaGwJojvtc VGugFOXQQlvjA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id A6B3C4482 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 8DB2E3A0582 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:03 +0100 Message-ID: <20240306110319.17339-2-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/18] fftools/ffmpeg_filter: refactor setting input timebase 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: Zk/Kfd/3BsbT Treat it analogously to stream parameters like format/dimensions/etc. This is functionally different from previous code in 2 ways: * for non-CFR video, the frame timebase (set by the decoder) is used rather than the demuxer timebase * for sub2video, AV_TIME_BASE_Q is used, which is hardcoded by the subtitle decoding API These changes should avoid unnecessary and potentially lossy timestamp conversions from decoder timebase into the demuxer one. Changes the timebases used in sub2video tests. --- fftools/ffmpeg_filter.c | 17 ++- tests/ref/fate/sub2video_basic | 182 +++++++++++++------------- tests/ref/fate/sub2video_time_limited | 8 +- 3 files changed, 106 insertions(+), 101 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 13c5065191..9d9762a599 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -148,6 +148,8 @@ typedef struct InputFilterPriv { // fallback parameters to use when no input is ever sent struct { + AVRational time_base; + int format; int width; @@ -696,6 +698,8 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) palettes for all rectangles are identical or compatible */ ifp->format = AV_PIX_FMT_RGB32; + ifp->time_base = AV_TIME_BASE_Q; + av_log(fgp, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n", ifp->width, ifp->height); } @@ -1469,7 +1473,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, AVFilterContext *last_filter; const AVFilter *buffer_filt = avfilter_get_by_name("buffer"); const AVPixFmtDescriptor *desc; - InputStream *ist = ifp->ist; AVRational fr = ifp->opts.framerate; AVRational sar; AVBPrint args; @@ -1482,9 +1485,6 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph, if (ifp->type_src == AVMEDIA_TYPE_SUBTITLE) sub2video_prepare(ifp); - ifp->time_base = (ifp->opts.flags & IFILTER_FLAG_CFR) ? - av_inv_q(ifp->opts.framerate) : ist->st->time_base; - sar = ifp->sample_aspect_ratio; if(!sar.den) sar = (AVRational){0,1}; @@ -1575,8 +1575,6 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph, char name[255]; int ret, pad_idx = 0; - ifp->time_base = (AVRational){ 1, ifp->sample_rate }; - av_bprint_init(&args, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprintf(&args, "time_base=%d/%d:sample_rate=%d:sample_fmt=%s", ifp->time_base.num, ifp->time_base.den, @@ -1804,6 +1802,8 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) { InputFilterPriv *ifp = ifp_from_ifilter(ifilter); + ifp->fallback.time_base = dec->pkt_timebase; + if (dec->codec_type == AVMEDIA_TYPE_VIDEO) { ifp->fallback.format = dec->pix_fmt; ifp->fallback.width = dec->width; @@ -1835,6 +1835,10 @@ static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *fr if (ret < 0) return ret; + ifp->time_base = (ifp->type == AVMEDIA_TYPE_AUDIO) ? (AVRational){ 1, frame->sample_rate } : + (ifp->opts.flags & IFILTER_FLAG_CFR) ? av_inv_q(ifp->opts.framerate) : + frame->time_base; + ifp->format = frame->format; ifp->width = frame->width; @@ -2524,6 +2528,7 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter, ifp->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; ifp->color_space = ifp->fallback.color_space; ifp->color_range = ifp->fallback.color_range; + ifp->time_base = ifp->fallback.time_base; ret = av_channel_layout_copy(&ifp->ch_layout, &ifp->fallback.ch_layout); diff --git a/tests/ref/fate/sub2video_basic b/tests/ref/fate/sub2video_basic index a6eb1a34ea..2e4dcb625e 100644 --- a/tests/ref/fate/sub2video_basic +++ b/tests/ref/fate/sub2video_basic @@ -1,95 +1,95 @@ -#tb 0: 1/1000 +#tb 0: 1/1000000 #media_type 0: video #codec_id 0: rawvideo #dimensions 0: 720x480 #sar 0: 0/1 -0, 132499, 132499, 0, 1382400, 0x00000000 -0, 132499, 132499, 0, 1382400, 0x8c93c2ba -0, 137459, 137459, 0, 1382400, 0x00000000 -0, 147355, 147355, 0, 1382400, 0xb02e32ca -0, 152088, 152088, 0, 1382400, 0x00000000 -0, 180797, 180797, 0, 1382400, 0x83b71116 -0, 183357, 183357, 0, 1382400, 0x00000000 -0, 183433, 183433, 0, 1382400, 0x85547fd1 -0, 185799, 185799, 0, 1382400, 0x00000000 -0, 185909, 185909, 0, 1382400, 0x00000000 -0, 185910, 185910, 0, 1382400, 0xb6a8f181 -0, 188606, 188606, 0, 1382400, 0x00000000 -0, 188663, 188663, 0, 1382400, 0xb64d1a2c -0, 189925, 189925, 0, 1382400, 0x00000000 -0, 190014, 190014, 0, 1382400, 0x7b37ecf3 -0, 191675, 191675, 0, 1382400, 0x00000000 -0, 199724, 199724, 0, 1382400, 0xdc025bd1 -0, 201089, 201089, 0, 1382400, 0x00000000 -0, 201175, 201175, 0, 1382400, 0x688b294d -0, 202733, 202733, 0, 1382400, 0x00000000 -0, 202819, 202819, 0, 1382400, 0xa2b33d1b -0, 204684, 204684, 0, 1382400, 0x00000000 -0, 204762, 204762, 0, 1382400, 0xb3e525e3 -0, 206730, 206730, 0, 1382400, 0x00000000 -0, 206806, 206806, 0, 1382400, 0xaa8fbdd7 -0, 208637, 208637, 0, 1382400, 0x00000000 -0, 208716, 208716, 0, 1382400, 0x7b7f26dd -0, 209978, 209978, 0, 1382400, 0x00000000 -0, 210051, 210051, 0, 1382400, 0x15e2f836 -0, 211575, 211575, 0, 1382400, 0x00000000 -0, 211644, 211644, 0, 1382400, 0x0fee9b0c -0, 214306, 214306, 0, 1382400, 0x00000000 -0, 214380, 214380, 0, 1382400, 0x89d62791 -0, 217144, 217144, 0, 1382400, 0x00000000 -0, 217225, 217225, 0, 1382400, 0xa6a9fd74 -0, 219591, 219591, 0, 1382400, 0x00000000 -0, 219652, 219652, 0, 1382400, 0x7896178d -0, 221483, 221483, 0, 1382400, 0x00000000 -0, 223531, 223531, 0, 1382400, 0x01751a52 -0, 225863, 225863, 0, 1382400, 0x00000000 -0, 227510, 227510, 0, 1382400, 0xa3959c6f -0, 230809, 230809, 0, 1382400, 0x00000000 -0, 230872, 230872, 0, 1382400, 0x3d3ea47b -0, 233033, 233033, 0, 1382400, 0x00000000 -0, 233124, 233124, 0, 1382400, 0x593f8b24 -0, 237220, 237220, 0, 1382400, 0x00000000 -0, 237303, 237303, 0, 1382400, 0x171f05ba -0, 240033, 240033, 0, 1382400, 0x00000000 -0, 240106, 240106, 0, 1382400, 0xb014cdf1 -0, 242165, 242165, 0, 1382400, 0x00000000 -0, 273556, 273556, 0, 1382400, 0xd918e667 -0, 275217, 275217, 0, 1382400, 0x00000000 -0, 295445, 295445, 0, 1382400, 0xc9406331 -0, 296776, 296776, 0, 1382400, 0x00000000 -0, 300049, 300049, 0, 1382400, 0xaf08b10d -0, 301949, 301949, 0, 1382400, 0x00000000 -0, 302034, 302034, 0, 1382400, 0x00000000 -0, 302035, 302035, 0, 1382400, 0x853a9d93 -0, 303559, 303559, 0, 1382400, 0x00000000 -0, 304203, 304203, 0, 1382400, 0x7491a87d -0, 305898, 305898, 0, 1382400, 0x00000000 -0, 305947, 305947, 0, 1382400, 0xf7383c58 -0, 307881, 307881, 0, 1382400, 0x00000000 -0, 307957, 307957, 0, 1382400, 0xe66be411 -0, 309720, 309720, 0, 1382400, 0x00000000 -0, 321295, 321295, 0, 1382400, 0xd6850362 -0, 323263, 323263, 0, 1382400, 0x00000000 -0, 323356, 323356, 0, 1382400, 0x3e1ed109 -0, 324584, 324584, 0, 1382400, 0x00000000 -0, 324640, 324640, 0, 1382400, 0x39c1b7bd -0, 326403, 326403, 0, 1382400, 0x00000000 -0, 327193, 327193, 0, 1382400, 0x35b85f2e -0, 328285, 328285, 0, 1382400, 0x00000000 -0, 328360, 328360, 0, 1382400, 0x00000000 -0, 328361, 328361, 0, 1382400, 0x83f103e5 -0, 329885, 329885, 0, 1382400, 0x00000000 -0, 329946, 329946, 0, 1382400, 0xbc1ca9b3 -0, 331106, 331106, 0, 1382400, 0x00000000 -0, 331230, 331230, 0, 1382400, 0x94d4a51e -0, 332857, 332857, 0, 1382400, 0x00000000 -0, 332924, 332924, 0, 1382400, 0xf88cdfde -0, 334687, 334687, 0, 1382400, 0x00000000 -0, 342600, 342600, 0, 1382400, 0xdd51423b -0, 344431, 344431, 0, 1382400, 0x00000000 -0, 346771, 346771, 0, 1382400, 0x08259fa4 -0, 348329, 348329, 0, 1382400, 0x00000000 -0, 357640, 357640, 0, 1382400, 0x1663fa34 -0, 359767, 359767, 0, 1382400, 0x00000000 -0, 359834, 359834, 0, 1382400, 0xda2ceb55 -0, 361096, 361096, 0, 1382400, 0x00000000 +0, 132499000, 132499000, 0, 1382400, 0x00000000 +0, 132499000, 132499000, 0, 1382400, 0x8c93c2ba +0, 137459000, 137459000, 0, 1382400, 0x00000000 +0, 147355000, 147355000, 0, 1382400, 0xb02e32ca +0, 152088000, 152088000, 0, 1382400, 0x00000000 +0, 180797000, 180797000, 0, 1382400, 0x83b71116 +0, 183357000, 183357000, 0, 1382400, 0x00000000 +0, 183433000, 183433000, 0, 1382400, 0x85547fd1 +0, 185799000, 185799000, 0, 1382400, 0x00000000 +0, 185909999, 185909999, 0, 1382400, 0x00000000 +0, 185910000, 185910000, 0, 1382400, 0xb6a8f181 +0, 188606000, 188606000, 0, 1382400, 0x00000000 +0, 188663000, 188663000, 0, 1382400, 0xb64d1a2c +0, 189925000, 189925000, 0, 1382400, 0x00000000 +0, 190014000, 190014000, 0, 1382400, 0x7b37ecf3 +0, 191675000, 191675000, 0, 1382400, 0x00000000 +0, 199724000, 199724000, 0, 1382400, 0xdc025bd1 +0, 201089000, 201089000, 0, 1382400, 0x00000000 +0, 201175000, 201175000, 0, 1382400, 0x688b294d +0, 202733000, 202733000, 0, 1382400, 0x00000000 +0, 202819000, 202819000, 0, 1382400, 0xa2b33d1b +0, 204684000, 204684000, 0, 1382400, 0x00000000 +0, 204762000, 204762000, 0, 1382400, 0xb3e525e3 +0, 206730000, 206730000, 0, 1382400, 0x00000000 +0, 206806000, 206806000, 0, 1382400, 0xaa8fbdd7 +0, 208637000, 208637000, 0, 1382400, 0x00000000 +0, 208716000, 208716000, 0, 1382400, 0x7b7f26dd +0, 209978000, 209978000, 0, 1382400, 0x00000000 +0, 210051000, 210051000, 0, 1382400, 0x15e2f836 +0, 211575000, 211575000, 0, 1382400, 0x00000000 +0, 211644000, 211644000, 0, 1382400, 0x0fee9b0c +0, 214306000, 214306000, 0, 1382400, 0x00000000 +0, 214380000, 214380000, 0, 1382400, 0x89d62791 +0, 217144000, 217144000, 0, 1382400, 0x00000000 +0, 217225000, 217225000, 0, 1382400, 0xa6a9fd74 +0, 219591000, 219591000, 0, 1382400, 0x00000000 +0, 219652000, 219652000, 0, 1382400, 0x7896178d +0, 221483000, 221483000, 0, 1382400, 0x00000000 +0, 223531000, 223531000, 0, 1382400, 0x01751a52 +0, 225863000, 225863000, 0, 1382400, 0x00000000 +0, 227510000, 227510000, 0, 1382400, 0xa3959c6f +0, 230809000, 230809000, 0, 1382400, 0x00000000 +0, 230872000, 230872000, 0, 1382400, 0x3d3ea47b +0, 233033000, 233033000, 0, 1382400, 0x00000000 +0, 233124000, 233124000, 0, 1382400, 0x593f8b24 +0, 237220000, 237220000, 0, 1382400, 0x00000000 +0, 237303000, 237303000, 0, 1382400, 0x171f05ba +0, 240033000, 240033000, 0, 1382400, 0x00000000 +0, 240106000, 240106000, 0, 1382400, 0xb014cdf1 +0, 242165000, 242165000, 0, 1382400, 0x00000000 +0, 273556000, 273556000, 0, 1382400, 0xd918e667 +0, 275217000, 275217000, 0, 1382400, 0x00000000 +0, 295445000, 295445000, 0, 1382400, 0xc9406331 +0, 296776000, 296776000, 0, 1382400, 0x00000000 +0, 300049000, 300049000, 0, 1382400, 0xaf08b10d +0, 301949000, 301949000, 0, 1382400, 0x00000000 +0, 302034999, 302034999, 0, 1382400, 0x00000000 +0, 302035000, 302035000, 0, 1382400, 0x853a9d93 +0, 303559000, 303559000, 0, 1382400, 0x00000000 +0, 304203000, 304203000, 0, 1382400, 0x7491a87d +0, 305898000, 305898000, 0, 1382400, 0x00000000 +0, 305947000, 305947000, 0, 1382400, 0xf7383c58 +0, 307881000, 307881000, 0, 1382400, 0x00000000 +0, 307957000, 307957000, 0, 1382400, 0xe66be411 +0, 309720000, 309720000, 0, 1382400, 0x00000000 +0, 321295000, 321295000, 0, 1382400, 0xd6850362 +0, 323263000, 323263000, 0, 1382400, 0x00000000 +0, 323356000, 323356000, 0, 1382400, 0x3e1ed109 +0, 324584000, 324584000, 0, 1382400, 0x00000000 +0, 324640000, 324640000, 0, 1382400, 0x39c1b7bd +0, 326403000, 326403000, 0, 1382400, 0x00000000 +0, 327193000, 327193000, 0, 1382400, 0x35b85f2e +0, 328285000, 328285000, 0, 1382400, 0x00000000 +0, 328360999, 328360999, 0, 1382400, 0x00000000 +0, 328361000, 328361000, 0, 1382400, 0x83f103e5 +0, 329885000, 329885000, 0, 1382400, 0x00000000 +0, 329946000, 329946000, 0, 1382400, 0xbc1ca9b3 +0, 331106000, 331106000, 0, 1382400, 0x00000000 +0, 331230000, 331230000, 0, 1382400, 0x94d4a51e +0, 332857000, 332857000, 0, 1382400, 0x00000000 +0, 332924000, 332924000, 0, 1382400, 0xf88cdfde +0, 334687000, 334687000, 0, 1382400, 0x00000000 +0, 342600000, 342600000, 0, 1382400, 0xdd51423b +0, 344431000, 344431000, 0, 1382400, 0x00000000 +0, 346771000, 346771000, 0, 1382400, 0x08259fa4 +0, 348329000, 348329000, 0, 1382400, 0x00000000 +0, 357640000, 357640000, 0, 1382400, 0x1663fa34 +0, 359767000, 359767000, 0, 1382400, 0x00000000 +0, 359834000, 359834000, 0, 1382400, 0xda2ceb55 +0, 361096000, 361096000, 0, 1382400, 0x00000000 diff --git a/tests/ref/fate/sub2video_time_limited b/tests/ref/fate/sub2video_time_limited index c7d48d639f..07d50fc697 100644 --- a/tests/ref/fate/sub2video_time_limited +++ b/tests/ref/fate/sub2video_time_limited @@ -1,8 +1,8 @@ -#tb 0: 1/90000 +#tb 0: 1/1000000 #media_type 0: video #codec_id 0: rawvideo #dimensions 0: 1920x1080 #sar 0: 0/1 -0, 6072, 6072, 0, 8294400, 0x00000000 -0, 6072, 6072, 0, 8294400, 0xa87c518f -0, 36101, 36101, 0, 8294400, 0xa87c518f +0, 67467, 67467, 0, 8294400, 0x00000000 +0, 67467, 67467, 0, 8294400, 0xa87c518f +0, 401132, 401132, 0, 8294400, 0xa87c518f From patchwork Wed Mar 6 11:03:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46834 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313045pzb; Wed, 6 Mar 2024 03:05:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU5Zh9mR94CJ4JN6nmOEb2ZTltPKRwE09VjQylgrXxliPiVvcbQFSiVVL1fRpsY8tYSUMBrQg+LEzhsFaRKSdmy4wclfOy/LXvf6Q== X-Google-Smtp-Source: AGHT+IEj5psx3/utNEw6N5VuY2yY0Ja8iB68sXkX11gn0pF4RpSddHesuHa2EnIodix8sJzGGAoq X-Received: by 2002:a50:85c6:0:b0:565:9fff:6046 with SMTP id q6-20020a5085c6000000b005659fff6046mr11466206edh.3.1709723148357; Wed, 06 Mar 2024 03:05:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723148; cv=none; d=google.com; s=arc-20160816; b=uy06f84N7lW2NWIEp3QMca0kgzj3wSjF8uevbZk9akJ9IppDl3zeoXdJap0MxNaZlI xcJVvCt3H77UMCk8kmth0yLXUz4ylpCmm5boeSYl1OtoOW5p1UgzLJ0XqICK1CPhnbxP 9m0ccvno4HsQU0iiG/i2sJbUPdGUDZQ7hBLzI2N1B24LAPo7upReQZhKjz+8gR/+uL59 2gmawnJDywPM2X5xaLzFTA1dzPz9Zt0vwVu3PSOriI2J9USXBkEHz1sk09mT7mXcSAWw mhWtSgcjFOFBEzyWUGkxN1K7AShH3wR/IRfBoU6A1956emmNaBR9BvSuJ+41MvUC4otd gPtA== 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:dkim-signature:delivered-to; bh=F9MhtIbxYNnCXoay9Ekx/+d5R2K7jnSzOu4plitCFdw=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=UljU28n1JrhXcLGdSuCjxtP8y+9OhddQ3nqQ2gqaYg+OBISYgER3rwzmS+8DwdlvLI cXCrP8keHS322Thre+V3TOcO+0y7/5nUARPzRs+3rTS3MCUIOgF9ZrtVOnv8PDGhv2IU dhkmEPe7nlCO42Sv3VPSnKpeKslxrr7UMQZLm5bwk6fuMy5FnQGpLRiAS4OXCFyVeeXu 3SGpUTHEHYs+1raFvL17dRBkJZAt3OgSOwJZx+OMNKFtk1/9jcqe8Y0YF9LcM64G2tfb 5mxDyYsIDgDpYu9V045ov011yHOFcx21k1NjoSBZMQ296X/BaDWFBfJjttfWcDNdq/kK U7cw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=YGdXUUa1; 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 m7-20020a50d7c7000000b00567e2f1ad01si580926edj.684.2024.03.06.03.05.48; Wed, 06 Mar 2024 03:05:48 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=YGdXUUa1; 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 1D30768CD49; Wed, 6 Mar 2024 13:05:32 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD95C68B5A1 for ; Wed, 6 Mar 2024 13:05:24 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=YGdXUUa1; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 7DB0F4D46 for ; Wed, 6 Mar 2024 12:05:24 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 8qFw8msNrsP0 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=Yormk3XSmJcFShZUII08iRmEUXoWd4H3DhZkyrlOdYc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YGdXUUa1po4jtfYjCHyjcmFwyRsR7DY6BqVDB+PCYHuCuv3ld9roBPjqONSK0CiL+ TSP4zmf1drUkPlAle453GrUDzVGKMhhW1sfB1YH3Eu9iNiVjmZp4tvAdRnZXKhCySe fEWJq7kFWbMnth6wJ1+xr4GdU8IjKALiYylfsCnrNPPNAfF1ltCV/rplVFXkCemc9X smpvOjgyRfxZLsKxZmltUPEBYUPONesssYt5CRPbiVamb9127j3jRPtuWSC6c8TlvA 8G2lQvsX7fbvt/mVsy3MsemyUeuVKLzkYx0EZFC9jAnOIa02+s7cfUP2BdTrF1jKIR +zCUDxV+2Z3vQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id B01F14D44 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 98DB83A076E for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:04 +0100 Message-ID: <20240306110319.17339-3-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/18] fftools/ffmpeg_filter: drop unused InputFilterPriv.ist 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: HCRQHx8Qjgt9 Outside of ifilter_bind_ist(), there are no longer any assumptions about about filter inputs being fed by an InputStream. --- fftools/ffmpeg_filter.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 9d9762a599..37705297fb 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -109,8 +109,6 @@ typedef struct InputFilterPriv { AVFilterContext *filter; - InputStream *ist; - // used to hold submitted input AVFrame *frame; @@ -125,6 +123,7 @@ typedef struct InputFilterPriv { enum AVMediaType type_src; int eof; + int bound; // parameters configured for this input int format; @@ -664,7 +663,8 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) FilterGraphPriv *fgp = fgp_from_fg(ifilter->graph); int ret, dec_idx; - av_assert0(!ifp->ist); + av_assert0(!ifp->bound); + ifp->bound = 1; if (ifp->type != ist->par->codec_type && !(ifp->type == AVMEDIA_TYPE_VIDEO && ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE)) { @@ -673,7 +673,6 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) return AVERROR(EINVAL); } - ifp->ist = ist; ifp->type_src = ist->st->codecpar->codec_type; dec_idx = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph), From patchwork Wed Mar 6 11:03:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46836 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313131pzb; Wed, 6 Mar 2024 03:05:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXUqMZPX43XkObpCh6jkZhOgMfgQYAZN2iIJJSbN04fjW4VluqRjK+OtWI1i9qhZEBd35YrTj8LopnQyfBoNfuhLFT5kYer5J1+QQ== X-Google-Smtp-Source: AGHT+IH3rlph+A8D3YZ8lclUI1a7tOl4vrDLEzZJefWrIbKEe8bI5mqRvUtQPBwI6fEAuG7RM3U6 X-Received: by 2002:aa7:dcc3:0:b0:566:c156:aaa6 with SMTP id w3-20020aa7dcc3000000b00566c156aaa6mr2203148edu.1.1709723136598; Wed, 06 Mar 2024 03:05:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723136; cv=none; d=google.com; s=arc-20160816; b=vM2DWk2MU2n89Im9bURvVU83s0B1KzQlt+ymlm0LWLghtK2FIXW1GIB0iLTnQbHjUL Mr6635X8NxfCZ3jW+7DheICun4eOZ1GUZ8RbrrsPOjCkTc4Pa7Boke9I7uDtaOyxeOUm R0jKgRG+VcMS4ftTUUcOVJOKJED8Cgq0xdaeMXXSWG4yQn+FkEIEV+z+N+RbU8F+Ryfu 2VRLJ28wPfv+nV+QY6riCcIaeuYdRlpWvBdV6vmTD2ZraX0E0VQMVRdnrSG1gMnwVMsb pFTOxN43IxCOgO2h9tTbW7t+ot3wt5HY9duOURNjfaw+m8REkKvsi+GMZidJB2nZFHRK S73g== 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:dkim-signature:delivered-to; bh=+qAlMH8OPkNhUEfEWCXD6xyJYN+TglToNnDfwJSM7Dg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=NRAVsNP/X3h5MdpHvEDAOcgn7ZAMsNgomM8g08Ctllhwx9BEuUhz7GflH/EFn0ooSG 6gwcZGxLSGU+P9zG1+Uzej1P8TKyaxR2q4T4A/VzAYGfP7TJHJB6YRsxtUPn1lF5pGNZ 5d0dYq5jFqFpe34aztWpvHlrHpxL5KAj23SyQuCA6Jp+7/nbvzumzptj4ge6EChaPKKZ wBFeLS5zuM56zTbMyXVMCwAsXTSwnqYGGmxg/CMHDGTd1Ej96R/OBqG9gYZuIwyhg67O JwC3zIYKnF9wQV5Whx+qDrbKT8GVamXw/5zvsyMK6FeYA7+Opj1/yQ4+9rSHy4n0f13H 62Vg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=VK33I+pR; 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 bx13-20020a0564020b4d00b00566728493dfsi5771741edb.493.2024.03.06.03.05.35; Wed, 06 Mar 2024 03:05:36 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=VK33I+pR; 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 1E76468CB61; Wed, 6 Mar 2024 13:05:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31A5F68B5A1 for ; Wed, 6 Mar 2024 13:05:24 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=VK33I+pR; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id BD6B84D58 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id OCuQaZMU4TG5 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=Rg4324EfyT/brOQYuc9nInFvUWPkcSBUPMrjEC4Y9sc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VK33I+pRyo0BjELVWoakqm0InGk8YXxHG6xPuYrhkiVIWvJLdCJLApK72tXB1pH8E o+EjHjz93qNmWZ2RCnTVWhwlWEd3tA4hVrG99uiwKq7OlsDzQVPdV3VKNSWrCf9f+J NG8OPjgg/5/IaTALnBP1S2lWqD0ec7B8ih9TvT0JX87WnJAxAj5IRoFKirN1a8mi1K wGsmjk+JeDfd64hNe+EMyK7CIzarNZac3Go/8xOq8qE9l9sfOWVKlGXj4bXWltDA+4 JL8J9bIwRbdZcSld+ipbVtadu7wj8MujZ865X5i+qP9Ns9ZJh+G+EPbO/i6nrh81Bw 4jJZscOVv7N+A== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id B96AB4D46 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id A459A3A0A6B for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:05 +0100 Message-ID: <20240306110319.17339-4-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/18] fftools/ffmpeg_dec: move scheduler registration from dec_open() to dec_alloc() 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: YFSmtELUbXfW Will be useful in following commits where we will want to create a decoder before having enough information to open it. --- fftools/ffmpeg_dec.c | 51 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 8c92b27cc1..98c4a0c83c 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -110,9 +110,26 @@ void dec_free(Decoder **pdec) av_freep(pdec); } -static int dec_alloc(DecoderPriv **pdec) +static const char *dec_item_name(void *obj) +{ + const DecoderPriv *dp = obj; + + return dp->log_name; +} + +static const AVClass dec_class = { + .class_name = "Decoder", + .version = LIBAVUTIL_VERSION_INT, + .parent_log_context_offset = offsetof(DecoderPriv, log_parent), + .item_name = dec_item_name, +}; + +static void *decoder_thread(void *arg); + +static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts) { DecoderPriv *dp; + int ret = 0; *pdec = NULL; @@ -128,17 +145,24 @@ static int dec_alloc(DecoderPriv **pdec) if (!dp->pkt) goto fail; + dp->dec.class = &dec_class; dp->last_filter_in_rescale_delta = AV_NOPTS_VALUE; dp->last_frame_pts = AV_NOPTS_VALUE; dp->last_frame_tb = (AVRational){ 1, 1 }; dp->hwaccel_pix_fmt = AV_PIX_FMT_NONE; + ret = sch_add_dec(sch, decoder_thread, dp, send_end_ts); + if (ret < 0) + goto fail; + dp->sch = sch; + dp->sch_idx = ret; + *pdec = dp; return 0; fail: dec_free((Decoder**)&dp); - return AVERROR(ENOMEM); + return ret >= 0 ? AVERROR(ENOMEM) : ret; } static AVRational audio_samplerate_update(DecoderPriv *dp, @@ -1042,20 +1066,6 @@ static int hw_device_setup_for_decode(DecoderPriv *dp, return 0; } -static const char *dec_item_name(void *obj) -{ - const DecoderPriv *dp = obj; - - return dp->log_name; -} - -static const AVClass dec_class = { - .class_name = "Decoder", - .version = LIBAVUTIL_VERSION_INT, - .parent_log_context_offset = offsetof(DecoderPriv, log_parent), - .item_name = dec_item_name, -}; - int dec_open(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o) { @@ -1065,18 +1075,11 @@ int dec_open(Decoder **pdec, Scheduler *sch, *pdec = NULL; - ret = dec_alloc(&dp); + ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS)); if (ret < 0) return ret; - ret = sch_add_dec(sch, decoder_thread, dp, o->flags & DECODER_FLAG_SEND_END_TS); - if (ret < 0) - return ret; - dp->sch = sch; - dp->sch_idx = ret; - dp->flags = o->flags; - dp->dec.class = &dec_class; dp->log_parent = o->log_parent; dp->framerate_in = o->framerate; From patchwork Wed Mar 6 11:03:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46851 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp314482pzb; Wed, 6 Mar 2024 03:08:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUUbcN+5w9kZSKMluF3Zl2Agsoe5/BqlAjzbOJ9GQYA/ug9bWWQqq+ESkabZIj5FbJb0CTa0Db7itpPB63LUBDz/mH3AK5n80QTGg== X-Google-Smtp-Source: AGHT+IF74LPqBXsR6FAH8ovXRjcPtofqKHHZ3j3t2irCJvqcFNYkdR59c8/gA4dkkB7fVzj3Pqgo X-Received: by 2002:a05:6402:5c1:b0:567:6a66:d0fd with SMTP id n1-20020a05640205c100b005676a66d0fdmr4726902edx.0.1709723312210; Wed, 06 Mar 2024 03:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723312; cv=none; d=google.com; s=arc-20160816; b=dVcOMAbmh9tkhsa3pVFBKyiMdMlK7mFtXqkQ90JoeXxHzb/1DZ+b/wyL0//eYrO8RO GjD06WdTRfSGT+l5QsQqnPZf3UMArD+VVhOC+lJBKuLK3ksCO4KbZsB0+iQ4Ykmpnz8w LHCFOQvgNsRLglrx+D5fVOTPzT0x7sHL+LMnVVZsZ/50Ar0p54Tad19VCyqKVjeJAAoq IpuYUN3rPkjeMmn0uY4ZlJjTqKUMdT6CS/zEyFNPfKAgSvnznKSzmkqk+m/qix/ec5v3 n0SuHE8fMzyE2KvNYb0UdAb3mSYsIQ7tKLX8oFYuANiIJCbVDx1huF0umRwiSKtODE0a ozyA== 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:dkim-signature:delivered-to; bh=XRRsDYcuLAfCUTWUqgPeEwS1jYiUE1MPYczvrxuwsuc=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=p7oIHcI6mxDZFMTpTlImmhmXN3h2UsIOLJK6mbrN4XksquJ114fan0HmS6ciFeRgZd /+nCGgULqTHmwbxpmYN5M9pUpCcD+UWPme2zxzFwGBlOyprP7msR+hlng5UsI/PPcuat PHB5YfiPF8FIWl4m/42X8NkYwhC+dxC8izNQ2JCXZlnMgvGFy9ZRq1GaO4DWrnOQ2mN1 zSisDDL8TGCw0ygiCpLG5DBowo5SwgxHZXTdh18w/Mx0jyoRexx41M+e7uzyYGTQkuiL /ZIQ9l1AiGRe2dunh5jkxx54PrnQFud+FvagUO9BbZMGjxTByJMdcjewe34Q4yRV/cWv S79w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=GkF28R6J; 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 w22-20020a056402269600b00566c329e3b0si5425565edd.459.2024.03.06.03.08.31; Wed, 06 Mar 2024 03:08:32 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=GkF28R6J; 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 0F02668CF68; Wed, 6 Mar 2024 13:05:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90CF968CDB9 for ; Wed, 6 Mar 2024 13:05:29 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=GkF28R6J; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id A18C54D4C for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id a6fqaeFQ3YKP for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=2ZZJra8tUeCn6pLScHwPscvF9pWEvqUYJi8gzOztkSs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GkF28R6Jq7eADArudtgrugABYSIEje6cc9T4b2dz5KFES+HjVBDkAr5723+DLxQf6 9JYhlFrEi18evPzqtvIWvVI24Cv2YTth2vgSnxeu0O4mgDJOzDZN7LCGRmFGD+luYD XVacNsOw/4mHS6GSomTKE9v8FjHy+N6j83+kuyqAyD8Af0aZOzchg854LehA5GocV8 ADQEHovaNN3t+1FTZhpWGGuX/oUihuUgU9Nluyfsm1dQS5X5YxOyKpBK4kDugwgoZZ cYVmI1GKeWGntcyL2C5vLSADWn8QhT1nfKYR7GQZ0lMwOsy5j7jHbY47h8ssCt5ChQ +FKgtdnJs5uHQ== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id C5DDD4D48 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id AF1273A0B9C for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:06 +0100 Message-ID: <20240306110319.17339-5-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/18] fftools/ffmpeg_dec: factor opening the decoder out of dec_open() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hLDP8SMANgXa Rename dec_open to dec_init(), as it is more descriptive of its new purpose. Will be useful in following commits, which will add a new path for opening decoders. --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_dec.c | 61 ++++++++++++++++++++++-------------------- fftools/ffmpeg_demux.c | 2 +- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 1c5ebcb43f..6b049e329b 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -740,7 +740,7 @@ AVBufferRef *hw_device_for_filter(void); * @retval ">=0" non-negative scheduler index on success * @retval "<0" an error code on failure */ -int dec_open(Decoder **pdec, Scheduler *sch, +int dec_init(Decoder **pdec, Scheduler *sch, AVDictionary **dec_opts, const DecoderOpts *o); void dec_free(Decoder **pdec); diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 98c4a0c83c..af57b2bb9d 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -1066,19 +1066,11 @@ static int hw_device_setup_for_decode(DecoderPriv *dp, return 0; } -int dec_open(Decoder **pdec, Scheduler *sch, - AVDictionary **dec_opts, const DecoderOpts *o) +static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o) { - DecoderPriv *dp; const AVCodec *codec = o->codec; int ret; - *pdec = NULL; - - ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS)); - if (ret < 0) - return ret; - dp->flags = o->flags; dp->log_parent = o->log_parent; @@ -1091,39 +1083,31 @@ int dec_open(Decoder **pdec, Scheduler *sch, snprintf(dp->log_name, sizeof(dp->log_name), "dec:%s", codec->name); dp->parent_name = av_strdup(o->name ? o->name : ""); - if (!dp->parent_name) { - ret = AVERROR(ENOMEM); - goto fail; - } + if (!dp->parent_name) + return AVERROR(ENOMEM); if (codec->type == AVMEDIA_TYPE_SUBTITLE && (dp->flags & DECODER_FLAG_FIX_SUB_DURATION)) { for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) { dp->sub_prev[i] = av_frame_alloc(); - if (!dp->sub_prev[i]) { - ret = AVERROR(ENOMEM); - goto fail; - } + if (!dp->sub_prev[i]) + return AVERROR(ENOMEM); } dp->sub_heartbeat = av_frame_alloc(); - if (!dp->sub_heartbeat) { - ret = AVERROR(ENOMEM); - goto fail; - } + if (!dp->sub_heartbeat) + return AVERROR(ENOMEM); } dp->sar_override = o->par->sample_aspect_ratio; dp->dec_ctx = avcodec_alloc_context3(codec); - if (!dp->dec_ctx) { - ret = AVERROR(ENOMEM); - goto fail; - } + if (!dp->dec_ctx) + return AVERROR(ENOMEM); ret = avcodec_parameters_to_context(dp->dec_ctx, o->par); if (ret < 0) { av_log(dp, AV_LOG_ERROR, "Error initializing the decoder context.\n"); - goto fail; + return ret; } dp->dec_ctx->opaque = dp; @@ -1140,22 +1124,41 @@ int dec_open(Decoder **pdec, Scheduler *sch, av_log(dp, AV_LOG_ERROR, "Hardware device setup failed for decoder: %s\n", av_err2str(ret)); - goto fail; + return ret; } if ((ret = avcodec_open2(dp->dec_ctx, codec, dec_opts)) < 0) { av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n", av_err2str(ret)); - goto fail; + return ret; } ret = check_avoptions(*dec_opts); if (ret < 0) - goto fail; + return ret; dp->dec.subtitle_header = dp->dec_ctx->subtitle_header; dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size; + return 0; +} + +int dec_init(Decoder **pdec, Scheduler *sch, + AVDictionary **dec_opts, const DecoderOpts *o) +{ + DecoderPriv *dp; + int ret; + + *pdec = NULL; + + ret = dec_alloc(&dp, sch, !!(o->flags & DECODER_FLAG_SEND_END_TS)); + if (ret < 0) + return ret; + + ret = dec_open(dp, dec_opts, o); + if (ret < 0) + goto fail; + *pdec = &dp->dec; return dp->sch_idx; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 29f4a26224..ae0f635d8c 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -935,7 +935,7 @@ static int ist_use(InputStream *ist, int decoding_needed) ds->dec_opts.log_parent = ist; - ret = dec_open(&ist->decoder, d->sch, + ret = dec_init(&ist->decoder, d->sch, &ds->decoder_opts, &ds->dec_opts); if (ret < 0) return ret; From patchwork Wed Mar 6 11:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46841 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313539pzb; Wed, 6 Mar 2024 03:06:42 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX3hmRBog/8EP2VFAzJiAVzoJLMEY77HqXHZPqe7s9OdBy8HEBHytnbMOk+g46e+rftxCdxPK4CqjVkmB19y+wON2nDQ0Go8IGxDg== X-Google-Smtp-Source: AGHT+IF7wsC8eLBVf0+nNsSrEoaOb/weDSpMB9aacgxzVGit3bdmBpQ+o+F5/nTHL5D0CGKOOQLm X-Received: by 2002:a17:906:b310:b0:a3e:feee:3a5b with SMTP id n16-20020a170906b31000b00a3efeee3a5bmr5510768ejz.3.1709723202344; Wed, 06 Mar 2024 03:06:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723202; cv=none; d=google.com; s=arc-20160816; b=KVhD2xhSdp5bWnLvPWkW2dDBJ7GgcK5mjFeVS72xqvTIrj23XMbJpHCmUNSlBsDBp7 YDRGt6w+hk1PTeZFK6iu8yUDLwMC8vfz8krxvYpPw9c58pkdoNoRsAq9GyjzPfdvxlyD O3+ejLWlUt5heOy8LslJZTf0TRVlpl9iyXqkyJRleT79/0uCXG0BtUod2x66i5SCGo+S 7VX2YvRLv7Qc6LCE0ef9vkTAQ01dOpuxp9Z2089YoAh4fn8qYdWAbX2VSeQbWoYo65gB jXplEmMBgo+tbpXmKze3rt0YrmP0HeqPDrIpz5a682VgJiHw27KSnMMtbl6n3h2wLe3o +fWA== 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:dkim-signature:delivered-to; bh=/W51fy6YQlPMkx6+OsDGXIApFvzuTbdUpvxZ7QYnI1s=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cK+LHrpn0FfBm39AbzkkdiUiwGd8lDZesJdCXzQerbI14oZHtjNZp3vSDWRgmJAi2w hxhU3L9CS1KYdgwcP50c1qrJkcAId853bGYo7b9elXWldEmkz8vsDS+RsDUoajb68axX oD4ZLRId9S1xVPyfyHoE+DvupLoxa0iYxQAgX6e3xnLiKYfgflawl+GhMrwnV/jg5NlB 4QqTXLr7U3jf7BMO+p4HKVVu2dVGdq7H/JDMv6IfsA7crI1IMkP3roBcAa4jZ2YE4bhq DKxqY57hoxZkZ8Qxp2BM8XhpAA6njCOLeJBB2V/E6qAipbcsLE7tVml1Q09z6lEZRlp+ 6dQw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=LaIf6RCy; 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 v8-20020a170906180800b00a458231643esi2054704eje.828.2024.03.06.03.06.41; Wed, 06 Mar 2024 03:06:42 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=LaIf6RCy; 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 99A7E68CDD1; Wed, 6 Mar 2024 13:05:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7BA9A68C462 for ; Wed, 6 Mar 2024 13:05:25 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=LaIf6RCy; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 222C94D41 for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id bQ48W-Uptfw2 for ; Wed, 6 Mar 2024 12:05:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=hpUj2lSbqQ2eUdycZrkCW6AKmmAhNKRuhXicOOBwumo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LaIf6RCydsDIAAYO7ZiLWmHe83dIq3MLiVc0hbjN3CUaIYxuYE8+v3Vmi3jiy1H5o 89F1MQmKZowLLVKoS4Aug1IZo+SHZwXGe0e9GZpxjHU4urfn/0hUO8B/+SzJKvGYxa cDkolY6Y/Amw3j4yP1X5KIgyYHk0cxdzeoH6yaAbk4UrptW/CeoW31vQTwG/HREXYh mafKJn/8/B51n/2eqVqgej6ltQG/ANYxEdukL1JcrDtWSOOvlbwf7ccOMZ3gg3kVWW utGMUL1d4CUiFh81/ZgnpofvKLLhlkZUIMKhjWIUPEWzCx3YaE8pzgBXr/uEr5Zv7u /xZ0sNhy3+nlA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id D34334D49 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id B9D143A0C79 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:07 +0100 Message-ID: <20240306110319.17339-6-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/18] fftools/ffmpeg_opt: merge init_complex_filters() and check_filter_outputs() 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: gye0zvZHdngU The first of these binds inputs of complex filtergraphs to demuxer streams (with a misleading comment claiming it *creates* complex filtergraphs). The second ensures that all filtergraph outputs are connected to an encoder. Merge them into a single function, which simplifies the ffmpeg_filter API, is shorter, and will also be useful in following commits. Also, rename misleadingly-named init_input_filter() to fg_complex_bind_input(). --- fftools/ffmpeg.h | 3 +-- fftools/ffmpeg_filter.c | 38 ++++++++++++++++++-------------------- fftools/ffmpeg_opt.c | 32 +++++++++----------------------- 3 files changed, 28 insertions(+), 45 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 6b049e329b..d3e03543ac 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -671,12 +671,11 @@ int find_codec(void *logctx, const char *name, enum AVMediaType type, int encoder, const AVCodec **codec); int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global); -int check_filter_outputs(void); int filtergraph_is_simple(const FilterGraph *fg); int init_simple_filtergraph(InputStream *ist, OutputStream *ost, char *graph_desc, Scheduler *sch, unsigned sch_idx_enc); -int init_complex_filtergraph(FilterGraph *fg); +int fg_finalise_bindings(FilterGraph *fg); /** * Get our axiliary frame data attached to the frame, allocating it diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 37705297fb..7425e3d2ed 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1096,7 +1096,7 @@ int init_simple_filtergraph(InputStream *ist, OutputStream *ost, return 0; } -static int init_input_filter(FilterGraph *fg, InputFilter *ifilter) +static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter) { FilterGraphPriv *fgp = fgp_from_fg(fg); InputFilterPriv *ifp = ifp_from_ifilter(ifilter); @@ -1162,14 +1162,29 @@ static int init_input_filter(FilterGraph *fg, InputFilter *ifilter) return 0; } -int init_complex_filtergraph(FilterGraph *fg) +int fg_finalise_bindings(FilterGraph *fg) { // bind filtergraph inputs to input streams for (int i = 0; i < fg->nb_inputs; i++) { - int ret = init_input_filter(fg, fg->inputs[i]); + InputFilterPriv *ifp = ifp_from_ifilter(fg->inputs[i]); + int ret; + + if (ifp->bound) + continue; + + ret = fg_complex_bind_input(fg, &ifp->ifilter); if (ret < 0) return ret; } + + for (int i = 0; i < fg->nb_outputs; i++) { + OutputFilter *output = fg->outputs[i]; + if (!output->ost) { + av_log(filtergraphs[i], AV_LOG_FATAL, + "Filter %s has an unconnected output\n", output->name); + return AVERROR(EINVAL); + } + } return 0; } @@ -1436,23 +1451,6 @@ static int configure_output_filter(FilterGraph *fg, AVFilterGraph *graph, } } -int check_filter_outputs(void) -{ - for (int i = 0; i < nb_filtergraphs; i++) { - int n; - for (n = 0; n < filtergraphs[i]->nb_outputs; n++) { - OutputFilter *output = filtergraphs[i]->outputs[n]; - if (!output->ost) { - av_log(filtergraphs[i], AV_LOG_FATAL, - "Filter %s has an unconnected output\n", output->name); - return AVERROR(EINVAL); - } - } - } - - return 0; -} - static void sub2video_prepare(InputFilterPriv *ifp) { ifp->sub2video.last_pts = INT64_MIN; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a9a785a0ac..b550382b4c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -674,18 +674,6 @@ static int opt_streamid(void *optctx, const char *opt, const char *arg) return av_dict_set(&o->streamid, idx_str, p, 0); } -static int init_complex_filters(void) -{ - int i, ret = 0; - - for (i = 0; i < nb_filtergraphs; i++) { - ret = init_complex_filtergraph(filtergraphs[i]); - if (ret < 0) - return ret; - } - return 0; -} - static int opt_target(void *optctx, const char *opt, const char *arg) { OptionsContext *o = optctx; @@ -1264,13 +1252,6 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch) goto fail; } - /* create the complex filtergraphs */ - ret = init_complex_filters(); - if (ret < 0) { - errmsg = "initializing complex filters"; - goto fail; - } - /* open output files */ ret = open_files(&octx.groups[GROUP_OUTFILE], "output", sch, of_open); if (ret < 0) { @@ -1278,16 +1259,21 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch) goto fail; } + // bind unbound filtegraph inputs/outputs and check consistency + for (int i = 0; i < nb_filtergraphs; i++) { + ret = fg_finalise_bindings(filtergraphs[i]); + if (ret < 0) { + errmsg = "binding filtergraph inputs/outputs"; + goto fail; + } + } + correct_input_start_times(); ret = apply_sync_offsets(); if (ret < 0) goto fail; - ret = check_filter_outputs(); - if (ret < 0) - goto fail; - fail: uninit_parse_context(&octx); if (ret < 0 && ret != AVERROR_EXIT) { From patchwork Wed Mar 6 11:03:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46850 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp314389pzb; Wed, 6 Mar 2024 03:08:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWs8L3sXkVfmORVRzYxZIYjyzd4h4je4jT/ZNgnV4zDQPrUvwM03yIsp/DvNhAn2jKBZeD8xi7SQrvEzMyep+B93qDD/gcDZJ/Dcw== X-Google-Smtp-Source: AGHT+IEf56KvrReRrbAhe7l4lxueNa4mroLVQ1IOgGohtzgCP3NstAlEQfAAAdsqPNVhyfV/Moq7 X-Received: by 2002:a17:906:1cd5:b0:a44:15c3:c8e9 with SMTP id i21-20020a1709061cd500b00a4415c3c8e9mr11628661ejh.28.1709723302503; Wed, 06 Mar 2024 03:08:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723302; cv=none; d=google.com; s=arc-20160816; b=NDQX1ySwTn6zhhUdf+eXzsYUpvltemLV474PozFg72JLDG9HUZeeGIJQwPfzgLBzxK eTc04gU4EMZ/O6dTwOGyIrcYxYWD6pKWfXFPmtItrSB5fb36dZXWF8bQ+uhos3NGsKqO Qx4crKwHQpw6SITd4Hh92Wl7tYkiSWQdIzfp7EgQq9NpRYWGlFXZPQp2FoCBW1R73dy1 yvLBeDwMM17sl/aAb4Xr0/eodBvB4L1Y89EO7p+PcJ2mr0Y3MErOWmSEXRPOjMAHvWcq o9F9qw1rZ7FFOegoTXg5siY9q3J0z2irnzkhTG2UTxLDuZQBEgWNdMgw2egBSvPqfqwj VpaQ== 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:dkim-signature:delivered-to; bh=kbAZ4NIey6tkX6idr6CqiCs7Jppb+sh1L5rqmsCO7gg=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=e4tUmMv7cJ4Q0Sm/1HvCu47V6DHlG8pPmvsVYwSHRnSTBWpSX6T5qcqwT5EysZ+5B1 Ww6jWN6HEVIn5siupkqRmuZfreaZ33v0w1m4PEP4/6OdBQcWcR/JqPQ05AqGLN77k3u/ 9RGd7ayZ70Qh05tRsTV8HDkAA7RVn6pMpLrlWomDvldQ67Scv1pHQXdLgA1MyZiaGenv RLLxpk5VTACIR5CAdXDucy9aMN1HNawKF8UTm1d7IVCwaEseNwrHyQXektOBv3RjZ4G8 YRpJx+CXMg0Lmu58Z05A0K72WprMRZDmmYVHZlSN/dS3RQYCvHKDnFQ7ji+TV/jupDXL plgw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=ekCOnra2; 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 hs38-20020a1709073ea600b00a45aeab65f4si1087460ejc.966.2024.03.06.03.08.22; Wed, 06 Mar 2024 03:08:22 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=ekCOnra2; 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 147C068CF4B; Wed, 6 Mar 2024 13:05:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 827C568CD96 for ; Wed, 6 Mar 2024 13:05:29 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=ekCOnra2; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 780A44482 for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id mb8E1_evD8G3 for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=fZ3dsvsMes/wzc/bHJv6aYZmeiFVI/NJoxSlo9DnHoY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ekCOnra2VPmnighVv29N1b8yPm+weW4isdUHGRvsOBQdcSIjXBYgQ47MrwY1p50gt ika/Iv0TEZGZdWOU0wkl/hQ/F2cf9hLs+6j33ptwGdFtDGi9KtGoemnWxmbigeSOwu BMl+b5MujyKc0nEARRok+B6o6hv/jUUdcVqJNDusFJKWkLyNR57zOXdn2E7lCxnk4f PLbuk92/jft3JoMe+l8clifOLlTOF1sQcmxWrt+vVrR7AN/6LBEQu6PYnPtCaxidrz i0oNPn8yzrPVEXztJ7ZUTnb/cTPqAyA7Bh6q1Q5/HYT+zZKrfp2QdoLFH9XikQ0RCF 9Q9Ah9UNp1JUg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id DC5624D4C for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C4ACF3A0C7C for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:08 +0100 Message-ID: <20240306110319.17339-7-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/18] fftools/ffmpeg_filter: move filtergraph input type check to a better place 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: FLykAf35LS1Q Perform it right after we figure out what the type is. --- fftools/ffmpeg_filter.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 7425e3d2ed..eb8d0aee78 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1005,6 +1005,14 @@ int fg_create(FilterGraph **pfg, char *graph_desc, Scheduler *sch) ifp->type = avfilter_pad_get_type(cur->filter_ctx->input_pads, cur->pad_idx); + + if (ifp->type != AVMEDIA_TYPE_VIDEO && ifp->type != AVMEDIA_TYPE_AUDIO) { + av_log(fg, AV_LOG_FATAL, "Only video and audio filters supported " + "currently.\n"); + ret = AVERROR(ENOSYS); + goto fail; + } + ifilter->name = describe_filter_link(fg, cur, 1); if (!ifilter->name) { ret = AVERROR(ENOMEM); @@ -1104,13 +1112,6 @@ static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter) enum AVMediaType type = ifp->type; int i, ret; - // TODO: support other filter types - if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) { - av_log(fg, AV_LOG_FATAL, "Only video and audio filters supported " - "currently.\n"); - return AVERROR(ENOSYS); - } - if (ifp->linklabel) { AVFormatContext *s; AVStream *st = NULL; From patchwork Wed Mar 6 11:03:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46843 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313719pzb; Wed, 6 Mar 2024 03:07:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXmuGSI+TdHYG4sAlp58On49yd5wryLONNK0A2d/MsYIKf7Qxl4Hk4hf2bQGQIEQQ9ubvLevHvlfFqr19ZZGL2HMBuyzaAtYtne9g== X-Google-Smtp-Source: AGHT+IHTAS2FgyeLbg5HAWfCCpIV+J1TIUf4wA3VU+cY8Gq9ffwc5fRsduYOcK4nHy2eIOviCOnz X-Received: by 2002:a17:906:3559:b0:a44:df65:b7e5 with SMTP id s25-20020a170906355900b00a44df65b7e5mr8197751eja.49.1709723221495; Wed, 06 Mar 2024 03:07:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723221; cv=none; d=google.com; s=arc-20160816; b=sKnA5rf5ohKM+6g3iavZOeiCtx9Ne7XsGEbUBJ4d1tzrzzX4mpIWFsF48Z3nS1O4Iw YOmw9L2/BF1qcy4Q0owwIqpGktmkhlJ+Jvs40Gzy+4OqvCAXfDwkNMY26j9GAukAeqK8 YzVZWLaT/3jnyVHHLCG0pDsFfBy3x9x9o7q57WkwDtwKmNU2x19xTZQqi3iKbhGYwtOQ 9D+x4tBq2aA2Zy4uVsjvv+BMvqSZe3IkzSpVdx1JVTjUDaLace7GSgg6yg+0nAamkouf w+cwE98mMEZBgrreeMbJLqjwH7AldGKwnZfBrTgXoXrVvLc4jbmraZTSjuaxQhUjNR4o b3cg== 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:dkim-signature:delivered-to; bh=4qeFXQfDM8eeJrMKYj1HU7OzpDN2vlxlMtOtyvkmxC4=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=bVtTXQoFne6PQj7YqyEGGw9ZqBVPeQm8hrFhEzZnsyS6Kzx6V8/MjvlsTtqaCr/s0F QbWgcz9t4a1aM5bsH6glyZXUBNoZ7QgJ5MNX7IBR5AccXIkHDFFI+icyzCOyT3pjthlp t98tgVadMsdxHOsOrl93tiIK0rjg6LzLeFqwbb2+BVQrWcRWGOsgS4AmB77G0awRbiMh 6vA9cfegbOJAL2RwzRnxrvgZ5miJLwONewPxNoggGjo2+oKPQEyv4dC2C1Xh3GV3ZjzI hsTbF/AwvI4Kd8sIS5iRRlde4eAl/KgkSskuP8ZoMOkmhPuFURC96IHYFIcshd39dltE uXFA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=GsaGfS26; 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 v6-20020a1709060b4600b00a3e7d270e2fsi5918729ejg.839.2024.03.06.03.07.01; Wed, 06 Mar 2024 03:07:01 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=GsaGfS26; 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 C194E68CE0E; Wed, 6 Mar 2024 13:05:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A24B368CB86 for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=GsaGfS26; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 422674D51 for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Xvj_rnq5fCuO for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723122; bh=/iXTZpWSa5BppIXvMjQwkNU7UK5jcyuYiHnc+B06E30=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GsaGfS26X57Z8YGqjJSDVdDSlziU2yAR8T9wY2Jq7ZGU87dqc6SgLnQHluka5+xp3 csV0gHUDgoutZMKKS48rxSYSbG4Gwsql8rHr7eBP6/i00U8Zn+UA3gX+D8ELRkGtCH W3/GE7QyvO2ZCW6wUcY4q2BNbHQbBbikB7BsIQRYPmGiToMjEZcMjhYUHRwurvCshN T2KnO2gHG+zushjNyiq26ENfB0w+KTygOG3VBP83DlRVGlZ99ExDChCDiuQUGjLT9Y gzf5bSKTQ5boJ6hzKtfP4i5z5Onmq+ImWpy60zqkjj8mTvEh3H+odPCsND2w1LXZwm S7Fri0WhQQoZA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id ED39D4D4D for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id D0BB93A0582 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:09 +0100 Message-ID: <20240306110319.17339-8-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/18] fftools/ffmpeg_filter: add logging for binding inputs to demuxer streams 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: YBdBf2vYNPSE --- fftools/ffmpeg_filter.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index eb8d0aee78..7aa9305c88 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -1142,6 +1142,10 @@ static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter) return AVERROR(EINVAL); } ist = input_files[file_idx]->streams[st->index]; + + av_log(fg, AV_LOG_VERBOSE, + "Binding input with label '%s' to input stream %d:%d\n", + ifp->linklabel, ist->file->index, ist->index); } else { ist = ist_find_unused(type); if (!ist) { @@ -1149,6 +1153,10 @@ static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter) "unlabeled input pad %s\n", ifilter->name); return AVERROR(EINVAL); } + + av_log(fg, AV_LOG_VERBOSE, + "Binding unlabeled input %d to input stream %d:%d\n", + ifp->index, ist->file->index, ist->index); } av_assert0(ist); From patchwork Wed Mar 6 11:03:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46839 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313362pzb; Wed, 6 Mar 2024 03:06:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVeBSTK7RMa6PpFoOmsI3dG8nP1HqvJGfzzwvYgab1mk8GGhe9wL9TNeWchb483bajf0i2x+zrhcoMikb9qa1FuypHYWzUqIJ8YQQ== X-Google-Smtp-Source: AGHT+IF1lscaOWi2gKWV2RN+4BA/Vsl3WQW4F6cL9HoxX7PLqBcq4DPF4zAeYq8jZKHq6bPApEw9 X-Received: by 2002:a17:906:1192:b0:a45:6ffe:c0e5 with SMTP id n18-20020a170906119200b00a456ffec0e5mr4781084eja.18.1709723180922; Wed, 06 Mar 2024 03:06:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723180; cv=none; d=google.com; s=arc-20160816; b=UWH1GhSoYpck8RpokSTfw+TUzn0Xh7srynpNfY7beJICfa4WkD4pl67bQc3VtWJjeO FiBHLANDdPX10AFypHZHp7U99r93gNNT9aGWpiEShjrpQTqnhSLDytmRWin/3GyeAXPF aQM8PPE82Ab9mFqWCSmNzjMTg71yKJVrrmM8sehuSqIz141LhtYYKqnPl8ktE9Koccvi pCegco6PYulz1uGB90vNJDSfzc/zmOYSNlAXZCCSj6dtIYRgZx0F5+88Ms2TNMgx8sWY zgJXRXFJ3ECNJNDpHIPKvP2R9ljVL7GRY1uhPm4ISwp7Wuu+Y5iwiSeKcQebmMJxeP0l WVeA== 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:dkim-signature:delivered-to; bh=4wT+nGC76X9Xd2CnEHzW2sR4FqmA/H5LSOtfi8UVzvk=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=tPbGLspZDtE0SKY9ZL642RxoujtZG0y2ta3oZ6gr5xANI8PhiiS4OjFgVwzJdWabKi aHlxkzxY8DXgJhJoav88o+49VTvDtvaOt7LkWb4fwlkPq9Lr92G5Je7oJWpGyxMmWzVB BlTTjRf3UsRVG1CxCHWvhZJ2NfovngUD8b3jhdnW1d1r40+Vb4hpmVA7Gor8vT2PxKN+ gqUGDuvi/enM7z0SYwk9jH5jEFRVdK/g7cT4/IDyDNS3a/HbEFcdY8tmpUHIcaxeSi5F U0hpzD71ddSt3wmKEuP+DIsNztD2EyVjMqW9650lx5c7cN0tSOzTDSyEZDvqGZAxWtPq bEGg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b="XeMH9/7y"; 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 y17-20020a1709060a9100b00a45a9d652c9si1373921ejf.467.2024.03.06.03.06.20; Wed, 06 Mar 2024 03:06:20 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b="XeMH9/7y"; 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 BAE5968CC5D; Wed, 6 Mar 2024 13:05:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76B3D68BC64 for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=XeMH9/7y; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 0BD564D4E for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id t_0-9utCkxYK for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=peeWXb0V8EyGWb5a+N7YQFR/CA5kE26PiwSiOYfwNrc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XeMH9/7yCjugz2fLaywkxNVqP8uGH3ZgBzB1kgNt824PFlTr0hXiVKlQ9qGj/6Jts xwj6eeZqm1B0eBRMhdfHGMKMUzLippmEJePB1FaefUA22j+8wfH35UJJE1NpEHL8a+ uXbdijmy7dwsiPWWVZbM2mayk7nibhhKcV3cMlfcPe14s4V0eM09UU2inEUl9j2Z1/ CZk4g1s0eWhhCMQUErqxqO9eHafHspmmRHjm0bvqWYTzxrziv9roQ0Ov/V5AZOeRjd GY/2yQFdGPKlVRPJpUJzq7uzvnIaJb+0Xb1JYcjTLXW+FQ+v8cIcGI8ZXYe0HG2bpE nAa641G8u+s1g== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id ED3C44D52 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id DC4EA3A0DA6 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:10 +0100 Message-ID: <20240306110319.17339-9-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/18] fftools/ffmpeg: simplify propagating fallback parameters from decoders to filters 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: CNnKSEFZjtLe Current callstack looks like this: * ifilter_bind_ist() (filter) calls ist_filter_add() (demuxer); * ist_filter_add() opens the decoder, and then calls dec_add_filter() (decoder); * dec_add_filter() calls ifilter_parameters_from_dec() (i.e. back into the filtering code) in order to give post-avcodec_open2() parameters to the filter. This is unnecessarily complicated. Pass the parameters as follows instead: * dec_init() (which opens the decoder) returns post-avcodec_open2() parameters to its caller (i.e. the demuxer) in a parameter-only AVFrame * the demuxer passes these parameters to the filter in InputFilterOptions, together with other filter options --- fftools/ffmpeg.h | 9 ++++--- fftools/ffmpeg_dec.c | 36 ++++++++++++++++++-------- fftools/ffmpeg_demux.c | 25 ++++++++++++++---- fftools/ffmpeg_filter.c | 57 ++++++++++++----------------------------- 4 files changed, 67 insertions(+), 60 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index d3e03543ac..1a60f035b0 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -259,6 +259,8 @@ typedef struct InputFilterOptions { // a combination of IFILTER_FLAG_* unsigned flags; + + AVFrame *fallback; } InputFilterOptions; typedef struct InputFilter { @@ -735,16 +737,17 @@ AVBufferRef *hw_device_for_filter(void); /** * @param dec_opts Dictionary filled with decoder options. Its ownership * is transferred to the decoder. + * @param param_out If non-NULL, media properties after opening the decoder + * are written here. * * @retval ">=0" non-negative scheduler index on success * @retval "<0" an error code on failure */ int dec_init(Decoder **pdec, Scheduler *sch, - AVDictionary **dec_opts, const DecoderOpts *o); + AVDictionary **dec_opts, const DecoderOpts *o, + AVFrame *param_out); void dec_free(Decoder **pdec); -int dec_add_filter(Decoder *dec, InputFilter *ifilter); - int enc_alloc(Encoder **penc, const AVCodec *codec, Scheduler *sch, unsigned sch_idx); void enc_free(Encoder **penc); diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index af57b2bb9d..7005ada527 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -1066,7 +1066,8 @@ static int hw_device_setup_for_decode(DecoderPriv *dp, return 0; } -static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts *o) +static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, + const DecoderOpts *o, AVFrame *param_out) { const AVCodec *codec = o->codec; int ret; @@ -1140,11 +1141,32 @@ static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, const DecoderOpts dp->dec.subtitle_header = dp->dec_ctx->subtitle_header; dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size; + if (param_out) { + if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) { + param_out->format = dp->dec_ctx->sample_fmt; + param_out->sample_rate = dp->dec_ctx->sample_rate; + + ret = av_channel_layout_copy(¶m_out->ch_layout, &dp->dec_ctx->ch_layout); + if (ret < 0) + return ret; + } else if (dp->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) { + param_out->format = dp->dec_ctx->pix_fmt; + param_out->width = dp->dec_ctx->width; + param_out->height = dp->dec_ctx->height; + param_out->sample_aspect_ratio = dp->dec_ctx->sample_aspect_ratio; + param_out->colorspace = dp->dec_ctx->colorspace; + param_out->color_range = dp->dec_ctx->color_range; + } + + param_out->time_base = dp->dec_ctx->pkt_timebase; + } + return 0; } int dec_init(Decoder **pdec, Scheduler *sch, - AVDictionary **dec_opts, const DecoderOpts *o) + AVDictionary **dec_opts, const DecoderOpts *o, + AVFrame *param_out) { DecoderPriv *dp; int ret; @@ -1155,7 +1177,7 @@ int dec_init(Decoder **pdec, Scheduler *sch, if (ret < 0) return ret; - ret = dec_open(dp, dec_opts, o); + ret = dec_open(dp, dec_opts, o, param_out); if (ret < 0) goto fail; @@ -1166,11 +1188,3 @@ fail: dec_free((Decoder**)&dp); return ret; } - -int dec_add_filter(Decoder *dec, InputFilter *ifilter) -{ - DecoderPriv *dp = dp_from_dec(dec); - - // initialize fallback parameters for filtering - return ifilter_parameters_from_dec(ifilter, dp->dec_ctx); -} diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index ae0f635d8c..032a96567f 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -81,6 +81,8 @@ typedef struct DemuxStream { AVDictionary *decoder_opts; DecoderOpts dec_opts; char dec_name[16]; + // decoded media properties, as estimated by opening the decoder + AVFrame *decoded_params; AVBSFContext *bsf; @@ -839,6 +841,8 @@ static void ist_free(InputStream **pist) avcodec_parameters_free(&ist->par); + av_frame_free(&ds->decoded_params); + av_bsf_free(&ds->bsf); av_freep(pist); @@ -935,8 +939,12 @@ static int ist_use(InputStream *ist, int decoding_needed) ds->dec_opts.log_parent = ist; + ds->decoded_params = av_frame_alloc(); + if (!ds->decoded_params) + return AVERROR(ENOMEM); + ret = dec_init(&ist->decoder, d->sch, - &ds->decoder_opts, &ds->dec_opts); + &ds->decoder_opts, &ds->dec_opts, ds->decoded_params); if (ret < 0) return ret; ds->sch_idx_dec = ret; @@ -988,10 +996,6 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, ist->filters[ist->nb_filters - 1] = ifilter; - ret = dec_add_filter(ist->decoder, ifilter); - if (ret < 0) - return ret; - if (ist->par->codec_type == AVMEDIA_TYPE_VIDEO) { if (ist->framerate.num > 0 && ist->framerate.den > 0) { opts->framerate = ist->framerate; @@ -1027,6 +1031,17 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, ds->have_sub2video = 1; } + ret = av_frame_copy_props(opts->fallback, ds->decoded_params); + if (ret < 0) + return ret; + opts->fallback->format = ds->decoded_params->format; + opts->fallback->width = ds->decoded_params->width; + opts->fallback->height = ds->decoded_params->height; + + ret = av_channel_layout_copy(&opts->fallback->ch_layout, &ds->decoded_params->ch_layout); + if (ret < 0) + return ret; + if (copy_ts) { tsoffset = d->f.start_time == AV_NOPTS_VALUE ? 0 : d->f.start_time; if (!start_at_zero && d->f.ctx->start_time != AV_NOPTS_VALUE) diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 7aa9305c88..6438cbd73b 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -675,6 +675,10 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) ifp->type_src = ist->st->codecpar->codec_type; + ifp->opts.fallback = av_frame_alloc(); + if (!ifp->opts.fallback) + return AVERROR(ENOMEM); + dec_idx = ist_filter_add(ist, ifilter, filtergraph_is_simple(ifilter->graph), &ifp->opts); if (dec_idx < 0) @@ -863,9 +867,8 @@ static InputFilter *ifilter_alloc(FilterGraph *fg) ifp->index = fg->nb_inputs - 1; ifp->format = -1; - ifp->fallback.format = -1; - ifp->color_space = ifp->fallback.color_space = AVCOL_SPC_UNSPECIFIED; - ifp->color_range = ifp->fallback.color_range = AVCOL_RANGE_UNSPECIFIED; + ifp->color_space = AVCOL_SPC_UNSPECIFIED; + ifp->color_range = AVCOL_RANGE_UNSPECIFIED; ifp->frame_queue = av_fifo_alloc2(8, sizeof(AVFrame*), AV_FIFO_FLAG_AUTO_GROW); if (!ifp->frame_queue) @@ -895,9 +898,8 @@ void fg_free(FilterGraph **pfg) } av_frame_free(&ifp->sub2video.frame); - av_channel_layout_uninit(&ifp->fallback.ch_layout); - av_frame_free(&ifp->frame); + av_frame_free(&ifp->opts.fallback); av_buffer_unref(&ifp->hw_frames_ctx); av_freep(&ifp->linklabel); @@ -1804,33 +1806,6 @@ fail: return ret; } -int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) -{ - InputFilterPriv *ifp = ifp_from_ifilter(ifilter); - - ifp->fallback.time_base = dec->pkt_timebase; - - if (dec->codec_type == AVMEDIA_TYPE_VIDEO) { - ifp->fallback.format = dec->pix_fmt; - ifp->fallback.width = dec->width; - ifp->fallback.height = dec->height; - ifp->fallback.sample_aspect_ratio = dec->sample_aspect_ratio; - ifp->fallback.color_space = dec->colorspace; - ifp->fallback.color_range = dec->color_range; - } else if (dec->codec_type == AVMEDIA_TYPE_AUDIO) { - int ret; - - ifp->fallback.format = dec->sample_fmt; - ifp->fallback.sample_rate = dec->sample_rate; - - ret = av_channel_layout_copy(&ifp->fallback.ch_layout, &dec->ch_layout); - if (ret < 0) - return ret; - } - - return 0; -} - static int ifilter_parameters_from_frame(InputFilter *ifilter, const AVFrame *frame) { InputFilterPriv *ifp = ifp_from_ifilter(ifilter); @@ -2527,17 +2502,17 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter, } else { if (ifp->format < 0) { // the filtergraph was never configured, use the fallback parameters - ifp->format = ifp->fallback.format; - ifp->sample_rate = ifp->fallback.sample_rate; - ifp->width = ifp->fallback.width; - ifp->height = ifp->fallback.height; - ifp->sample_aspect_ratio = ifp->fallback.sample_aspect_ratio; - ifp->color_space = ifp->fallback.color_space; - ifp->color_range = ifp->fallback.color_range; - ifp->time_base = ifp->fallback.time_base; + ifp->format = ifp->opts.fallback->format; + ifp->sample_rate = ifp->opts.fallback->sample_rate; + ifp->width = ifp->opts.fallback->width; + ifp->height = ifp->opts.fallback->height; + ifp->sample_aspect_ratio = ifp->opts.fallback->sample_aspect_ratio; + ifp->color_space = ifp->opts.fallback->colorspace; + ifp->color_range = ifp->opts.fallback->color_range; + ifp->time_base = ifp->opts.fallback->time_base; ret = av_channel_layout_copy(&ifp->ch_layout, - &ifp->fallback.ch_layout); + &ifp->opts.fallback->ch_layout); if (ret < 0) return ret; From patchwork Wed Mar 6 11:03:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46845 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313872pzb; Wed, 6 Mar 2024 03:07:21 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWm7U6LzK1ikXR+XIqnMwXxKbbM7UspAaK+nImkl0y+o1y7M51QvIGxmcCKCy0Qml2qURravkxCwkl8Pvf1os07W6orZbddaqbTrA== X-Google-Smtp-Source: AGHT+IE6zlbWcWq9+TKLBSO9QAiawwsr/z4fRJueLquqm3vHUk1OT0YG556alWTsV+QQjI552bYG X-Received: by 2002:a17:906:4f0a:b0:a45:46f8:a181 with SMTP id t10-20020a1709064f0a00b00a4546f8a181mr5762385eju.46.1709723241453; Wed, 06 Mar 2024 03:07:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723241; cv=none; d=google.com; s=arc-20160816; b=Qqk4r7LgUdY5XJ+DSPhlgc8SREm02YOsZaTxs8LSflN4lci+P2XfDiBAar1TBjWbYF qR4w6yXJf9n/5uKCPnrIrtFsQxsA9EOWUdnAQfPDU1WrXzKZO9l4QSdTs4PUMBWpQiVr p1DUgcJmfbhfeE9T4VcbZcBWNbo02Z/ibopX0iUfcBqWtTRut4WH4e5ALLInlaL3PkxR 8emO95cE6z5ogkLG0EbGMFXRCkw6/6mijCNR6Rtkl52swve/oLbPI4gw+gLSTpHETt6e +luPjCHhFdCxbP1rPVb6ZkilExLuPVYhgma5PBeO6L6Z3+uZ/Pt232fWz8gL9T+/E6Xw mSNQ== 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:dkim-signature:delivered-to; bh=S72I2d6c6LH/hbLckYQjok41tvdRqIZH9KoWeXjAhjU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=yRONBr98L6YjNo00LMfu2/T7l8s3a/7UzpwCtlsarjqQHmQiA0QUK4pd449QA3UTYP vM39AFlnX85Cy3e4Ym6y0BofRPqznsS50UPnNm44WtzBnIhmLc4ofv9u3HSy/p039OKy ZWGcipnXFnd0QUJdp+GJX62lzi64viyZM9d7REkQ15iqWMQ3Bh/E5CgYyUkBmt5hsJ4P UkdXeQOUetJBYBRQfMmAamVK/Tx2bjZ8LiS6vI19vYVquBLKpluOjuY6tDAXhBQ6d4xI UnIZPg4e57ULFZ7t18aGah0ZIqwkxrjTyKn7JQ2zXvstFahFSq2Y+MIlq3meVrrJujPt yrAw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=LHBTQC24; 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 a9-20020a1709064a4900b00a4504198645si3431229ejv.556.2024.03.06.03.07.21; Wed, 06 Mar 2024 03:07:21 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=LHBTQC24; 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 02F9768CE0F; Wed, 6 Mar 2024 13:05:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A2FA668CC5D for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=LHBTQC24; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 85F5F4D52 for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 3bhw29JZx3L2 for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=43YfZCP302n4AwfF3zi3t4lmPmvinmhqaBYF19DMwnI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=LHBTQC24ufj0xFUaWBQ8Znv7z6UHkxCR1MWKwYqnK0XcG0+K6hR4kyH3m56gkzw6Q tD+PvEPX1M2YzmmlV8DZD6riZYUnsmzXVb4nuDgORm+PFjBTnR1GVKuv10QFl/d3Ba yssfRHJmNkFkyyhAJ/WnW8TfJqssUQf6j6RW6YqMpCqdyKftaYSOZ1bBzvUgXEozh7 BDNYWzVpy8EMMSF34hYiOcZwIIePd7cdRHJY5sSehWTQvYhFz/vGyBu7sHOYoFCyYp mRHTGl9thrfDbvpGPzh2oMVocKSwmR3iM1PitUpyP8Jb1NcUMRXwyuYk+6VHPvJplN BSlOZNV4mqmLA== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 0155D4D54 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id E7FD83A0F49 for ; Wed, 6 Mar 2024 12:05:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:11 +0100 Message-ID: <20240306110319.17339-10-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/18] fftools/ffmpeg: remove unncessary casts for *_thread() return values 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: MY17d6iIObMZ These functions used to be passed directly to pthread_create(), which required them to return void*. This is no longer the case, so they can return a plain int. --- fftools/ffmpeg.h | 4 ++-- fftools/ffmpeg_dec.c | 6 +++--- fftools/ffmpeg_demux.c | 4 ++-- fftools/ffmpeg_enc.c | 4 ++-- fftools/ffmpeg_filter.c | 6 +++--- fftools/ffmpeg_mux.c | 4 ++-- fftools/ffmpeg_sched.c | 2 +- fftools/ffmpeg_sched.h | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 1a60f035b0..1966817bc3 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -832,7 +832,7 @@ void update_benchmark(const char *fmt, ...); const char *opt_match_per_type_str(const SpecifierOptList *sol, char mediatype); -void *muxer_thread(void *arg); -void *encoder_thread(void *arg); +int muxer_thread(void *arg); +int encoder_thread(void *arg); #endif /* FFTOOLS_FFMPEG_H */ diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 7005ada527..3bf7ab4960 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -124,7 +124,7 @@ static const AVClass dec_class = { .item_name = dec_item_name, }; -static void *decoder_thread(void *arg); +static int decoder_thread(void *arg); static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts) { @@ -789,7 +789,7 @@ fail: return AVERROR(ENOMEM); } -static void *decoder_thread(void *arg) +static int decoder_thread(void *arg) { DecoderPriv *dp = arg; DecThreadContext dt; @@ -884,7 +884,7 @@ static void *decoder_thread(void *arg) finish: dec_thread_uninit(&dt); - return (void*)(intptr_t)ret; + return ret; } static enum AVPixelFormat get_format(AVCodecContext *s, const enum AVPixelFormat *pix_fmts) diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 032a96567f..47312c9fe1 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -675,7 +675,7 @@ static int demux_thread_init(DemuxThreadContext *dt) return 0; } -static void *input_thread(void *arg) +static int input_thread(void *arg) { Demuxer *d = arg; InputFile *f = &d->f; @@ -780,7 +780,7 @@ static void *input_thread(void *arg) finish: demux_thread_uninit(&dt); - return (void*)(intptr_t)ret; + return ret; } static void demux_final_stats(Demuxer *d) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index bdba50df03..1ddef46d03 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -870,7 +870,7 @@ fail: return AVERROR(ENOMEM); } -void *encoder_thread(void *arg) +int encoder_thread(void *arg) { OutputStream *ost = arg; Encoder *e = ost->enc; @@ -948,5 +948,5 @@ void *encoder_thread(void *arg) finish: enc_thread_uninit(&et); - return (void*)(intptr_t)ret; + return ret; } diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 6438cbd73b..a29008387a 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -626,7 +626,7 @@ static int ifilter_has_all_input_formats(FilterGraph *fg) return 1; } -static void *filter_thread(void *arg); +static int filter_thread(void *arg); static char *describe_filter_link(FilterGraph *fg, AVFilterInOut *inout, int in) { @@ -2735,7 +2735,7 @@ fail: return AVERROR(ENOMEM); } -static void *filter_thread(void *arg) +static int filter_thread(void *arg) { FilterGraphPriv *fgp = arg; FilterGraph *fg = &fgp->fg; @@ -2849,7 +2849,7 @@ finish: fg_thread_uninit(&fgt); - return (void*)(intptr_t)ret; + return ret; } void fg_send_command(FilterGraph *fg, double time, const char *target, diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 6ba54b878b..59befefab2 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -404,7 +404,7 @@ fail: return AVERROR(ENOMEM); } -void *muxer_thread(void *arg) +int muxer_thread(void *arg) { Muxer *mux = arg; OutputFile *of = &mux->of; @@ -453,7 +453,7 @@ void *muxer_thread(void *arg) finish: mux_thread_uninit(&mt); - return (void*)(intptr_t)ret; + return ret; } static int of_streamcopy(OutputFile *of, OutputStream *ost, AVPacket *pkt) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index 1144fce958..cf9b0c836e 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -2226,7 +2226,7 @@ static void *task_wrapper(void *arg) int ret; int err = 0; - ret = (intptr_t)task->func(task->func_arg); + ret = task->func(task->func_arg); if (ret < 0) av_log(task->func_arg, AV_LOG_ERROR, "Task finished with error code: %d (%s)\n", ret, av_err2str(ret)); diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h index 95f9c1d4db..fc6711f9c3 100644 --- a/fftools/ffmpeg_sched.h +++ b/fftools/ffmpeg_sched.h @@ -102,7 +102,7 @@ typedef struct SchedulerNode { unsigned idx_stream; } SchedulerNode; -typedef void* (*SchThreadFunc)(void *arg); +typedef int (*SchThreadFunc)(void *arg); #define SCH_DSTREAM(file, stream) \ (SchedulerNode){ .type = SCH_NODE_TYPE_DEMUX, \ From patchwork Wed Mar 6 11:03:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46838 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313261pzb; Wed, 6 Mar 2024 03:06:10 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUM1HQPvesgmVYl88ALZdlU72jxj3Bz73ycCu9V8FxH0G45Tpl7ZoZDjuddtXu8fasl/9aswkntBe+vXHm9J14ASxmqkEjYolDLfg== X-Google-Smtp-Source: AGHT+IHnPU8h/iTF16W8PdYmGcEK+at2qK/pQDMJa2qvc+ojC0J+wrJwWmyX57tOlofEVmyXIpaa X-Received: by 2002:a05:6402:22bc:b0:566:c2f8:a47d with SMTP id cx28-20020a05640222bc00b00566c2f8a47dmr2088909edb.1.1709723170321; Wed, 06 Mar 2024 03:06:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723170; cv=none; d=google.com; s=arc-20160816; b=H+hFySdGiUpqafXTAwjHIniskExq7BWKX0wpVd9GzCXXQRdhOYB/GxIHHcpdACV0RC HullruD85CkCzDoaWkmgZigr61DCw8xtWTAcX2QA4nEtiLh+mARfBM9S1QhaTpIIL1qI KFlpuRZmFvcRKFZ6ZjJ9geloVXMlsAsdTB1yWnCD5rbloTbuAW3/3l0rtSG/Y+XURHtE PFsKBYG7r108Esnh7utB/HxndTW2k9tcglLdFg/13TBOr21NxiKOFqL44DQ61dvX1ccJ XxnS7SnfnHO+qwuORpzOsBZFihDn2XtzM9EviQeBkR14sCyinhhcH/K+VPPLCFMuNfT8 R32w== 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:dkim-signature:delivered-to; bh=FRUdME782Z0qZMMCp1+CZ2LEhW6QRo9LcXLwq+VNVQM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=cyh2liwtv0iJYap0ZSXG9myH1xDrgdOat6gDpN6mLNKbIipiEFrFMDQxWfEaoHa85H rXI/Jkzp/O8izD3L05V8GZp2hYIsS/8Iu5w+sp7TTYxy6BtFGCZbBKRh7bHrvMzy+Z9h SFpoLU/ngeB7+Xr/kxx5jNpmOizYW3JYq/eanH6ynCMEFFFvhPcS6YeoQ6LySwgR0uFd dhMvZDDDqFDC2rxNgGQPURzn7zhJ67ahl5VPKO6odtEfMq3LIUfvahHxnX611DZ5Z9lU tDHzVPLCiCqMXskYmAsGy5hUBevPcBOoET/DlBrOzI4uohRoBLxz+6n/pImys89goN/b QqcA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=dSpEQDGo; 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 n10-20020a05640205ca00b005664cef247fsi5880742edx.179.2024.03.06.03.06.09; Wed, 06 Mar 2024 03:06:10 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=dSpEQDGo; 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 6C5FF68CCF8; Wed, 6 Mar 2024 13:05:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76EF568BE7C for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=dSpEQDGo; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id E92584D48 for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id EECuZOC2G8Ey for ; Wed, 6 Mar 2024 12:05:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=tiqBXmuPxXRuF0dNM20HTUqfTagojYHtn+rlxEpfHM8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dSpEQDGo6NPB64KqX1C75EJSufME8EaGJ2gXQyXeKHOwTeVAryRdAQPDFWNiYcHJS WWyYannz0a714RYvuVUKuZedEZemvnp5ISBXwo1vPdl4fBKM75FxDJv27o6O4OnZAi 406n3opuffrzYS3SYG0Avs7hH6Fruvdk+gStrmz7lgQmlFNoYy0JOKij1xR90Pi61q VKHr/mCR8u9IZjbybWTu5vtYBjn0Eqwxrke2pj6f70qSlZCShnu5G6YNCYPveybTfF /YOcMpjr1PzzO1P7ARaIVvpeMa43qXufHgglJWXJ3k5/rVNUS+CEErvr8rvzZu+5Aq V+4LZGVlAvnvw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 0C1014D59 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 004CA3A0357 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:12 +0100 Message-ID: <20240306110319.17339-11-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/18] fftools/ffmpeg_enc: drop unnecessary parameter from forced_kf_apply() 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: f9wzdvTHuH+m Encoder timebase is equal to the frame timebase, so does not need to be passed separately. Also, rename in_picture to frame, which is shorter and more accurate - it always contains a frame, never a field. --- fftools/ffmpeg_enc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 1ddef46d03..f0a17228fe 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -746,16 +746,16 @@ static int do_audio_out(OutputFile *of, OutputStream *ost, } static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, - AVRational tb, const AVFrame *in_picture) + const AVFrame *frame) { double pts_time; if (kf->ref_pts == AV_NOPTS_VALUE) - kf->ref_pts = in_picture->pts; + kf->ref_pts = frame->pts; - pts_time = (in_picture->pts - kf->ref_pts) * av_q2d(tb); + pts_time = (frame->pts - kf->ref_pts) * av_q2d(frame->time_base); if (kf->index < kf->nb_pts && - av_compare_ts(in_picture->pts, tb, kf->pts[kf->index], AV_TIME_BASE_Q) >= 0) { + av_compare_ts(frame->pts, frame->time_base, kf->pts[kf->index], AV_TIME_BASE_Q) >= 0) { kf->index++; goto force_keyframe; } else if (kf->pexpr) { @@ -780,7 +780,7 @@ static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, kf->expr_const_values[FKF_N_FORCED] += 1; goto force_keyframe; } - } else if (kf->type == KF_FORCE_SOURCE && (in_picture->flags & AV_FRAME_FLAG_KEY)) { + } else if (kf->type == KF_FORCE_SOURCE && (frame->flags & AV_FRAME_FLAG_KEY)) { goto force_keyframe; } @@ -801,7 +801,7 @@ static int do_video_out(OutputFile *of, OutputStream *ost, return AVERROR_EOF; in_picture->quality = enc->global_quality; - in_picture->pict_type = forced_kf_apply(ost, &ost->kf, enc->time_base, in_picture); + in_picture->pict_type = forced_kf_apply(ost, &ost->kf, in_picture); #if FFMPEG_OPT_TOP if (ost->top_field_first >= 0) { From patchwork Wed Mar 6 11:03:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46849 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp314275pzb; Wed, 6 Mar 2024 03:08:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWdMWlqlqSKzrl5L6oXPpzMstr+yIWC6FeoetCFy9m4jnczxgE7qv3diVBbjtpETjL9L6S2nwDNDc17t+/47iMvhaapC1mKo7a7Kw== X-Google-Smtp-Source: AGHT+IG9wOWlnGZF1Kydarf5nJD+0hWM8V2MkzCskC6Qx4ngB+Lcg9YYs6KqLfafkQov/IFN5oi4 X-Received: by 2002:a17:906:ad9a:b0:a45:2601:56b with SMTP id la26-20020a170906ad9a00b00a452601056bmr6074107ejb.51.1709723292412; Wed, 06 Mar 2024 03:08:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723292; cv=none; d=google.com; s=arc-20160816; b=TEnyeRvuPkdRx6gs9czvMcmEu8BwO3gzxU+2rOq9Uz/Us9fGmEWm1SLfeeT6Km0bIR 25Sk8CjHxjeY1ZpJQwfnh3SuggsxSpVRTKyZDaDSgSQPNWD1bcgm5XiH4deVPjfpSq2K lbYtXphTeNRiZcXrlwgCOCqzxFdJDV4Ql5RWp35YLc6WGlFYXWpMKyu6kRpi0w5sVjlj 6jeEqLGnHxjQGdvQ6ldckgvUgrS/oomL1on9XCqoAWOaxS+GA/JcVGUZS5d41ee5pnTN Q4HUTCoIRY48B/vyAlFwGwuv0+lG3TBruhwuZqHUWldwaUBPobHaUnL9sTzGQ3xab0ni 1w5g== 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:dkim-signature:delivered-to; bh=+Lj1OWpFqOppBrdjqoiWNUMww9exD6qiPEsqDUrNqG8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=EsXA5Ckod+UBxc9hfx2pgbnAymwSbegpEtGvm34EVCXdgsOJk/9MUQzG1WuKnWYzFG +cJCgXGbafbYn1oclpuihKUtmQLwHqxsah7atsaev8gtuPs1V/dVLJNVTuYpabtsQYVZ vgDAyNiO58hKNXuC4OONHLTbhDRsUoBEssLWOiyHYYbN4QpxLVEhdsmx5bfIYBv4hauO fef9cMU7idhtH5BNFxyPtPHCYhysM5CVYzPKQHFm8YHQV8rANHFy3zgxigsCVBatHYYg hKDGQQxc2vznA3zmBgLNIxONIwi9hXY0/8jmdxmhCzpEHo0PDOPNsgRJ90ow8nlKyb+H 1SVw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=IYS70mka; 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 ho37-20020a1709070ea500b00a45a3e58134si1638092ejc.604.2024.03.06.03.08.12; Wed, 06 Mar 2024 03:08:12 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=IYS70mka; 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 07A4468CF3B; Wed, 6 Mar 2024 13:05:48 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8F7DB68CD22 for ; Wed, 6 Mar 2024 13:05:31 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=IYS70mka; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 70B3D4D41 for ; Wed, 6 Mar 2024 12:05:31 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id sQ2IZTLYpe4v for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=nmJfqXiAPaANJ7kce0Q2AYiK/2K5u0B0MNYeKfo5FHI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IYS70mkaw/ZxUOARHgofVyvEo3bEoe64qwjAQSQMzmQ3zBMIZjL6gZrbJ+MedTUo9 kJBDpkfCiCFml0YGfZ6tRcUhRwmawzYMQP/6nlJUWLhkTiiJqsf0AWfTd9i1hTbQtb +VNeQVasTMgXuZHo8Jitac4gaQ8z91tD+QTiP7vQSGUK9QJzcGxnqXbG+rerNwrfbT ghL6sKnzkyrP1OCfwiROdhcEt3pkCK9cpE+GvJ5KuqZFCcPn+6kWU9BxpMLJAAHCst pKvNAB2RwNn0nBu+XaXdqtzr/6YMK/3lWD4aA9TMsiRfWloQ7uick/Ly47wTP/GUUW j4Wt3Vx/d0Z5Q== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 179654D5C for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0B5763A076E for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:13 +0100 Message-ID: <20240306110319.17339-12-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 12/18] fftools/ffmpeg_enc: merge do_{audio, video}_out into frame_encode() 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: lgTEq9JNY9Kn These functions used to be much longer, but now they are only a couple lines each, some of them duplicated between audio and video. --- fftools/ffmpeg_enc.c | 65 +++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index f0a17228fe..88635629f7 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -727,24 +727,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, av_assert0(0); } -static int do_audio_out(OutputFile *of, OutputStream *ost, - AVFrame *frame, AVPacket *pkt) -{ - AVCodecContext *enc = ost->enc_ctx; - - if (!(enc->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && - enc->ch_layout.nb_channels != frame->ch_layout.nb_channels) { - av_log(ost, AV_LOG_ERROR, - "Audio channel count changed and encoder does not support parameter changes\n"); - return 0; - } - - if (!check_recording_time(ost, frame->pts, frame->time_base)) - return AVERROR_EOF; - - return encode_frame(of, ost, frame, pkt); -} - static enum AVPictureType forced_kf_apply(void *logctx, KeyframeForceCtx *kf, const AVFrame *frame) { @@ -791,28 +773,6 @@ force_keyframe: return AV_PICTURE_TYPE_I; } -/* May modify/reset frame */ -static int do_video_out(OutputFile *of, OutputStream *ost, - AVFrame *in_picture, AVPacket *pkt) -{ - AVCodecContext *enc = ost->enc_ctx; - - if (!check_recording_time(ost, in_picture->pts, ost->enc_ctx->time_base)) - return AVERROR_EOF; - - in_picture->quality = enc->global_quality; - in_picture->pict_type = forced_kf_apply(ost, &ost->kf, in_picture); - -#if FFMPEG_OPT_TOP - if (ost->top_field_first >= 0) { - in_picture->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; - in_picture->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * (!!ost->top_field_first); - } -#endif - - return encode_frame(of, ost, in_picture, pkt); -} - static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt) { OutputFile *of = ost->file; @@ -828,11 +788,30 @@ static int frame_encode(OutputStream *ost, AVFrame *frame, AVPacket *pkt) } if (frame) { - return (type == AVMEDIA_TYPE_VIDEO) ? do_video_out(of, ost, frame, pkt) : - do_audio_out(of, ost, frame, pkt); + if (!check_recording_time(ost, frame->pts, frame->time_base)) + return AVERROR_EOF; + + if (type == AVMEDIA_TYPE_VIDEO) { + frame->quality = ost->enc_ctx->global_quality; + frame->pict_type = forced_kf_apply(ost, &ost->kf, frame); + +#if FFMPEG_OPT_TOP + if (ost->top_field_first >= 0) { + frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; + frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * (!!ost->top_field_first); + } +#endif + } else { + if (!(ost->enc_ctx->codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE) && + ost->enc_ctx->ch_layout.nb_channels != frame->ch_layout.nb_channels) { + av_log(ost, AV_LOG_ERROR, + "Audio channel count changed and encoder does not support parameter changes\n"); + return 0; + } + } } - return encode_frame(of, ost, NULL, pkt); + return encode_frame(of, ost, frame, pkt); } static void enc_thread_set_name(const OutputStream *ost) From patchwork Wed Mar 6 11:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46842 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313630pzb; Wed, 6 Mar 2024 03:06:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXFAZtODDcle2cfc1R9hvI6070ywbaLvA4f0fPSP+TjU/hVbLpTAgRNhvEN8p8c0IepIsDcWMZKTIl4GmON0NPk5k0dYyvOwDRssA== X-Google-Smtp-Source: AGHT+IGWKfEwhPoodkujZJshIXk8L9OUX0vqzIbsvLDMLVxxwf/jzpnl6lwPOtpBhSEi1Zfsmlo9 X-Received: by 2002:a17:906:1959:b0:a3e:93d0:3443 with SMTP id b25-20020a170906195900b00a3e93d03443mr9069157eje.34.1709723211867; Wed, 06 Mar 2024 03:06:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723211; cv=none; d=google.com; s=arc-20160816; b=pRZmS6Z9SdpWVQ57IKCEtA6IMMQE2WODhhwuGgkd208AjJ3CXHm303Yu/f7IkkXtw2 H/bezba/OQtGFJlLGwYEZdE4JZpSF8OPlmnNsc+gD0re6Qe6nPi7QLx7xd9c1ATIizFZ JU4RBfpiVaPNF5A37Mk/4tpeQ3mGTBynIKZ4PzGndLlqQ1T1P7JHMQ0HnD6DXRLzEv9v V1A0FjZuNW+rTeJz7zlJkx/gkJfsu1DdYzspEf5MpIS2N/x9fUwq8/yzp2v6iwqeVB6F NQFl0cXoOstsDBostLj7Ve+GeeNVEQLSJvnLqDrL9caZk5L/SQOeXy0fYEouLQmga9jq 6NUw== 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:dkim-signature:delivered-to; bh=SDa7ZRHUXk5pEQJqsSAdZcLJUYpVcV3pyfyb7iKMD38=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=k0iz+6+eX9/ztNUGnUPMsz9dOFCl6jUmO1aQlzhBhNBK2B7/5/IdB2dW7TOFSR16FB ifj9/f+T9bhsHbqlnRaLp1dLgOfYrO02pPS/n7+SbZhiRoaz/hkduUCqMm8NNAGHdpMN U3Fvl/cVE2apOqRUMA9nC0h+ygG56NpJ2cXZSk6EAP6zxEcOjwkY4MEJsKqDYvStYM6B dUfC9lqL0aiIkM20vOrOa21zFX0JmWMgclMS7n0b2QOQMEYQzyFCoPxl/kVAeiyRkzjk XiAiQfaD14/z55kmh3EUTrsgd56Sqe4bee0bVFIroYpdMKo/Vy6ZEgD1LLmFVgWuuVV4 jBCg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=FNPdJlPw; 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 a17-20020a17090680d100b00a45bc0a2394si430659ejx.1049.2024.03.06.03.06.51; Wed, 06 Mar 2024 03:06:51 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=FNPdJlPw; 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 B5C7D68CDFB; Wed, 6 Mar 2024 13:05:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9B0FD68CAF7 for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=FNPdJlPw; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id EAABE4D54 for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id nUVs_Rst-a23 for ; Wed, 6 Mar 2024 12:05:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=meeVTIJk4moi4tc4pMkg9DXCv7Z3nJlnwtAASbh1/Is=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FNPdJlPwQti+PexuFzKYJIY9XjMg0/2cf+TE1BwNf2Ah62cI774/kvq/CaPLSwJa9 HIkkY1OkH/Wm+648TP8d2fJ3vQ6z3QjhoKuVXjo6/nEtQHbdQ30CD1JMJM3Sfvoskb NPeXVzFAPeovt5dypLohv9GlPIhoFmJsul2iX1vPhWLb03wFW2Wxke5x2/xe3L85DG tU/eVCFmctuLqBrm0aQHOqAkbRsZCHz0FzQ/UAtUtytL3RuU4qzwTLx/eyNwJVGGUo Ahk/tzAvBTCZyz17MlLuuqXXy++Wgz7knbnjtzXCK0gnc9q6c3X/RKLUU72D1WLV6C Pnqq/Az0UVOsw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 247624D5D for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 16FA43A0582 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:14 +0100 Message-ID: <20240306110319.17339-13-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/18] fftools/ffmpeg_sched: allow encoders to send to multiple destinations 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: gwpPp19owCBi Will become useful in following commits. --- fftools/ffmpeg_sched.c | 117 ++++++++++++++++++++++++++++++++++------- 1 file changed, 98 insertions(+), 19 deletions(-) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index cf9b0c836e..e5435dd866 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -104,7 +104,9 @@ typedef struct SchEnc { const AVClass *class; SchedulerNode src; - SchedulerNode dst; + SchedulerNode *dst; + uint8_t *dst_finished; + unsigned nb_dst; // [0] - index of the sync queue in Scheduler.sq_enc, // [1] - index of this encoder in the sq @@ -134,7 +136,9 @@ typedef struct SchEnc { ThreadQueue *queue; // tq_send() to queue returned EOF int in_finished; - int out_finished; + + // temporary storage used by sch_enc_send() + AVPacket *send_pkt; } SchEnc; typedef struct SchDemuxStream { @@ -569,6 +573,11 @@ void sch_free(Scheduler **psch) SchEnc *enc = &sch->enc[i]; tq_free(&enc->queue); + + av_packet_free(&enc->send_pkt); + + av_freep(&enc->dst); + av_freep(&enc->dst_finished); } av_freep(&sch->enc); @@ -819,6 +828,10 @@ int sch_add_enc(Scheduler *sch, SchThreadFunc func, void *ctx, task_init(sch, &enc->task, SCH_NODE_TYPE_ENC, idx, func, ctx); + enc->send_pkt = av_packet_alloc(); + if (!enc->send_pkt) + return AVERROR(ENOMEM); + ret = queue_alloc(&enc->queue, 1, 0, QUEUE_FRAMES); if (ret < 0) return ret; @@ -1048,9 +1061,14 @@ int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst) enc = &sch->enc[src.idx]; ms = &sch->mux[dst.idx].streams[dst.idx_stream]; - av_assert0(!enc->dst.type && !ms->src.type); - enc->dst = dst; - ms->src = src; + av_assert0(!ms->src.type); + + ret = GROW_ARRAY(enc->dst, enc->nb_dst); + if (ret < 0) + return ret; + + enc->dst[enc->nb_dst - 1] = dst; + ms->src = src; break; } @@ -1339,12 +1357,16 @@ int sch_start(Scheduler *sch) "Encoder not connected to a source\n"); return AVERROR(EINVAL); } - if (!enc->dst.type) { + if (!enc->nb_dst) { av_log(enc, AV_LOG_ERROR, - "Encoder not connected to a sink\n"); + "Encoder not connected to any sink\n"); return AVERROR(EINVAL); } + enc->dst_finished = av_calloc(enc->nb_dst, sizeof(*enc->dst_finished)); + if (!enc->dst_finished) + return AVERROR(ENOMEM); + ret = task_start(&enc->task); if (ret < 0) return ret; @@ -1518,15 +1540,21 @@ static int send_to_enc_sq(Scheduler *sch, SchEnc *enc, AVFrame *frame) // TODO: consider a cleaner way of passing this information through // the pipeline if (!frame) { - SchMux *mux = &sch->mux[enc->dst.idx]; - SchMuxStream *ms = &mux->streams[enc->dst.idx_stream]; + for (unsigned i = 0; i < enc->nb_dst; i++) { + SchMux *mux; + SchMuxStream *ms; - pthread_mutex_lock(&sch->schedule_lock); - ms->source_finished = 1; - schedule_update_locked(sch); + mux = &sch->mux[enc->dst[i].idx]; + ms = &mux->streams[enc->dst[i].idx_stream]; - pthread_mutex_unlock(&sch->schedule_lock); + pthread_mutex_lock(&sch->schedule_lock); + + ms->source_finished = 1; + schedule_update_locked(sch); + + pthread_mutex_unlock(&sch->schedule_lock); + } } pthread_mutex_lock(&sq->lock); @@ -2080,20 +2108,64 @@ int sch_enc_receive(Scheduler *sch, unsigned enc_idx, AVFrame *frame) return ret; } +static int enc_send_to_dst(Scheduler *sch, const SchedulerNode dst, + uint8_t *dst_finished, AVPacket *pkt) +{ + int ret; + + if (*dst_finished) + return AVERROR_EOF; + + if (!pkt) + goto finish; + + ret = send_to_mux(sch, &sch->mux[dst.idx], dst.idx_stream, pkt); + if (ret == AVERROR_EOF) + goto finish; + + return ret; + +finish: + send_to_mux(sch, &sch->mux[dst.idx], dst.idx_stream, NULL); + + *dst_finished = 1; + + return AVERROR_EOF; +} + int sch_enc_send(Scheduler *sch, unsigned enc_idx, AVPacket *pkt) { SchEnc *enc; int ret; + unsigned nb_done = 0; av_assert0(enc_idx < sch->nb_enc); enc = &sch->enc[enc_idx]; - if (enc->out_finished) - return pkt ? AVERROR_EOF : 0; + for (unsigned i = 0; i < enc->nb_dst; i++) { + uint8_t *finished = &enc->dst_finished[i]; + AVPacket *to_send = pkt; - ret = send_to_mux(sch, &sch->mux[enc->dst.idx], enc->dst.idx_stream, pkt); - if (ret < 0) - enc->out_finished = 1; + // sending a packet consumes it, so make a temporary reference if needed + if (i < enc->nb_dst - 1) { + to_send = enc->send_pkt; + + ret = av_packet_ref(to_send, pkt); + if (ret < 0) + return ret; + } + + ret = enc_send_to_dst(sch, enc->dst[i], finished, to_send); + if (ret < 0) { + av_packet_unref(to_send); + if (ret == AVERROR_EOF) { + nb_done++; + ret = 0; + continue; + } + return ret; + } + } return ret; } @@ -2101,10 +2173,17 @@ int sch_enc_send(Scheduler *sch, unsigned enc_idx, AVPacket *pkt) static int enc_done(Scheduler *sch, unsigned enc_idx) { SchEnc *enc = &sch->enc[enc_idx]; + int ret = 0; tq_receive_finish(enc->queue, 0); - return send_to_mux(sch, &sch->mux[enc->dst.idx], enc->dst.idx_stream, NULL); + for (unsigned i = 0; i < enc->nb_dst; i++) { + int err = enc_send_to_dst(sch, enc->dst[i], &enc->dst_finished[i], NULL); + if (err < 0 && err != AVERROR_EOF) + ret = err_merge(ret, err); + } + + return ret; } int sch_filter_receive(Scheduler *sch, unsigned fg_idx, From patchwork Wed Mar 6 11:03:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46844 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313798pzb; Wed, 6 Mar 2024 03:07:11 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWXgtek9PrZhZz2pSW4dj2WNP2/7/Ega8a8lz6wyThFAJEAVVfDBqDI1kTAy3I2pBWORVKzcNBvyM2fYXXWRdX0la1VTzxvA37jEg== X-Google-Smtp-Source: AGHT+IGpZ8HTBoFACn/EAxlly9CZBgMz81EpGVvi56Ip7LPQju45LZUEtrPLtEXs3Kwtq4FcFRCs X-Received: by 2002:a17:907:8747:b0:a44:205d:bb84 with SMTP id qo7-20020a170907874700b00a44205dbb84mr2159081ejc.2.1709723231637; Wed, 06 Mar 2024 03:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723231; cv=none; d=google.com; s=arc-20160816; b=gtECPwPCQvikfy9LzYjPyRdWE5XA5rceVZ5IlgQy2F+5HMqeerkzRJlIZBorOfJ6BI RjQnCTWPkg5qz0KuZRLpjuEgNyspROk6j+4y/rzSE/PkeVfkNVnZGlDvQG3i9aGSFEVV oqytEMyjA/vEHeUbOfgvqCl5lu0rUehtgQKq/+GqVo0qeWXMFntWkwRIgz472uh5R50c rynQice8eLlY/ftUn7uSQCGSulLGOI9f/0xMePEYqpL3E6qNODs+70+/HCHfDF6iH/oi jLE/qD3sup9h6KNm8vwDON/iNwtq6bnCjYQ9A/YEB9Ka1pzIXeHHmpUs0Rvi1Z+D0FK3 ijBw== 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:dkim-signature:delivered-to; bh=04Y5EUDUIxk5E6QmX+sw9YUsePrwaPs60Asje8FQCOM=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=xyHp/BXmopGVuRv19SMuuXN61s45tAQJUQ7Ggz41tuoDvCaeiPCjGxSW/2NPMGYJRh n3z9Cky3UyhzNv6P0t8h3HcneKOsqMZczK09NLms300Vy5N7JREh6tSKakUEKYV9PVnf fXj7Q7Nhm2g7xKud5qD6rnRcoeXWDlx/lPkkGWYYGHgNVPkTZfjKoT1Jel2+zmoz42Dq XQiIBq1pCpNXIdWo+uADQpkhjwRhyYoS/DneJrHARw5j1XksuQ4xHNsBGIglyHCN+AdL LJKOG5jR8W6J6pubZGFwxbTRggykVc6osS31yAxV0dt2sWpbfSdKA53hvF1XFKmOVtc2 1ZPg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=VU+knBdj; 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 jz9-20020a170906bb0900b00a4556ab6bddsi2675632ejb.451.2024.03.06.03.07.11; Wed, 06 Mar 2024 03:07:11 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=VU+knBdj; 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 D2C0268CE24; Wed, 6 Mar 2024 13:05:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9D1B268CB61 for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=VU+knBdj; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 5D7C24D56 for ; Wed, 6 Mar 2024 12:05:27 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id qzwAyzvdKBlw for ; Wed, 6 Mar 2024 12:05:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=44Yd89q/HNjVRSusuQF31vraoVqIPYT+BLQJLwOa73Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VU+knBdjE6oeqVpWp4LsYqm7LmrUEGdLkLPb9YMCrfZmMC3rLulUa8GsB3rRWSGHp 0vul+RB/Qd7pk2cOE/YHfRhwXlmvUaWTcs/8DerjP1kWHUE5Yg5lA+fckqNEL/Wfb7 stxizeQhUtN5etrrUN7F0NBNbsCqDXyleCZniNmEA/NOzwkyb0q1CNLnWQfYDvKfLb 202meL+FUDLGM6cWU/drEyL+9IhC5+hg7BN6jRsNzPMNdnI+VrSXab3gbsukJKSUPt D0R+O82TlqkvVUj/0EnxRNBFx/YVwVZH5lrX9Ju+HEUHfmVw/iWWelI6eyEim4rhY4 cEaLataQIcRfg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 30FAF4D5E for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 23D253A0A6B for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:15 +0100 Message-ID: <20240306110319.17339-14-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/18] fftools/ffmpeg_sched: factor initializing nodes into separate function 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: 5F0ZNzmmbmpF Will be useful in following commits. --- fftools/ffmpeg_sched.c | 151 +++++++++++++++++++++++++---------------- 1 file changed, 91 insertions(+), 60 deletions(-) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index e5435dd866..5f8ef04680 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -1303,11 +1303,65 @@ static void schedule_update_locked(Scheduler *sch) } -int sch_start(Scheduler *sch) +static int start_prepare(Scheduler *sch) { int ret; - sch->transcode_started = 1; + for (unsigned i = 0; i < sch->nb_demux; i++) { + SchDemux *d = &sch->demux[i]; + + for (unsigned j = 0; j < d->nb_streams; j++) { + SchDemuxStream *ds = &d->streams[j]; + + if (!ds->nb_dst) { + av_log(d, AV_LOG_ERROR, + "Demuxer stream %u not connected to any sink\n", j); + return AVERROR(EINVAL); + } + + ds->dst_finished = av_calloc(ds->nb_dst, sizeof(*ds->dst_finished)); + if (!ds->dst_finished) + return AVERROR(ENOMEM); + } + } + + for (unsigned i = 0; i < sch->nb_dec; i++) { + SchDec *dec = &sch->dec[i]; + + if (!dec->src.type) { + av_log(dec, AV_LOG_ERROR, + "Decoder not connected to a source\n"); + return AVERROR(EINVAL); + } + if (!dec->nb_dst) { + av_log(dec, AV_LOG_ERROR, + "Decoder not connected to any sink\n"); + return AVERROR(EINVAL); + } + + dec->dst_finished = av_calloc(dec->nb_dst, sizeof(*dec->dst_finished)); + if (!dec->dst_finished) + return AVERROR(ENOMEM); + } + + for (unsigned i = 0; i < sch->nb_enc; i++) { + SchEnc *enc = &sch->enc[i]; + + if (!enc->src.type) { + av_log(enc, AV_LOG_ERROR, + "Encoder not connected to a source\n"); + return AVERROR(EINVAL); + } + if (!enc->nb_dst) { + av_log(enc, AV_LOG_ERROR, + "Encoder not connected to any sink\n"); + return AVERROR(EINVAL); + } + + enc->dst_finished = av_calloc(enc->nb_dst, sizeof(*enc->dst_finished)); + if (!enc->dst_finished) + return AVERROR(ENOMEM); + } for (unsigned i = 0; i < sch->nb_mux; i++) { SchMux *mux = &sch->mux[i]; @@ -1341,35 +1395,6 @@ int sch_start(Scheduler *sch) QUEUE_PACKETS); if (ret < 0) return ret; - - if (mux->nb_streams_ready == mux->nb_streams) { - ret = mux_init(sch, mux); - if (ret < 0) - return ret; - } - } - - for (unsigned i = 0; i < sch->nb_enc; i++) { - SchEnc *enc = &sch->enc[i]; - - if (!enc->src.type) { - av_log(enc, AV_LOG_ERROR, - "Encoder not connected to a source\n"); - return AVERROR(EINVAL); - } - if (!enc->nb_dst) { - av_log(enc, AV_LOG_ERROR, - "Encoder not connected to any sink\n"); - return AVERROR(EINVAL); - } - - enc->dst_finished = av_calloc(enc->nb_dst, sizeof(*enc->dst_finished)); - if (!enc->dst_finished) - return AVERROR(ENOMEM); - - ret = task_start(&enc->task); - if (ret < 0) - return ret; } for (unsigned i = 0; i < sch->nb_filters; i++) { @@ -1396,6 +1421,41 @@ int sch_start(Scheduler *sch) return AVERROR(EINVAL); } } + } + + return 0; +} + +int sch_start(Scheduler *sch) +{ + int ret; + + ret = start_prepare(sch); + if (ret < 0) + return ret; + + sch->transcode_started = 1; + + for (unsigned i = 0; i < sch->nb_mux; i++) { + SchMux *mux = &sch->mux[i]; + + if (mux->nb_streams_ready == mux->nb_streams) { + ret = mux_init(sch, mux); + if (ret < 0) + return ret; + } + } + + for (unsigned i = 0; i < sch->nb_enc; i++) { + SchEnc *enc = &sch->enc[i]; + + ret = task_start(&enc->task); + if (ret < 0) + return ret; + } + + for (unsigned i = 0; i < sch->nb_filters; i++) { + SchFilterGraph *fg = &sch->filters[i]; ret = task_start(&fg->task); if (ret < 0) @@ -1405,21 +1465,6 @@ int sch_start(Scheduler *sch) for (unsigned i = 0; i < sch->nb_dec; i++) { SchDec *dec = &sch->dec[i]; - if (!dec->src.type) { - av_log(dec, AV_LOG_ERROR, - "Decoder not connected to a source\n"); - return AVERROR(EINVAL); - } - if (!dec->nb_dst) { - av_log(dec, AV_LOG_ERROR, - "Decoder not connected to any sink\n"); - return AVERROR(EINVAL); - } - - dec->dst_finished = av_calloc(dec->nb_dst, sizeof(*dec->dst_finished)); - if (!dec->dst_finished) - return AVERROR(ENOMEM); - ret = task_start(&dec->task); if (ret < 0) return ret; @@ -1431,20 +1476,6 @@ int sch_start(Scheduler *sch) if (!d->nb_streams) continue; - for (unsigned j = 0; j < d->nb_streams; j++) { - SchDemuxStream *ds = &d->streams[j]; - - if (!ds->nb_dst) { - av_log(d, AV_LOG_ERROR, - "Demuxer stream %u not connected to any sink\n", j); - return AVERROR(EINVAL); - } - - ds->dst_finished = av_calloc(ds->nb_dst, sizeof(*ds->dst_finished)); - if (!ds->dst_finished) - return AVERROR(ENOMEM); - } - ret = task_start(&d->task); if (ret < 0) return ret; From patchwork Wed Mar 6 11:03:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46846 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp313946pzb; Wed, 6 Mar 2024 03:07:31 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUo/2fAHCgtecneh1WlL/xbbJngYd9OejLUsqZ4ZRjGOTPAAVZ1s1orhJ/u3YGQojwAFWux+zB2UqIEK4/YmmMNqRUC86zKRFF7bg== X-Google-Smtp-Source: AGHT+IHD+bbhHDy5Uho8oSjPcE2KBMQfHARkwT0x0wkaTpS+mdWH4Sc8li3rr21MAD+Rh+Hasd5Z X-Received: by 2002:a05:6402:511:b0:566:abbd:c390 with SMTP id m17-20020a056402051100b00566abbdc390mr5470350edv.6.1709723251489; Wed, 06 Mar 2024 03:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723251; cv=none; d=google.com; s=arc-20160816; b=uKdXyJV7bLAEy5Vynjqai5ERIab7emUirexUFp3HE5bpQ9zswHoN2TfTxrpXiuZLl7 k7iLuPV0b9I+CSeUqfh27mlBmRUDkvGNPYFgi2TV7/frrab7MuU25YCfUot01yF9AFl0 jkLHiYW8mq5IDQV1XnGpHWTgGGfJNQDjRJ1re/yti7otJp/XTx2FGHmnVKPx/k44RCPk 6vv6AhSRJUTphimJ5MtmFCoSn/94UQkhsoy0qik6ljLWTl26C4bC97GdzXms21F+6uHg XYBVmjEspjE89qRPgKFPVJMb2X6rfYkCcAPu7HRzQPcjj8gfhlePelJFF3jn/LVDgVk5 kaww== 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:dkim-signature:delivered-to; bh=GYdxFZxCH65m/+GqYRz2El1l7c5TtL8RLPnPFVAmU8o=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=uB1m4HuzvZKgjmijZaxrCbc0hUm4vtngJOTZGEqlDrsi4BLJA1bXjRtFsL8sGonVhS JNa21ueg0QXF2yupN8byxqevTDHN5qjaouNPuxWMkkn4V4H/AHx0bqMjukBvBgnSKVZn 1fLj8OSqWAd+DpKdIfE1WL506N3WXs12nxBGmZH0WRW+FUbhOS3eSAQdpYbaJ/PpzFgt e5v/lBY/KuEvAZyiDhnEm3TyIgjZG3T630xZbGfCHPtH9Q5yqSpqSab3DV6yEutAkxdw WfmCQ/XD/BOpbr4nbKRt8TJFQ0CAAUr6Jf2S4e+kD3gaydqn+sYk637SGiC40Dxdl4l5 1t+w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=GsAafDAa; 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 y2-20020a056402440200b00565d035f48esi6118360eda.158.2024.03.06.03.07.31; Wed, 06 Mar 2024 03:07:31 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=GsAafDAa; 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 7BD9C68CEC6; Wed, 6 Mar 2024 13:05:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D625268C97D for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=GsAafDAa; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 3C7A84D5E for ; Wed, 6 Mar 2024 12:05:28 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id WLj93cWDY4JK for ; Wed, 6 Mar 2024 12:05:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=4awKoN74/by19YpqsLKevaNe3F+jj2LiOrlfYYGZjCM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GsAafDAa03U+JHrMFcriLAvpMB7Xp2i96rVFAHv4xJ8dt7pZn0HoM4uFqfDFUXuKE KRWuwqNYf0voPEcaioQ84oEY2nFp0VOhFk8G6Nt7rrXMAKnvt8nO48i5zquIlFT7ri AQMWZMQs9gGfSBZJC+neTkM4i+f9edwtvm5hp0ypZ4eGzfIiivD59yqCIUiD1zPv7u DFI509wnVThD2bl3hs3AUymoY5Zha/vrQhUcyPUyNI3SVGe2wTaljr41jL4TqAq8JZ jlmj+DniAoW2dpyvqMtb4ajyo+/80fsxCyyvLyf7t2Q9/ZJKSX8JEz6M9GrZUA6Ry8 QvTsHF29D1S6Q== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 3DCFD4D61 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 304873A0357 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:16 +0100 Message-ID: <20240306110319.17339-15-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 15/18] fftools/ffmpeg_sched: allow connecting encoder output to decoders X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: S+iFYlBjFykM --- fftools/ffmpeg_sched.c | 212 ++++++++++++++++++++++++++++++++++------- fftools/ffmpeg_sched.h | 8 +- 2 files changed, 181 insertions(+), 39 deletions(-) diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c index 5f8ef04680..d1fb942c34 100644 --- a/fftools/ffmpeg_sched.c +++ b/fftools/ffmpeg_sched.c @@ -1051,24 +1051,43 @@ int sch_connect(Scheduler *sch, SchedulerNode src, SchedulerNode dst) } case SCH_NODE_TYPE_ENC: { SchEnc *enc; - SchMuxStream *ms; av_assert0(src.idx < sch->nb_enc); - // encoding packets go to muxing - av_assert0(dst.type == SCH_NODE_TYPE_MUX && - dst.idx < sch->nb_mux && - dst.idx_stream < sch->mux[dst.idx].nb_streams); enc = &sch->enc[src.idx]; - ms = &sch->mux[dst.idx].streams[dst.idx_stream]; - - av_assert0(!ms->src.type); ret = GROW_ARRAY(enc->dst, enc->nb_dst); if (ret < 0) return ret; enc->dst[enc->nb_dst - 1] = dst; - ms->src = src; + + // encoding packets go to muxing or decoding + switch (dst.type) { + case SCH_NODE_TYPE_MUX: { + SchMuxStream *ms; + + av_assert0(dst.idx < sch->nb_mux && + dst.idx_stream < sch->mux[dst.idx].nb_streams); + ms = &sch->mux[dst.idx].streams[dst.idx_stream]; + + av_assert0(!ms->src.type); + ms->src = src; + + break; + } + case SCH_NODE_TYPE_DEC: { + SchDec *dec; + + av_assert0(dst.idx < sch->nb_dec); + dec = &sch->dec[dst.idx]; + + av_assert0(!dec->src.type); + dec->src = src; + + break; + } + default: av_assert0(0); + } break; } @@ -1217,6 +1236,31 @@ int sch_mux_sub_heartbeat_add(Scheduler *sch, unsigned mux_idx, unsigned stream_ return 0; } +static void unchoke_for_stream(Scheduler *sch, SchedulerNode src) +{ + while (1) { + SchFilterGraph *fg; + + // fed directly by a demuxer (i.e. not through a filtergraph) + if (src.type == SCH_NODE_TYPE_DEMUX) { + sch->demux[src.idx].waiter.choked_next = 0; + return; + } + + av_assert0(src.type == SCH_NODE_TYPE_FILTER_OUT); + fg = &sch->filters[src.idx]; + + // the filtergraph contains internal sources and + // requested to be scheduled directly + if (fg->best_input == fg->nb_inputs) { + fg->waiter.choked_next = 0; + return; + } + + src = fg->inputs[fg->best_input].src_sched; + } +} + static void schedule_update_locked(Scheduler *sch) { int64_t dts; @@ -1245,7 +1289,6 @@ static void schedule_update_locked(Scheduler *sch) for (unsigned j = 0; j < mux->nb_streams; j++) { SchMuxStream *ms = &mux->streams[j]; - SchDemux *d; // unblock sources for output streams that are not finished // and not too far ahead of the trailing stream @@ -1256,28 +1299,9 @@ static void schedule_update_locked(Scheduler *sch) if (dts != AV_NOPTS_VALUE && ms->last_dts - dts >= SCHEDULE_TOLERANCE) continue; - // for outputs fed from filtergraphs, consider that filtergraph's - // best_input information, in other cases there is a well-defined - // source demuxer - if (ms->src_sched.type == SCH_NODE_TYPE_FILTER_OUT) { - SchFilterGraph *fg = &sch->filters[ms->src_sched.idx]; - SchFilterIn *fi; - - // the filtergraph contains internal sources and - // requested to be scheduled directly - if (fg->best_input == fg->nb_inputs) { - fg->waiter.choked_next = 0; - have_unchoked = 1; - continue; - } - - fi = &fg->inputs[fg->best_input]; - d = &sch->demux[fi->src_sched.idx]; - } else - d = &sch->demux[ms->src_sched.idx]; - - d->waiter.choked_next = 0; - have_unchoked = 1; + // resolve the source to unchoke + unchoke_for_stream(sch, ms->src_sched); + have_unchoked = 1; } } @@ -1303,6 +1327,105 @@ static void schedule_update_locked(Scheduler *sch) } +enum { + CYCLE_NODE_NEW = 0, + CYCLE_NODE_STARTED, + CYCLE_NODE_DONE, +}; + +static int +check_acyclic_for_output(const Scheduler *sch, SchedulerNode src, + uint8_t *filters_visited, SchedulerNode *filters_stack) +{ + unsigned nb_filters_stack = 0; + + memset(filters_visited, 0, sch->nb_filters * sizeof(*filters_visited)); + + while (1) { + const SchFilterGraph *fg = &sch->filters[src.idx]; + + filters_visited[src.idx] = CYCLE_NODE_STARTED; + + // descend into every input, depth first + if (src.idx_stream < fg->nb_inputs) { + const SchFilterIn *fi = &fg->inputs[src.idx_stream++]; + + // connected to demuxer, no cycles possible + if (fi->src_sched.type == SCH_NODE_TYPE_DEMUX) + continue; + + // otherwise connected to another filtergraph + av_assert0(fi->src_sched.type == SCH_NODE_TYPE_FILTER_OUT); + + // found a cycle + if (filters_visited[fi->src_sched.idx] == CYCLE_NODE_STARTED) + return AVERROR(EINVAL); + + // place current position on stack and descend + av_assert0(nb_filters_stack < sch->nb_filters); + filters_stack[nb_filters_stack++] = src; + src = (SchedulerNode){ .idx = fi->src_sched.idx, .idx_stream = 0 }; + continue; + } + + filters_visited[src.idx] = CYCLE_NODE_DONE; + + // previous search finished, + if (nb_filters_stack) { + src = filters_stack[--nb_filters_stack]; + continue; + } + return 0; + } +} + +static int check_acyclic(Scheduler *sch) +{ + uint8_t *filters_visited = NULL; + SchedulerNode *filters_stack = NULL; + + int ret = 0; + + if (!sch->nb_filters) + return 0; + + filters_visited = av_malloc_array(sch->nb_filters, sizeof(*filters_visited)); + if (!filters_visited) + return AVERROR(ENOMEM); + + filters_stack = av_malloc_array(sch->nb_filters, sizeof(*filters_stack)); + if (!filters_stack) { + ret = AVERROR(ENOMEM); + goto fail; + } + + // trace the transcoding graph upstream from every output stream + // fed by a filtergraph + for (unsigned i = 0; i < sch->nb_mux; i++) { + SchMux *mux = &sch->mux[i]; + + for (unsigned j = 0; j < mux->nb_streams; j++) { + SchMuxStream *ms = &mux->streams[j]; + SchedulerNode src = ms->src_sched; + + if (src.type != SCH_NODE_TYPE_FILTER_OUT) + continue; + src.idx_stream = 0; + + ret = check_acyclic_for_output(sch, src, filters_visited, filters_stack); + if (ret < 0) { + av_log(mux, AV_LOG_ERROR, "Transcoding graph has a cycle\n"); + goto fail; + } + } + } + +fail: + av_freep(&filters_visited); + av_freep(&filters_stack); + return ret; +} + static int start_prepare(Scheduler *sch) { int ret; @@ -1402,14 +1525,21 @@ static int start_prepare(Scheduler *sch) for (unsigned j = 0; j < fg->nb_inputs; j++) { SchFilterIn *fi = &fg->inputs[j]; + SchDec *dec; if (!fi->src.type) { av_log(fg, AV_LOG_ERROR, "Filtergraph input %u not connected to a source\n", j); return AVERROR(EINVAL); } + av_assert0(fi->src.type == SCH_NODE_TYPE_DEC); + dec = &sch->dec[fi->src.idx]; - fi->src_sched = sch->dec[fi->src.idx].src; + switch (dec->src.type) { + case SCH_NODE_TYPE_DEMUX: fi->src_sched = dec->src; break; + case SCH_NODE_TYPE_ENC: fi->src_sched = sch->enc[dec->src.idx].src; break; + default: av_assert0(0); + } } for (unsigned j = 0; j < fg->nb_outputs; j++) { @@ -1423,6 +1553,11 @@ static int start_prepare(Scheduler *sch) } } + // Check that the transcoding graph has no cycles. + ret = check_acyclic(sch); + if (ret < 0) + return ret; + return 0; } @@ -1575,6 +1710,8 @@ static int send_to_enc_sq(Scheduler *sch, SchEnc *enc, AVFrame *frame) SchMux *mux; SchMuxStream *ms; + if (enc->dst[i].type != SCH_NODE_TYPE_MUX) + continue; mux = &sch->mux[enc->dst[i].idx]; ms = &mux->streams[enc->dst[i].idx_stream]; @@ -2150,14 +2287,19 @@ static int enc_send_to_dst(Scheduler *sch, const SchedulerNode dst, if (!pkt) goto finish; - ret = send_to_mux(sch, &sch->mux[dst.idx], dst.idx_stream, pkt); + ret = (dst.type == SCH_NODE_TYPE_MUX) ? + send_to_mux(sch, &sch->mux[dst.idx], dst.idx_stream, pkt) : + tq_send(sch->dec[dst.idx].queue, 0, pkt); if (ret == AVERROR_EOF) goto finish; return ret; finish: - send_to_mux(sch, &sch->mux[dst.idx], dst.idx_stream, NULL); + if (dst.type == SCH_NODE_TYPE_MUX) + send_to_mux(sch, &sch->mux[dst.idx], dst.idx_stream, NULL); + else + tq_send_finish(sch->dec[dst.idx].queue, 0); *dst_finished = 1; diff --git a/fftools/ffmpeg_sched.h b/fftools/ffmpeg_sched.h index fc6711f9c3..a9190bd3d1 100644 --- a/fftools/ffmpeg_sched.h +++ b/fftools/ffmpeg_sched.h @@ -35,9 +35,9 @@ * - demuxers, each containing any number of demuxed streams; demuxed packets * belonging to some stream are sent to any number of decoders (transcoding) * and/or muxers (streamcopy); - * - decoders, which receive encoded packets from some demuxed stream, decode - * them, and send decoded frames to any number of filtergraph inputs - * (audio/video) or encoders (subtitles); + * - decoders, which receive encoded packets from some demuxed stream or + * encoder, decode them, and send decoded frames to any number of filtergraph + * inputs (audio/video) or encoders (subtitles); * - filtergraphs, each containing zero or more inputs (0 in case the * filtergraph contains a lavfi source filter), and one or more outputs; the * inputs and outputs need not have matching media types; @@ -45,7 +45,7 @@ * filtered frames from each output are sent to some encoder; * - encoders, which receive decoded frames from some decoder (subtitles) or * some filtergraph output (audio/video), encode them, and send encoded - * packets to some muxed stream; + * packets to any number of muxed streams or decoders; * - muxers, each containing any number of muxed streams; each muxed stream * receives encoded packets from some demuxed stream (streamcopy) or some * encoder (transcoding); those packets are interleaved and written out by the From patchwork Wed Mar 6 11:03:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46835 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp314029pzb; Wed, 6 Mar 2024 03:07:42 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX1QrzrLzkJxvL3Y50MdF99nc295fTyXh/DKEUkBrlZwg9d82NGsQcKe4sG9JK1dD9cOpjBrZjiZxcVoqdUi9XdkoAvLSlMP8HbSA== X-Google-Smtp-Source: AGHT+IEe9CIGXS6xvPUzS44xALosz1I9hjQ1R4eUgEngoyNxriSZWN3CkbrL9zLymFbFqVYwXTHf X-Received: by 2002:a17:906:3941:b0:a3f:ce8:1234 with SMTP id g1-20020a170906394100b00a3f0ce81234mr10176912eje.68.1709723262037; Wed, 06 Mar 2024 03:07:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723262; cv=none; d=google.com; s=arc-20160816; b=aUVL6QfeK67nf4viK4/+f3ffWE1GEE3QTTO3/k0WJzvPwOCD8XrFAq3scsO9pirgTk 1VnGews0v85ZD7oaCBUTrqWjGelMpgvxUzFZukYHe+cs49g6dUdxAn4Q3n/0N4kHelOb syn5ZD5X75FGmWl46SzX0UuF3mgK3XeUrdTMOx8efrw8yoNQFqtZ/gaJlrj9ONwAHSgR x3j5MDAja8rXU3Spr2Nmwh9jfvlGGZs+OKommq19lc+qMkmgTowEzawLG0F+9oWf+vjs jrMWZmMjLDIQzg1Rcrhy6o34jgXGH5/vJ1ifEopW9NjqdNrH+yIvlrcLJV3bZv6+pPAs VA1A== 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:dkim-signature:delivered-to; bh=trF6W/nicaQVnMRkrOADcm6sRsDOI7oLGb0sDp+uG5A=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=dsWRizOibPxyKmxoOWq6PwW+DfQvsVVYroVVmLWGnNPaKG4bAvIeMpdG0FLcIPfpbP JhUXM24HHhWTPNroC4WdCG0gbYpyEzR0vZby5B4NrwNv3Zzig7iBXVC9Pi5EWqopK4Nv GQPUZEq7mLZDZQHasLjBnk5SkuUsoECTu8+E6eBo8JgPQOZxMkd7EkdQaC/sV0Mk5R4N CeVYvBlKc0PCTB8XHOhyTbMtvQ6NEBqh/NKRdpHX95IaKyUdSP+qbdAS/IMRfClqT3A3 hlukQ3TuX1A8q50IrL4sQxFuZNttQt3YliwEHuL3Rrip+BjcZtGrzjb+h5SPKoyVsUh7 35rQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=ImYZicdI; 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 k16-20020a17090627d000b00a456423c7e1si2560155ejc.692.2024.03.06.03.07.41; Wed, 06 Mar 2024 03:07:42 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=ImYZicdI; 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 096AE68B5A1; Wed, 6 Mar 2024 13:05:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE5CA68C462 for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=ImYZicdI; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id AC7344D5D for ; Wed, 6 Mar 2024 12:05:27 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 8wDlg90uQe9t for ; Wed, 6 Mar 2024 12:05:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=0/n618pxJ/PVbuCl3zqWaGMuZvEVOdMRJzX9LIcQDUI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ImYZicdItpXyJJLZyZN/QzdaauQmuXsn6icohSfINrEjhZRmfd3Rcn+1kMxcn9HJZ dZkBixqGg381eu1nVmLjIwH1eQs94PfLP7gjXPP8ERDtw77815qGWFUDaLYjKgp377 rhoEBsRis8OSmMeNYyERbBE+QEI77NpEAPQ9TrCQi6cpNSMDCx8G4FpFqGcEfwM8oc xR138F6fYGPuLJd+6CfeuLo68/202d8M6Kub7JaUrVJToJkPyDL6ZIdY3D8he95+Qv 5iejNuqFNVJ6NkxwH95VpfoHB7dLS6YllGD1qowgsu/pilI+gj+g6+W6ilkB0iWMOI YcZfifBfrDbLg== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 48CDD4D62 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 3BE833A076E for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:17 +0100 Message-ID: <20240306110319.17339-16-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 16/18] fftools/ffmpeg: prepare FrameData for having allocated fields 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: 7QswKJhzNoh8 Will be useful in following commits. --- fftools/ffmpeg.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index 2f01a01e2d..ffd25f4c5b 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -402,23 +402,44 @@ InputStream *ist_iter(InputStream *prev) return NULL; } +static void frame_data_free(void *opaque, uint8_t *data) +{ + av_free(data); +} + static int frame_data_ensure(AVBufferRef **dst, int writable) { - if (!*dst) { + AVBufferRef *src = *dst; + + if (!src || (writable && !av_buffer_is_writable(src))) { FrameData *fd; - *dst = av_buffer_allocz(sizeof(*fd)); - if (!*dst) + fd = av_mallocz(sizeof(*fd)); + if (!fd) return AVERROR(ENOMEM); - fd = (FrameData*)((*dst)->data); - fd->dec.frame_num = UINT64_MAX; - fd->dec.pts = AV_NOPTS_VALUE; + *dst = av_buffer_create((uint8_t *)fd, sizeof(*fd), + frame_data_free, NULL, 0); + if (!*dst) { + av_buffer_unref(&src); + av_freep(&fd); + return AVERROR(ENOMEM); + } - for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i++) - fd->wallclock[i] = INT64_MIN; - } else if (writable) - return av_buffer_make_writable(dst); + if (src) { + const FrameData *fd_src = (const FrameData *)src->data; + + memcpy(fd, fd_src, sizeof(*fd)); + + av_buffer_unref(&src); + } else { + fd->dec.frame_num = UINT64_MAX; + fd->dec.pts = AV_NOPTS_VALUE; + + for (unsigned i = 0; i < FF_ARRAY_ELEMS(fd->wallclock); i++) + fd->wallclock[i] = INT64_MIN; + } + } return 0; } From patchwork Wed Mar 6 11:03:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46848 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp314193pzb; Wed, 6 Mar 2024 03:08:01 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUJ8cmU42AMMQwF7VdStG4oyeVj5HSDG73ocBWy+FErUIPQz/2I5XIJ7OyKAI0kUiOttPnCvq5VdS1qgqifGZZhw5ZVyVjpzqZV4g== X-Google-Smtp-Source: AGHT+IGJgciRMonh/DN0PpuxF6jFDmj3Wqm6jMGc4hfM3i81dUYMpbcPsWsQssJ2nTPxg9KnrfTV X-Received: by 2002:a50:85c3:0:b0:566:5cd2:873 with SMTP id q3-20020a5085c3000000b005665cd20873mr5674251edh.4.1709723281689; Wed, 06 Mar 2024 03:08:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723281; cv=none; d=google.com; s=arc-20160816; b=nqIpdD1A8UWFVGkbV5F0ee7u+E8NZ1qXKgfNWqDj2hdMi4wSeGMXf0CBX1xdYaAJSF iPxpgIiTpBdlcRN0vZfojM8u/Tpik3QIkq+Eccu0wzuokXNLQXE06dGPFgKvCCAF2L0l qmZjuk5X5gJLRKXPUC5pncwNlEhyHa9SGOQRIwpkALlly+b8t4TIZrETlBqO4/3n1wt2 r/whNycdKx0lOEtmSJ2NUvIWMCJwsDPg8oqrmI+bMcFUvPcySeOoLLtANdezZjjadKzL 5j+eu121gYytUUytI3o0imoTu+2DQVbjtilS5rHYzNqr0l7Q0Bl0TuqUSVswR169ozse SGWQ== 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:dkim-signature:delivered-to; bh=s/jm5UiU9i6XvKEwKeFeUrahE9tQGHEGgeos9a2WkQA=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=IgtfjfNupaJTjPBOTcCu5xDsYTvib7yvm3h021mkI01uKWAcFfwscpOIfmD43DhhJM jGiN1N3rbrAn9PoH+CcjaAt1rIX9oH73N9BgfuwNEBRHJM7R1KrYvztrAt8/lVYW3lgS n+UHLteQZYYriBQDPqvVBm/5noTYdK1vQdIpqSZYlsl+gyl7utjtp86eI9DYyQVn3M2S HVPSZK216CQR1n20Cx2djZGG0WrWtLqABGPZ+OUqbIJYsGP1rw8BNoLXfShCmM0GdFWE 0MHNUf6GqaUo9yakLx9wPkxmPUxlM2NjJgbzqvlnGLT4UjwKdgF1XCu64COWwqEO33fa 1x5Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=UNCI9OuC; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s15-20020a05640217cf00b00564479629ecsi5855950edy.575.2024.03.06.03.08.01; Wed, 06 Mar 2024 03:08:01 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=UNCI9OuC; 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 F13A368CF0F; Wed, 6 Mar 2024 13:05:46 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E037D68CCE7 for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=UNCI9OuC; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 1D2464D61 for ; Wed, 6 Mar 2024 12:05:29 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ySyaQNe18tTY for ; Wed, 6 Mar 2024 12:05:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=MzLd4EdXtCNf3HRSTzNEWW3Mf00e+3vo0782G3Fcc7w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=UNCI9OuCTRozmm923RhBu6aewADtwoS1EGfDIBBi95ArV/wpYkpAwMJj+mB6Wkqct jQKihM1C6p1X+dMvSw7Oihfnim7ZE+aey/wtzFzXQuAXCEg/RbZFQCZZmWql2+fbpa ZmT13d0pzU4pG1miD8JznrNwtnVtrhdVE40lCwrX75//A8YEfrHlZ5ke3fU7lobMSi H3fpNck8KQxn0RJ1oOmda+yFlF0sWxmu7Vi985867VJ/pr2PKWx3vlZUXT4w4kPHQY Gmzw1ovTwXWjzQ/+NKYdsgbK8VKjp2VjffVcVHy9poKiBdDUaZn9siC0A1UigtaDcf PC54QP+MjbwYw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 5444B4D64 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 483FB3A0582 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:18 +0100 Message-ID: <20240306110319.17339-17-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/18] fftools/ffmpeg: add loopback decoding 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: /oa+NToht5A1 This allows to send an encoder's output back to decoding and feed the result into a complex filtergraph. --- Changelog | 1 + doc/ffmpeg.texi | 49 ++++++++++-- fftools/cmdutils.c | 2 +- fftools/cmdutils.h | 7 +- fftools/ffmpeg.c | 26 +++++++ fftools/ffmpeg.h | 22 ++++++ fftools/ffmpeg_dec.c | 164 +++++++++++++++++++++++++++++++++++++++- fftools/ffmpeg_enc.c | 19 +++++ fftools/ffmpeg_filter.c | 47 +++++++++++- fftools/ffmpeg_opt.c | 13 +++- 10 files changed, 336 insertions(+), 14 deletions(-) diff --git a/Changelog b/Changelog index 0ba3a77c08..22186697fb 100644 --- a/Changelog +++ b/Changelog @@ -31,6 +31,7 @@ version : - removed deprecated ffmpeg CLI options -psnr and -map_channel - DVD-Video demuxer, powered by libdvdnav and libdvdread - ffprobe -show_stream_groups option +- ffmpeg CLI loopback decoders version 6.1: diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index bee3cd4c70..650011e6d2 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -219,6 +219,40 @@ Since there is no decoding or encoding, it is very fast and there is no quality loss. However, it might not work in some cases because of many factors. Applying filters is obviously also impossible, since filters work on uncompressed data. +@section Loopback decoders +While decoders are normally associated with demuxer streams, it is also possible +to create "loopback" decoders that decode the output from some encoder and allow +it to be fed back to complex filtergraphs. This is done with the @code{-dec} +directive, which takes as a parameter the index of the output stream that should +be decoded. Every such directive creates a new loopback decoder, indexed with +successive integers starting at zero. These indices should then be used to refer +to loopback decoders in complex filtergraph link labels, as described in the +documentation for @option{-filter_complex}. + +E.g. the following example: + +@example +ffmpeg -i INPUT \ + -map 0:v:0 -c:v libx264 -crf 45 -f null - \ + -dec 0:0 -filter_complex '[0:v][dec0]hstack[stack]' \ + -map '[stack]' -c:v ffv1 OUTPUT +@end example + +reads an input video and +@itemize +@item +(line 2) encodes it with @code{libx264} at low quality; + +@item +(line 3) decodes this encoded stream and places it side by side with the +original input video; + +@item +(line 4) combined video is then losslessly encoded and written into +@file{OUTPUT}. + +@end itemize + @c man end DETAILED DESCRIPTION @chapter Stream selection @@ -2105,11 +2139,16 @@ type -- see the @option{-filter} options. @var{filtergraph} is a description of the filtergraph, as described in the ``Filtergraph syntax'' section of the ffmpeg-filters manual. -Input link labels must refer to input streams using the -@code{[file_index:stream_specifier]} syntax (i.e. the same as @option{-map} -uses). If @var{stream_specifier} matches multiple streams, the first one will be -used. An unlabeled input will be connected to the first unused input stream of -the matching type. +Input link labels must refer to either input streams or loopback decoders. For +input streams, use the @code{[file_index:stream_specifier]} syntax (i.e. the +same as @option{-map} uses). If @var{stream_specifier} matches multiple streams, +the first one will be used. + +For decoders, the link label must be [dec@var{dec_idx}], where @var{dec_idx} is +the index of the loopback decoder to be connected to given input. + +An unlabeled input will be connected to the first unused input stream of the +matching type. Output link labels are referred to with @option{-map}. Unlabeled outputs are added to the first output file. diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 8efec942bd..f3c258bb99 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -528,7 +528,7 @@ static void check_options(const OptionDef *po) { while (po->name) { if (po->flags & OPT_PERFILE) - av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT)); + av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT | OPT_DECODER)); if (po->type == OPT_TYPE_FUNC) av_assert0(!(po->flags & (OPT_FLAG_OFFSET | OPT_FLAG_SPEC))); diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h index 86428b3fa4..d0c773663b 100644 --- a/fftools/cmdutils.h +++ b/fftools/cmdutils.h @@ -144,8 +144,8 @@ typedef struct OptionDef { #define OPT_AUDIO (1 << 4) #define OPT_SUBTITLE (1 << 5) #define OPT_DATA (1 << 6) -/* The option is per-file (currently ffmpeg-only). At least one of OPT_INPUT or - * OPT_OUTPUT must be set when this flag is in use. +/* The option is per-file (currently ffmpeg-only). At least one of OPT_INPUT, + * OPT_OUTPUT, OPT_DECODER must be set when this flag is in use. */ #define OPT_PERFILE (1 << 7) @@ -175,6 +175,9 @@ typedef struct OptionDef { * name is stored in u1.name_canon */ #define OPT_HAS_CANON (1 << 14) +/* ffmpeg-only - OPT_PERFILE may apply to standalone decoders */ +#define OPT_DECODER (1 << 15) + union { void *dst_ptr; int (*func_arg)(void *, const char *, const char *); diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index ffd25f4c5b..d4e5f978f1 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -131,6 +131,9 @@ int nb_output_files = 0; FilterGraph **filtergraphs; int nb_filtergraphs; +Decoder **decoders; +int nb_decoders; + #if HAVE_TERMIOS_H /* init terminal so that we can grab keys */ @@ -340,6 +343,10 @@ static void ffmpeg_cleanup(int ret) for (int i = 0; i < nb_input_files; i++) ifile_close(&input_files[i]); + for (int i = 0; i < nb_decoders; i++) + dec_free(&decoders[i]); + av_freep(&decoders); + if (vstats_file) { if (fclose(vstats_file)) av_log(NULL, AV_LOG_ERROR, @@ -404,6 +411,10 @@ InputStream *ist_iter(InputStream *prev) static void frame_data_free(void *opaque, uint8_t *data) { + FrameData *fd = (FrameData *)data; + + avcodec_parameters_free(&fd->par_enc); + av_free(data); } @@ -430,6 +441,21 @@ static int frame_data_ensure(AVBufferRef **dst, int writable) const FrameData *fd_src = (const FrameData *)src->data; memcpy(fd, fd_src, sizeof(*fd)); + fd->par_enc = NULL; + + if (fd_src->par_enc) { + int ret = 0; + + fd->par_enc = avcodec_parameters_alloc(); + ret = fd->par_enc ? + avcodec_parameters_copy(fd->par_enc, fd_src->par_enc) : + AVERROR(ENOMEM); + if (ret < 0) { + av_buffer_unref(dst); + av_buffer_unref(&src); + return ret; + } + } av_buffer_unref(&src); } else { diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 1966817bc3..7454089c2d 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -331,6 +331,8 @@ typedef struct DecoderOpts { typedef struct Decoder { const AVClass *class; + enum AVMediaType type; + const uint8_t *subtitle_header; int subtitle_header_size; @@ -606,6 +608,8 @@ typedef struct FrameData { int bits_per_raw_sample; int64_t wallclock[LATENCY_PROBE_NB]; + + AVCodecParameters *par_enc; } FrameData; extern InputFile **input_files; @@ -617,6 +621,10 @@ extern int nb_output_files; extern FilterGraph **filtergraphs; extern int nb_filtergraphs; +// standalone decoders (not tied to demuxed streams) +extern Decoder **decoders; +extern int nb_decoders; + extern char *vstats_filename; extern float dts_delta_threshold; @@ -734,6 +742,11 @@ void hw_device_free_all(void); */ AVBufferRef *hw_device_for_filter(void); +/** + * Create a standalone decoder. + */ +int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch); + /** * @param dec_opts Dictionary filled with decoder options. Its ownership * is transferred to the decoder. @@ -748,12 +761,21 @@ int dec_init(Decoder **pdec, Scheduler *sch, AVFrame *param_out); void dec_free(Decoder **pdec); +/* + * Called by filters to connect decoder's output to given filtergraph input. + * + * @param opts filtergraph input options, to be filled by this function + */ +int dec_filter_add(Decoder *dec, InputFilter *ifilter, InputFilterOptions *opts); + int enc_alloc(Encoder **penc, const AVCodec *codec, Scheduler *sch, unsigned sch_idx); void enc_free(Encoder **penc); int enc_open(void *opaque, const AVFrame *frame); +int enc_loopback(Encoder *enc); + /* * Initialize muxing state for the given stream, should be called * after the codec/streamcopy setup has been done. diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c index 3bf7ab4960..c41c5748e5 100644 --- a/fftools/ffmpeg_dec.c +++ b/fftools/ffmpeg_dec.c @@ -17,6 +17,7 @@ */ #include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include "libavutil/dict.h" #include "libavutil/error.h" #include "libavutil/log.h" @@ -71,9 +72,16 @@ typedef struct DecoderPriv { Scheduler *sch; unsigned sch_idx; + // this decoder's index in decoders or -1 + int index; void *log_parent; char log_name[32]; char *parent_name; + + struct { + AVDictionary *opts; + const AVCodec *codec; + } standalone_init; } DecoderPriv; static DecoderPriv *dp_from_dec(Decoder *d) @@ -101,6 +109,8 @@ void dec_free(Decoder **pdec) av_frame_free(&dp->frame); av_packet_free(&dp->pkt); + av_dict_free(&dp->standalone_init.opts); + for (int i = 0; i < FF_ARRAY_ELEMS(dp->sub_prev); i++) av_frame_free(&dp->sub_prev[i]); av_frame_free(&dp->sub_heartbeat); @@ -145,6 +155,7 @@ static int dec_alloc(DecoderPriv **pdec, Scheduler *sch, int send_end_ts) if (!dp->pkt) goto fail; + dp->index = -1; dp->dec.class = &dec_class; dp->last_filter_in_rescale_delta = AV_NOPTS_VALUE; dp->last_frame_pts = AV_NOPTS_VALUE; @@ -754,11 +765,56 @@ static int packet_decode(DecoderPriv *dp, AVPacket *pkt, AVFrame *frame) } } +static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, + const DecoderOpts *o, AVFrame *param_out); + +static int dec_standalone_open(DecoderPriv *dp, const AVPacket *pkt) +{ + DecoderOpts o; + const FrameData *fd; + char name[16]; + + if (!pkt->opaque_ref) + return AVERROR_BUG; + fd = (FrameData *)pkt->opaque_ref->data; + + if (!fd->par_enc) + return AVERROR_BUG; + + memset(&o, 0, sizeof(o)); + + o.par = fd->par_enc; + o.time_base = pkt->time_base; + + o.codec = dp->standalone_init.codec; + if (!o.codec) + o.codec = avcodec_find_decoder(o.par->codec_id); + if (!o.codec) { + const AVCodecDescriptor *desc = avcodec_descriptor_get(o.par->codec_id); + + av_log(dp, AV_LOG_ERROR, "Cannot find a decoder for codec ID '%s'\n", + desc ? desc->name : "?"); + return AVERROR_DECODER_NOT_FOUND; + } + + snprintf(name, sizeof(name), "dec%d", dp->index); + o.name = name; + + return dec_open(dp, &dp->standalone_init.opts, &o, NULL); +} + static void dec_thread_set_name(const DecoderPriv *dp) { - char name[16]; - snprintf(name, sizeof(name), "dec%s:%s", dp->parent_name, - dp->dec_ctx->codec->name); + char name[16] = "dec"; + + if (dp->index >= 0) + av_strlcatf(name, sizeof(name), "%d", dp->index); + else if (dp->parent_name) + av_strlcat(name, dp->parent_name, sizeof(name)); + + if (dp->dec_ctx) + av_strlcatf(name, sizeof(name), ":%s", dp->dec_ctx->codec->name); + ff_thread_setname(name); } @@ -814,6 +870,22 @@ static int decoder_thread(void *arg) av_log(dp, AV_LOG_VERBOSE, "Decoder thread received %s packet\n", flush_buffers ? "flush" : "EOF"); + // this is a standalone decoder that has not been initialized yet + if (!dp->dec_ctx) { + if (flush_buffers) + continue; + if (input_status < 0) { + av_log(dp, AV_LOG_ERROR, + "Cannot initialize a standalone decoder\n"); + ret = input_status; + goto finish; + } + + ret = dec_standalone_open(dp, dt.pkt); + if (ret < 0) + goto finish; + } + ret = packet_decode(dp, have_data ? dt.pkt : NULL, dt.frame); av_packet_unref(dt.pkt); @@ -1075,6 +1147,7 @@ static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts, dp->flags = o->flags; dp->log_parent = o->log_parent; + dp->dec.type = codec->type; dp->framerate_in = o->framerate; dp->hwaccel_id = o->hwaccel_id; @@ -1188,3 +1261,88 @@ fail: dec_free((Decoder**)&dp); return ret; } + +int dec_create(const OptionsContext *o, const char *arg, Scheduler *sch) +{ + DecoderPriv *dp; + + OutputFile *of; + OutputStream *ost; + int of_index, ost_index; + char *p; + + unsigned enc_idx; + int ret; + + ret = dec_alloc(&dp, sch, 0); + if (ret < 0) + return ret; + + dp->index = nb_decoders; + + ret = GROW_ARRAY(decoders, nb_decoders); + if (ret < 0) { + dec_free((Decoder **)&dp); + return ret; + } + + decoders[nb_decoders - 1] = (Decoder *)dp; + + of_index = strtol(arg, &p, 0); + if (of_index < 0 || of_index >= nb_output_files) { + av_log(dp, AV_LOG_ERROR, "Invalid output file index '%d' in %s\n", of_index, arg); + return AVERROR(EINVAL); + } + of = output_files[of_index]; + + ost_index = strtol(p + 1, NULL, 0); + if (ost_index < 0 || ost_index >= of->nb_streams) { + av_log(dp, AV_LOG_ERROR, "Invalid output stream index '%d' in %s\n", ost_index, arg); + return AVERROR(EINVAL); + } + ost = of->streams[ost_index]; + + if (!ost->enc) { + av_log(dp, AV_LOG_ERROR, "Output stream %s has no encoder\n", arg); + return AVERROR(EINVAL); + } + + dp->dec.type = ost->type; + + ret = enc_loopback(ost->enc); + if (ret < 0) + return ret; + enc_idx = ret; + + ret = sch_connect(sch, SCH_ENC(enc_idx), SCH_DEC(dp->sch_idx)); + if (ret < 0) + return ret; + + ret = av_dict_copy(&dp->standalone_init.opts, o->g->codec_opts, 0); + if (ret < 0) + return ret; + + if (o->codec_names.nb_opt) { + const char *name = o->codec_names.opt[o->codec_names.nb_opt - 1].u.str; + dp->standalone_init.codec = avcodec_find_decoder_by_name(name); + if (!dp->standalone_init.codec) { + av_log(dp, AV_LOG_ERROR, "No such decoder: %s\n", name); + return AVERROR_DECODER_NOT_FOUND; + } + } + + return 0; +} + +int dec_filter_add(Decoder *d, InputFilter *ifilter, InputFilterOptions *opts) +{ + DecoderPriv *dp = dp_from_dec(d); + char name[16]; + + snprintf(name, sizeof(name), "dec%d", dp->index); + opts->name = av_strdup(name); + if (!opts->name) + return AVERROR(ENOMEM); + + return dp->sch_idx; +} diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index 88635629f7..d1dae558e1 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -49,6 +49,7 @@ struct Encoder { uint64_t packets_encoded; int opened; + int attach_par; Scheduler *sch; unsigned sch_idx; @@ -693,6 +694,18 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, return AVERROR(ENOMEM); fd->wallclock[LATENCY_PROBE_ENC_POST] = av_gettime_relative(); + // attach stream parameters to first packet if requested + avcodec_parameters_free(&fd->par_enc); + if (e->attach_par && !e->packets_encoded) { + fd->par_enc = avcodec_parameters_alloc(); + if (!fd->par_enc) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_from_context(fd->par_enc, enc); + if (ret < 0) + return ret; + } + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { ret = update_video_stats(ost, pkt, !!vstats_filename); if (ret < 0) @@ -929,3 +942,9 @@ finish: return ret; } + +int enc_loopback(Encoder *enc) +{ + enc->attach_par = 1; + return enc->sch_idx; +} diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index a29008387a..cf4f819927 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -710,6 +710,34 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) return 0; } +static int ifilter_bind_dec(InputFilterPriv *ifp, Decoder *dec) +{ + FilterGraphPriv *fgp = fgp_from_fg(ifp->ifilter.graph); + int ret, dec_idx; + + av_assert0(!ifp->bound); + ifp->bound = 1; + + if (ifp->type != dec->type) { + av_log(fgp, AV_LOG_ERROR, "Tried to connect %s decoder to %s filtergraph input\n", + av_get_media_type_string(dec->type), av_get_media_type_string(ifp->type)); + return AVERROR(EINVAL); + } + + ifp->type_src = ifp->type; + + dec_idx = dec_filter_add(dec, &ifp->ifilter, &ifp->opts); + if (dec_idx < 0) + return dec_idx; + + ret = sch_connect(fgp->sch, SCH_DEC(dec_idx), + SCH_FILTER_IN(fgp->sch_idx, ifp->index)); + if (ret < 0) + return ret; + + return 0; +} + static int set_channel_layout(OutputFilterPriv *f, OutputStream *ost) { const AVCodec *c = ost->enc_ctx->codec; @@ -1114,7 +1142,24 @@ static int fg_complex_bind_input(FilterGraph *fg, InputFilter *ifilter) enum AVMediaType type = ifp->type; int i, ret; - if (ifp->linklabel) { + if (ifp->linklabel && !strncmp(ifp->linklabel, "dec", 3)) { + // bind to a standalone decoder + int dec_idx; + + dec_idx = strtol(ifp->linklabel + 3, NULL, 0); + if (dec_idx < 0 || dec_idx >= nb_decoders) { + av_log(fg, AV_LOG_ERROR, "Invalid decoder index %d in filtergraph description %s\n", + dec_idx, fgp->graph_desc); + return AVERROR(EINVAL); + } + + ret = ifilter_bind_dec(ifp, decoders[dec_idx]); + if (ret < 0) + av_log(fg, AV_LOG_ERROR, "Error binding a decoder to filtergraph input %s\n", + ifilter->name); + return ret; + } else if (ifp->linklabel) { + // bind to an explicitly specified demuxer stream AVFormatContext *s; AVStream *st = NULL; char *p; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index b550382b4c..6cc549ddb4 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1177,11 +1177,13 @@ void show_usage(void) enum OptGroup { GROUP_OUTFILE, GROUP_INFILE, + GROUP_DECODER, }; static const OptionGroupDef groups[] = { [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT }, [GROUP_INFILE] = { "input url", "i", OPT_INPUT }, + [GROUP_DECODER] = { "loopback decoder", "dec", OPT_DECODER }, }; static int open_files(OptionGroupList *l, const char *inout, Scheduler *sch, @@ -1259,6 +1261,13 @@ int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch) goto fail; } + /* create loopback decoders */ + ret = open_files(&octx.groups[GROUP_DECODER], "decoder", sch, dec_create); + if (ret < 0) { + errmsg = "creating loopback decoders"; + goto fail; + } + // bind unbound filtegraph inputs/outputs and check consistency for (int i = 0; i < nb_filtergraphs; i++) { ret = fg_finalise_bindings(filtergraphs[i]); @@ -1367,11 +1376,11 @@ const OptionDef options[] = { { "recast_media", OPT_TYPE_BOOL, OPT_EXPERT, { &recast_media }, "allow recasting stream type in order to force a decoder of different media type" }, - { "c", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON, + { "c", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_DECODER | OPT_HAS_CANON, { .off = OFFSET(codec_names) }, "select encoder/decoder ('copy' to copy stream without reencoding)", "codec", .u1.name_canon = "codec", }, - { "codec", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_EXPERT | OPT_HAS_ALT, + { "codec", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_DECODER | OPT_EXPERT | OPT_HAS_ALT, { .off = OFFSET(codec_names) }, "alias for -c (select encoder/decoder)", "codec", .u1.names_alt = alt_codec, }, From patchwork Wed Mar 6 11:03:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46847 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp314113pzb; Wed, 6 Mar 2024 03:07:52 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWpcGU+IDUYzmKzsvLWrNPuhZL7odC03e9HkPVqT6vrDo9JydpwDA9qiI0yuk581ATsKXtfEtgDTCO5uYRBo+UbhhmSj448NuxVvg== X-Google-Smtp-Source: AGHT+IHRbAdpu2qpHj7IL3zwyk439BP35KePZ0+wmOiH7YdoctGTNRVZ3s25Yz4Ixk6sc+hotvR+ X-Received: by 2002:a17:906:1d08:b0:a44:4610:6aad with SMTP id n8-20020a1709061d0800b00a4446106aadmr9323159ejh.11.1709723272127; Wed, 06 Mar 2024 03:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709723272; cv=none; d=google.com; s=arc-20160816; b=kXCzfx2yjkev52WxoW7pIbieX5KoT5ew9NqEjPTnuQPQmAUXOTBpwA89zTAc9HJ63/ IThf73MEa/fOfbGiJfW8fGfbs+wfI4OzAWo+BvneAEidiKdI35KLkk/DklkuGNXSM5DT 6u2VcjhiEL5nShMOVmTJX/pQjY2nrATPWvwrouxRHsld/O490U4/kZIdW37uB94A42f/ 9ASYprcKKggx9SLFT7eZunZP0r6uBGd9SRHB/y2Qp+KPUCyUf0OiHWy+vEaMZb0lyMet R6tW8DKpTZ7t5AQ1IEcPkkGDDLO8D+PUqohs7FGOWptHs/tznCpLxukXF22XhOaNIykN NEbg== 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:dkim-signature:delivered-to; bh=WNdfxkDFRe5UdH61NGutdbk/Y7PcKe9juFDi0ZSHv28=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=T0SQAcdeMjHZY5d/rP52xiETGcVid7StnbaZiTYNe4zgBLLO1YV6rxeC3dwJCWw58h xz+QbrKdhkFYSv7F2pkHx6BR/AqgDIUMLFsDzahHovGHnJK05gFOpilWmcAszC3VeGl/ oRR4+iXiSDGOmKsC6afCmoI0f7HqoMBJ8V7yizjhV58/7pty4TavfMqNyTcdin6d1sax p5LYhMjj1NafZY7JaSHeIhAiwGcBlnHe6ZDxEKCPBWP0yDBVMXBke399yxs81kLDZxrb 4SMfNuBpsiWn61/I+Z0pggIiGBnBOZm/0seBRPcgGEV1O6GpUHp95BvOPCDjLKWH6Qki i6Pw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=BL8I28Wc; 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 a14-20020a1709065f8e00b00a412e3b6368si5994614eju.576.2024.03.06.03.07.51; Wed, 06 Mar 2024 03:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=BL8I28Wc; 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 EC34668CEE6; Wed, 6 Mar 2024 13:05:45 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E064468CCFC for ; Wed, 6 Mar 2024 13:05:30 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=BL8I28Wc; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 6FFF44D58 for ; Wed, 6 Mar 2024 12:05:29 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id 81UIlC_OXGDG for ; Wed, 6 Mar 2024 12:05:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1709723123; bh=CXcHGKUUj8/ll28PFehryMM3OtgdqSD8m5inkNCuiww=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BL8I28WcYogdg+C2Wyg1TeMyPX7nfLZP7a0dQlLo0Yf1LDl/yEoPjG3w2dqNKNpzc SmAphgEXmSNV4KbPyRpmR+S4P+MVts3uh5P1k0j4Vx0bxeTpepZFFDsGIvdTD1lemE 6kPsHQlwDRA6WNtkGNrFbw5NSzYYyE+m3P7psVsQmded8qRxuT6+3e+rmlkiPuhjh0 3Fb91LSH6AklQ5uKgJeXsOs3TZumSN3s8TgcqFJi/2V6LIW6F112acqT5LB5w3uWjn 3y+bpfX2+c3nt97d+esnOxnH2jjHjSMOW2Y0se12Upg+T9tvRedJgr0FQf4U+lPPQb JFpKEgiO6bSRw== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id 601024D66 for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 5355F3A0A6B for ; Wed, 6 Mar 2024 12:05:23 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 6 Mar 2024 12:03:19 +0100 Message-ID: <20240306110319.17339-18-anton@khirnov.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240306110319.17339-1-anton@khirnov.net> References: <20240306110319.17339-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/18] fftools/ffmpeg_enc: set AV_PKT_FLAG_TRUSTED on encoded packets 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: 2jYw/8M98fgS This allows using WRAPPED_AVFRAME encoders with loopback decoders in order to connect multiple filtergraphs together. Clear the flag in muxers, since lavf does not need it for anything and it would change the results of framecrc FATE tests. --- fftools/ffmpeg_enc.c | 2 ++ fftools/ffmpeg_mux.c | 1 + 2 files changed, 3 insertions(+) diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c index d1dae558e1..c9a12af139 100644 --- a/fftools/ffmpeg_enc.c +++ b/fftools/ffmpeg_enc.c @@ -706,6 +706,8 @@ static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, return ret; } + pkt->flags |= AV_PKT_FLAG_TRUSTED; + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { ret = update_video_stats(ost, pkt, !!vstats_filename); if (ret < 0) diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c index 59befefab2..e8e5c677b8 100644 --- a/fftools/ffmpeg_mux.c +++ b/fftools/ffmpeg_mux.c @@ -433,6 +433,7 @@ int muxer_thread(void *arg) ost = of->streams[mux->sch_stream_idx[stream_idx]]; mt.pkt->stream_index = ost->index; + mt.pkt->flags &= ~AV_PKT_FLAG_TRUSTED; ret = mux_packet_filter(mux, &mt, ost, ret < 0 ? NULL : mt.pkt, &stream_eof); av_packet_unref(mt.pkt);