[FFmpeg-devel] [PATCH] ffplay: Use sws_scale to scale subtitles
Marton Balint
cus at passwd.hu
Wed Jul 29 02:22:02 CEST 2015
On Tue, 28 Jul 2015, Michael Niedermayer wrote:
> From: Michael Niedermayer <michael at niedermayer.cc>
>
> Fixes some files from Ticket679
>
> This also changes subtitles to 4:2:0 matching the output format and thus
> simplifying the blend code.
> This restricts placement to the chroma sample resolution though, speak up
> if you consider this a problem, say so, the code could be changed to use
> YUV444 for subtitles and scaling them down while blending, this would be
> slower though.
> The current code only uses a single swscale context and reinitializes it
> as needed, this could be changed as well if needed
>
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
> ffplay.c | 284 ++++++++++++++++----------------------------------------------
> 1 file changed, 71 insertions(+), 213 deletions(-)
>
[...]
> @@ -2348,14 +2176,41 @@ static int subtitle_thread(void *arg)
>
> for (i = 0; i < sp->sub.num_rects; i++)
> {
> - for (j = 0; j < sp->sub.rects[i]->nb_colors; j++)
> - {
> - RGBA_IN(r, g, b, a, (uint32_t*)sp->sub.rects[i]->pict.data[1] + j);
> - y = RGB_TO_Y_CCIR(r, g, b);
> - u = RGB_TO_U_CCIR(r, g, b, 0);
> - v = RGB_TO_V_CCIR(r, g, b, 0);
> - YUVA_OUT((uint32_t*)sp->sub.rects[i]->pict.data[1] + j, y, u, v, a);
> + int in_w = sp->sub.rects[i]->w;
> + int in_h = sp->sub.rects[i]->h;
> + int subw = is->subdec.avctx->width ? is->subdec.avctx->width : is->viddec_width;
> + int subh = is->subdec.avctx->height ? is->subdec.avctx->height : is->viddec_height;
> + int out_w = in_w * is->viddec_width / subw;
> + int out_h = in_h * is->viddec_height / subh;
You should check for zero viddec_width/height here. E.g.:
out_w = is->viddec_width ? in_w * is->viddec_width / subw : in_w;
out_h = is->viddec_height ? in_h * is->viddec_height / subh : in_h;
Otherwise LGTM.
Thanks,
Marton
More information about the ffmpeg-devel
mailing list