Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PR] disabling background disposal for non alpha formats (PR #21414)
@ 2026-01-08 20:41 hassanhany via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: hassanhany via ffmpeg-devel @ 2026-01-08 20:41 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: hassanhany

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" <hassanhanyrashad@gmail.com>
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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-01-08 20:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-08 20:41 [FFmpeg-devel] [PR] disabling background disposal for non alpha formats (PR #21414) hassanhany via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git