From: Traian Coza <traian.coza@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Traian Coza <traian.coza@gmail.com> Subject: [FFmpeg-devel] [PATCH 03/12] Retreive width and height from video stream! Date: Tue, 3 May 2022 12:13:19 -0400 Message-ID: <20220503161328.842587-4-traian.coza@gmail.com> (raw) In-Reply-To: <20220503161328.842587-1-traian.coza@gmail.com> --- 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".
next prev parent reply other threads:[~2022-05-03 16:14 UTC|newest] Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-03 16:13 [FFmpeg-devel] [PATCH 00/12] I added text to bitmap subtitle conversion functionality! Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 01/12] Implemented text to bitmap subtitles! Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 02/12] Render only when necessary Traian Coza 2022-05-03 16:13 ` Traian Coza [this message] 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 04/12] Initialize ass library only once! Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 05/12] Cleaned up Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 06/12] Wrote proper headers Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 07/12] Close libass after using Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 08/12] Added standard headers Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 09/12] Rearranged files, all tests are passing! Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 10/12] " Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 11/12] Added logging Traian Coza 2022-05-03 16:13 ` [FFmpeg-devel] [PATCH 12/12] Added more logging Traian Coza 2022-05-03 16:20 ` [FFmpeg-devel] [PATCH 00/12] I added text to bitmap subtitle conversion functionality! Paul B Mahol 2022-05-03 16:51 ` Nicolas George 2022-05-03 17:01 ` Traian Coza 2022-05-03 17:05 ` Leo Izen 2022-05-03 17:09 ` Traian Coza 2022-05-03 16:27 ` Soft Works 2022-05-04 0:16 ` Soft Works
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220503161328.842587-4-traian.coza@gmail.com \ --to=traian.coza@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git