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

Clément Bœsch ubitux at gmail.com
Mon May 20 13:06:40 CEST 2013


On Sat, May 18, 2013 at 07:23:18PM +0100, Adam Guthrie wrote:
> 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);

You should fix your mailer, it mangles the patch, we can't apply it.

> +            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);

I'm not sure it is a good idea to involve the alpha channel in the scene
scoring. Note that it might be a bit tricky to adjust this code to ignore
the alpha...

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130520/45cf93a6/attachment.asc>


More information about the ffmpeg-devel mailing list