[FFmpeg-devel] [PATCH] bug in avcodec_find_best_pix_fmt_of_list

Александр Чирятьев heimdallr at ngs.ru
Sat Mar 31 16:09:38 EEST 2018


Hello!

Let me propose to review my patch for avcodec_find_best_pix_fmt_of_list.
It's very old bug. Here is example:

AVPixelFormat pixFmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA };
int loss = 0;
AVPixelFormat best_fmt = avcodec_find_best_pix_fmt_of_list(pixFmts, 
AV_PIX_FMT_BGRA, 1, &loss);

Now best_fmt is AV_PIX_FMT_RGB24. But AV_PIX_FMT_RGBA is better.


Regards,
Alexander Chiryatev.

-------------- next part --------------
From 4e9caf7d208a6de065ba0ee9f164ccf577fb7e89 Mon Sep 17 00:00:00 2001
From: heimdallr <heimdallr at ngs.ru>
Date: Sat, 31 Mar 2018 19:37:23 +0700
Subject: [PATCH] bug in avcodec_find_best_pix_fmt_of_list

example:

AVPixelFormat pixFmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_RGBA };
int loss = 0;
AVPixelFormat best = avcodec_find_best_pix_fmt_of_list(pixFmts, AV_PIX_FMT_BGRA, 1, &loss);

best is AV_PIX_FMT_RGB24. But AV_PIX_FMT_RGBA is better.
---
 libavcodec/imgconvert.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 1547f18966..7b0005b308 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -69,10 +69,14 @@ enum AVPixelFormat avcodec_find_best_pix_fmt_of_list(const enum AVPixelFormat *p
     int i;
 
     enum AVPixelFormat best = AV_PIX_FMT_NONE;
+    int loss;
 
-    for(i=0; pix_fmt_list[i] != AV_PIX_FMT_NONE; i++)
-        best = avcodec_find_best_pix_fmt_of_2(best, pix_fmt_list[i], src_pix_fmt, has_alpha, loss_ptr);
+    for (i=0; pix_fmt_list[i] != AV_PIX_FMT_NONE; i++) {
+        loss = *loss_ptr;
+        best = avcodec_find_best_pix_fmt_of_2(best, pix_fmt_list[i], src_pix_fmt, has_alpha, &loss);
+    }
 
+    *loss_ptr = loss;
     return best;
 }
 
-- 
2.14.1.windows.1



More information about the ffmpeg-devel mailing list