[FFmpeg-devel] [PATCH] lavfi/select: support for pixel formats with alpha

Adam Guthrie asguthrie at gmail.com
Sat May 18 20:23:18 CEST 2013


Signed-off-by: Adam Guthrie <asguthrie at gmail.com>
---
 libavfilter/f_select.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index 07a64f3..fc61fdf 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -23,11 +23,13 @@
  * filter for selecting which frame passes in the filterchain
  */

+#include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/eval.h"
 #include "libavutil/fifo.h"
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
 #include "avfilter.h"
 #include "audio.h"
 #include "formats.h"
@@ -150,6 +152,7 @@ typedef struct {
     double prev_mafd;               ///< previous MAFD
        (scene detect only)
 #endif
     AVFrame *prev_picref; ///< previous frame
 (scene detect only)
+    int nb_components;              ///< number of video components per
pixel      (scene detect only)
     double select;
     int select_out;                 ///< mark the selected output pad index
     int nb_outputs;
@@ -246,6 +249,13 @@ static int config_input(AVFilterLink *inlink)
         if (!select->avctx)
             return AVERROR(ENOMEM);
         avpriv_dsputil_init(&select->c, select->avctx);
+
+        if (inlink->type == AVMEDIA_TYPE_VIDEO) {
+            const AVPixFmtDescriptor *pix_fmt =
av_pix_fmt_desc_get(inlink->format);
+            av_assert0(pix_fmt);
+
+            select->nb_components = pix_fmt->nb_components;
+        }
     }
 #endif
     return 0;
@@ -257,6 +267,7 @@ static double get_scene_score(AVFilterContext *ctx,
AVFrame *frame)
     double ret = 0;
     SelectContext *select = ctx->priv;
     AVFrame *prev_picref = select->prev_picref;
+    uint8_t nb_components = select->nb_components;

     if (prev_picref &&
         frame->height    == prev_picref->height &&
@@ -270,7 +281,7 @@ static double get_scene_score(AVFilterContext *ctx,
AVFrame *frame)
         const int linesize = frame->linesize[0];

         for (y = 0; y < frame->height - 8; y += 8) {
-            for (x = 0; x < frame->width*3 - 8; x += 8) {
+            for (x = 0; x < frame->width*nb_components - 8; x += 8) {
                 sad += select->c.sad[1](select, p1 + x, p2 + x,
                                         linesize, 8);
                 nb_sad += 8 * 8;
@@ -438,6 +449,8 @@ static int query_formats(AVFilterContext *ctx)
     } else {
         static const enum AVPixelFormat pix_fmts[] = {
             AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
+            AV_PIX_FMT_RGBA, AV_PIX_FMT_ARGB,
+            AV_PIX_FMT_BGRA, AV_PIX_FMT_ABGR,
             AV_PIX_FMT_NONE
         };
         ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
-- 
1.8.2.2


More information about the ffmpeg-devel mailing list