From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 4F9D748669 for ; Wed, 14 Feb 2024 18:25:00 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75B2268D21D; Wed, 14 Feb 2024 20:24:49 +0200 (EET) Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ED86468D205 for ; Wed, 14 Feb 2024 20:24:41 +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=NuDB0iGX; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 8BD7072E for ; Wed, 14 Feb 2024 19:24:41 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id ay2YnU5hKblX for ; Wed, 14 Feb 2024 19:24:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1707935078; bh=aIbdbBxmdOVQRseBs0Inyeu4X08NwLOMoYIn8P2nG0c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NuDB0iGXYRRD1IolQe8OLXwnK59jO4AqhMHbuMvxD+9N0NgrphSEivfK/p3iBdChd j2hO7O+Sfewf5c5+igX4Xc9byVuP3ydA1jYhpLYbAlwlVMey+Kj2Uc0Kf2Y7vNlUql cCrQK0oM7QLXWHrARVD7uK5MfIglpf3xlvwxSXk5SRJECtky6iHw3EM1y2EVjXkDZN ROrrhiadZDotYqRkAGUZcgpM5xmhTZ4TRHJXTLWD1WHrDJScWMzfM2FeIuy1/tnl+S 2dY+Abo5u3wTzWER9AmeQPk9M2wAAMdCn1Msyu+kd+uh0kF+CDwi88k/TY5YLzNcLy 55Jn7Tn05a49g== 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 8C2DA4492 for ; Wed, 14 Feb 2024 19:24:38 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 748C23A21D2 for ; Wed, 14 Feb 2024 19:24:38 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 14 Feb 2024 19:24:29 +0100 Message-ID: <20240214182435.31380-4-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240214182435.31380-1-anton@khirnov.net> References: <20240214182435.31380-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/10] fftools/ffmpeg_filter: pass sub2video canvas size through InputFilterOptions 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Rather than read them directly from InputStream. This is a step towards avoiding the assumption that filtergraph inputs are always fed by demuxers. --- fftools/ffmpeg.h | 7 +++---- fftools/ffmpeg_demux.c | 41 ++++++++++++++++++++--------------------- fftools/ffmpeg_filter.c | 21 ++++++++++----------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 2c1ad714b6..6db7b8a9c4 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -255,6 +255,9 @@ typedef struct InputFilterOptions { int64_t trim_end_us; uint8_t *name; + + int sub2video_width; + int sub2video_height; } InputFilterOptions; typedef struct InputFilter { @@ -366,10 +369,6 @@ typedef struct InputStream { int fix_sub_duration; - struct sub2video { - int w, h; - } sub2video; - /* decoded data from this stream goes into all those filters * currently video and audio only */ InputFilter **filters; diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index 4cbad80e17..87ed8225c2 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -992,6 +992,26 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple, return ret; if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) { + /* Compute the size of the canvas for the subtitles stream. + If the subtitles codecpar has set a size, use it. Otherwise use the + maximum dimensions of the video streams in the same file. */ + opts->sub2video_width = ist->par->width; + opts->sub2video_height = ist->par->height; + if (!(opts->sub2video_width && opts->sub2video_height)) { + for (int j = 0; j < d->f.nb_streams; j++) { + AVCodecParameters *par1 = d->f.streams[j]->par; + if (par1->codec_type == AVMEDIA_TYPE_VIDEO) { + opts->sub2video_width = FFMAX(opts->sub2video_width, par1->width); + opts->sub2video_height = FFMAX(opts->sub2video_height, par1->height); + } + } + } + + if (!(opts->sub2video_width && opts->sub2video_height)) { + opts->sub2video_width = FFMAX(opts->sub2video_width, 720); + opts->sub2video_height = FFMAX(opts->sub2video_height, 576); + } + if (!d->pkt_heartbeat) { d->pkt_heartbeat = av_packet_alloc(); if (!d->pkt_heartbeat) @@ -1357,27 +1377,6 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st) return ret; } } - - /* Compute the size of the canvas for the subtitles stream. - If the subtitles codecpar has set a size, use it. Otherwise use the - maximum dimensions of the video streams in the same file. */ - ist->sub2video.w = par->width; - ist->sub2video.h = par->height; - if (!(ist->sub2video.w && ist->sub2video.h)) { - for (int j = 0; j < ic->nb_streams; j++) { - AVCodecParameters *par1 = ic->streams[j]->codecpar; - if (par1->codec_type == AVMEDIA_TYPE_VIDEO) { - ist->sub2video.w = FFMAX(ist->sub2video.w, par1->width); - ist->sub2video.h = FFMAX(ist->sub2video.h, par1->height); - } - } - } - - if (!(ist->sub2video.w && ist->sub2video.h)) { - ist->sub2video.w = FFMAX(ist->sub2video.w, 720); - ist->sub2video.h = FFMAX(ist->sub2video.h, 576); - } - break; } case AVMEDIA_TYPE_ATTACHMENT: diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c index 0f57035104..d182f3ab2e 100644 --- a/fftools/ffmpeg_filter.c +++ b/fftools/ffmpeg_filter.c @@ -689,6 +689,16 @@ static int ifilter_bind_ist(InputFilter *ifilter, InputStream *ist) ifp->sub2video.frame = av_frame_alloc(); if (!ifp->sub2video.frame) return AVERROR(ENOMEM); + + ifp->width = ifp->opts.sub2video_width; + ifp->height = ifp->opts.sub2video_height; + + /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the + palettes for all rectangles are identical or compatible */ + ifp->format = AV_PIX_FMT_RGB32; + + av_log(fgp, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n", + ifp->width, ifp->height); } return 0; @@ -1829,17 +1839,6 @@ int ifilter_parameters_from_dec(InputFilter *ifilter, const AVCodecContext *dec) ret = av_channel_layout_copy(&ifp->fallback.ch_layout, &dec->ch_layout); if (ret < 0) return ret; - } else { - // for subtitles (i.e. sub2video) we set the actual parameters, - // rather than just fallback - ifp->width = ifp->ist->sub2video.w; - ifp->height = ifp->ist->sub2video.h; - - /* rectangles are AV_PIX_FMT_PAL8, but we have no guarantee that the - palettes for all rectangles are identical or compatible */ - ifp->format = AV_PIX_FMT_RGB32; - - av_log(NULL, AV_LOG_VERBOSE, "sub2video: using %dx%d canvas\n", ifp->width, ifp->height); } return 0; -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".