Search code examples
ffmpegpng

ffmpeg: preserve transparency when scaling png


I'm trying to invoke the following command:

ffmpeg -y -i 1.png -vf "thumbnail=300,scale='min(300,iw)':-1" -frames:v 1 o.png

Input file:

enter image description here

Output file:

enter image description here

Is it possible to fix it?


Solution

  • Remove the thumbnail filter. It does not preserve transparency and it does nothing in your command as it is intended to be used with a video input and not a single image input:

    thumbnail
    Select the most representative frame in a given sequence of consecutive frames.

    ffmpeg -y -i 1.png -vf "scale='min(300,iw)':-1" -frames:v 1 o.png
    

    You can view the source code of libavfilter/vf_thumbnail.c to see supported pixel formats:

    static const enum AVPixelFormat pix_fmts[] = {
        AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
        AV_PIX_FMT_NONE
    };
    

    None of these support transparency (it would contain A in the pixel format name that does support transparency/alpha).