[FFmpeg-devel] [PATCH] avfilter/vf_subtitles: pass storage size to libass

Soft Works softworkz at hotmail.com
Mon Mar 14 21:35:36 EET 2022



> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Oneric
> Sent: Monday, March 14, 2022 8:07 PM
> To: ffmpeg-devel at ffmpeg.org
> Cc: Oneric <oneric at oneric.de>
> Subject: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: pass storage size
> to libass
> 
> Due to a quirk of the ASS format some tags depend on the exact storage
> resolution of the video, so tell libass via ass_set_storage_size.
> 
> ---
> ass_set_storage_size exists since libass 0.10.2;
> ffmpeg since 5.0 already requires 0.11.0.
> 
> This resolution dependences of ASS was already recognised when the
> original_size parameter was added, but it actually goes farther than
> just the aspect ratio. Conveniently this parameter still has all the
> required information to retain rendering after resizing :)
> 
> Sample files to show the difference can be found eg here
> https://code.videolan.org/videolan/vlc/uploads/b54e0761d0d3f4f79b2947ffb83
> a3b59/vlc-issue_libass-storage-size.tar.xz
> 
> ./ffmpeg -i test_1080p.mkv -filter:v ass=./test_1080p.ass tmp_1080.mkv
> ./ffmpeg -i anamorphic_s720x576_d1024x576.mkv -filter:v
> ass=./anamorphic_s720x576_d1024x576.ass tmp_anam.mkv
> 
> ---
>  libavfilter/vf_subtitles.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
> index 3fc4eeb63d..af6352b315 100644
> --- a/libavfilter/vf_subtitles.c
> +++ b/libavfilter/vf_subtitles.c
> @@ -146,9 +146,14 @@ static int config_input(AVFilterLink *inlink)
>      ff_draw_init(&ass->draw, inlink->format, ass->alpha ?
> FF_DRAW_PROCESS_ALPHA : 0);
> 
>      ass_set_frame_size  (ass->renderer, inlink->w, inlink->h);
> -    if (ass->original_w && ass->original_h)
> +    if (ass->original_w && ass->original_h) {
>          ass_set_pixel_aspect(ass->renderer, (double)inlink->w / inlink->h
> /
>                               ((double)ass->original_w / ass-
> >original_h));
> +        ass_set_storage_size(ass->renderer, ass->original_w, ass-
> >original_h);
> +    } else {
> +        ass_set_storage_size(ass->renderer, inlink->w, inlink->h);
> +    }
> +
>      if (ass->shaping != -1)
>          ass_set_shaper(ass->renderer, ass->shaping);
> 

Hi,

thanks for the patch!

I've been at the same point some time ago where I wondered why ffmpeg is
not setting this, but then I had found that it is overridden by the call 
to ass_set_pixel_aspect().

ass_set_pixel_aspect() is setting settings.par and if I'm not mistaken,
an existing par setting leads to the storage size setting to be ignored:

https://github.com/libass/libass/blob/5f0e8450f834894b2745238e3d32ff4878710ec8/libass/ass_render.c#L2891-L2903

But perhaps I'm missing something..

softworkz



More information about the ffmpeg-devel mailing list