PR #21414 opened by hassanhany URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21414 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21414.patch
this is in relation to Trac ticket 9602 which was reopened 2 weeks ago where the issue was there were gray bars in apng rgb24 (and other non alpha based formats) this PR fixes it by disabling the background disposal operation for non alpha formats since it relies on transparency as defined by the spec "APNG_DISPOSE_OP_BACKGROUND: the frame's region of the output buffer is to be cleared to fully transparent black before rendering the next frame." Building FFmpeg with this patch produces the correct output, removing the gray bars, >From 253901b2b72889878d8bbe69c66c898fdfc011f4 Mon Sep 17 00:00:00 2001 From: "U-DESKTOP-70DF2U5\\GIGABYT" <[email protected]> Date: Thu, 8 Jan 2026 21:04:52 +0200 Subject: [PATCH] disabling background disposal for non alpha formats --- libavcodec/pngenc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c index e627bf83fc..808fac6a38 100644 --- a/libavcodec/pngenc.c +++ b/libavcodec/pngenc.c @@ -39,7 +39,7 @@ #include "libavutil/opt.h" #include "libavutil/rational.h" #include "libavutil/stereo3d.h" - +#include "libavutil/pixdesc.h" #include <zlib.h> #define IOBUF_SIZE 4096 @@ -885,7 +885,8 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict, size_t best_bytestream_size = SIZE_MAX; APNGFctlChunk last_fctl_chunk = *best_last_fctl_chunk; APNGFctlChunk fctl_chunk = *best_fctl_chunk; - + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pict->format); + if (avctx->frame_num == 0) { best_fctl_chunk->width = pict->width; best_fctl_chunk->height = pict->height; @@ -919,7 +920,11 @@ static int apng_encode_frame(AVCodecContext *avctx, const AVFrame *pict, // 0: APNG_DISPOSE_OP_NONE // 1: APNG_DISPOSE_OP_BACKGROUND // 2: APNG_DISPOSE_OP_PREVIOUS - + if(last_fctl_chunk.dispose_op==APNG_DISPOSE_OP_BACKGROUND) { + if(!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) { + continue; + } + } for (fctl_chunk.blend_op = 0; fctl_chunk.blend_op < 2; ++fctl_chunk.blend_op) { // 0: APNG_BLEND_OP_SOURCE // 1: APNG_BLEND_OP_OVER -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
