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 6DCC742CDC for ; Tue, 3 May 2022 16:14:19 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1EC8E68B39A; Tue, 3 May 2022 19:13:59 +0300 (EEST) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4F2E168B394 for ; Tue, 3 May 2022 19:13:52 +0300 (EEST) Received: by mail-qt1-f177.google.com with SMTP id hh4so13875590qtb.10 for ; Tue, 03 May 2022 09:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6PFjBMPY0LcWDjHW8ANF6N3ro/90ICiz03wEyR5aF18=; b=A3aP/9lGl9jEp0Dvmjizmouz3xemj4XT7CHOAnNtPEvgirUn/Pos5Y2oAD40htw7c7 6ZaVygfS144VKxiCLcNsrWOrcpd01RzBEiEQsiSrEF/Hf3PbvtKGXXoH/3CxNkOBEDG2 9zx1W7u+gH+2FYgNsJmFxr0eBq6V5xxb1ceFc7B6fm9ouFRMbJZDpdSChJ+VxWIIILsV 4Fs/m6gOVHFkeGYS/F4PsjvNAv56MXBJaeWZVRieA5EuuA6IgFGymxVxhXvPLRpx8RVU d9+5hl68JYv/nWTHAxFffC8XzLwmZjQqqgdieskT+tLzb/EwJaDfc0/me0/QDS+J04mt MSgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6PFjBMPY0LcWDjHW8ANF6N3ro/90ICiz03wEyR5aF18=; b=njOUGgxAgGvodC65PJAIafkb+EeyAPkn4UAMCwikF571TccgQcAxsn9bgOhvQWGvGx aN/pKTvAZJKgclUvgMxC54oD91xb1kPMfH6efuriAohVxdyvX+TnlcMu5CbJpcIPAZWE oY9gjPU2U3P6zQ+ZZwLnSxdNv1ZH+cUMl/TOC+2LzHgzU2eKqZUT9odtjz0zaIXPQ1H4 1KT1Bbisi1OvsTLgJWlVlKfMPDkKG/KaNd23hctwVotqWfx7op5o66VOW2lz8C+1vuc5 uh0TOVLsyjWOqrUVdklqy5CKev9LahX1XvezPKOvY5sM1Y7SJExCDPc7fitgJ3KgPSOb Klnw== X-Gm-Message-State: AOAM533SJLrEEStus42Z9dWyX2HY3B/YtkDGVxmlAtUb8TeY9fTppYh/ bf9HNYL9UGsAcw/NGw51uHsqqeeCarmU X-Google-Smtp-Source: ABdhPJyK9jVS/zLwAW+G+7MvE2kPYh+RQz+2MXhs/Odq3dQ4fvIUJB/gHoy9Gq0a9sLFq+vciCWJYg== X-Received: by 2002:a05:622a:164b:b0:2f3:8701:2859 with SMTP id y11-20020a05622a164b00b002f387012859mr15306703qtj.33.1651594430993; Tue, 03 May 2022 09:13:50 -0700 (PDT) Received: from thinkpad.. ([66.220.203.136]) by smtp.gmail.com with ESMTPSA id fp35-20020a05622a50a300b002f39b99f67asm5812731qtb.20.2022.05.03.09.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 09:13:50 -0700 (PDT) From: Traian Coza To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 May 2022 12:13:19 -0400 Message-Id: <20220503161328.842587-4-traian.coza@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220503161328.842587-1-traian.coza@gmail.com> References: <20220503161328.842587-1-traian.coza@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/12] Retreive width and height from video stream! X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Traian Coza 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: --- fftools/ffmpeg.c | 29 ++++++++++++++++++++++++++--- libavfilter/vf_subtitles.c | 9 ++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index dea2aec2ce..a74800bb68 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2325,7 +2325,7 @@ fail: return err < 0 ? err : ret; } -void render_avsub_ass(InputStream *, AVSubtitle *); +void render_avsub_ass(InputStream *, AVSubtitle *, int, int); static void print_subtitle(AVSubtitle sub) { @@ -2423,7 +2423,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, ist->frames_decoded++; - int rendered = 0; + int rendered = 0; // Variable for text to bitmap support for (i = 0; i < nb_output_streams; i++) { OutputStream *ost = output_streams[i]; @@ -2431,10 +2431,33 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output, || ost->enc->type != AVMEDIA_TYPE_SUBTITLE) continue; + // Support text to bitmap if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & AV_CODEC_PROP_BITMAP_SUB) if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & AV_CODEC_PROP_TEXT_SUB) if (!rendered) { - render_avsub_ass(ist, &subtitle); + // Try to get a height and width from a video + int width = 0, height = 0; + // Try output streams + for (int j = 0; j < nb_output_streams; j++) + if (output_streams[j]->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) + { + width = output_streams[j]->enc_ctx->width; + height = output_streams[j]->enc_ctx->height; + break; + } + if (width == 0) + // Try input streams + for (int j = 0; j < nb_input_streams; j++) + if (input_streams[j]->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) + { + width = input_streams[j]->dec_ctx->width; + height = input_streams[j]->dec_ctx->height; + break; + } + if (width == 0) { + // TODO Error: Cannot render without a video stream + } + render_avsub_ass(ist, &subtitle, width, height); for (int r = 0; r < subtitle.num_rects; r++) subtitle.rects[r]->type = SUBTITLE_BITMAP; rendered = 1; diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index 16f9c3fff6..7226911f6c 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -223,16 +223,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) #define ALPHA_THRESHOLD 0b10000000 -void render_avsub_ass(InputStream *, AVSubtitle *); -void render_avsub_ass(InputStream *ist, AVSubtitle *sub) +void render_avsub_ass(InputStream *, AVSubtitle *, int, int); +void render_avsub_ass(InputStream *ist, AVSubtitle *sub, int frame_width, int frame_height) { ASS_Library *library = ass_library_init(); ass_set_extract_fonts(library, 1); ASS_Renderer *renderer = ass_renderer_init(library); - int w = 1920, h = 1080; - ass_set_frame_size(renderer, w, h); + ass_set_frame_size(renderer, frame_width, frame_height); ass_set_pixel_aspect(renderer, 1); - ass_set_storage_size(renderer, w, h); + ass_set_storage_size(renderer, frame_width, frame_height); ass_set_shaper(renderer, 0); ass_set_fonts(renderer, NULL, NULL, 1, NULL, 1); -- 2.34.1 _______________________________________________ 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".