--- 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-requ...@ffmpeg.org with subject "unsubscribe".