[FFmpeg-soc] [soc]: r330 - in libavfilter: Makefile allfilters.h avfilter.c vf_slicify.c

koorogi subversion at mplayerhq.hu
Fri Jul 6 19:57:37 CEST 2007


Author: koorogi
Date: Fri Jul  6 19:57:36 2007
New Revision: 330

Log:
Add a filter to cut video frames into smaller slices.


Added:
   libavfilter/vf_slicify.c
      - copied, changed from r327, /libavfilter/vf_passthrough.c
Modified:
   libavfilter/Makefile
   libavfilter/allfilters.h
   libavfilter/avfilter.c

Modified: libavfilter/Makefile
==============================================================================
--- libavfilter/Makefile	(original)
+++ libavfilter/Makefile	Fri Jul  6 19:57:36 2007
@@ -7,6 +7,7 @@ OBJECTS = avfilter.o          \
 		  vo_sdl.o            \
 		  vf_crop.o           \
 		  vf_passthrough.o    \
+		  vf_slicify.o        \
 
 all: filter_test
 

Modified: libavfilter/allfilters.h
==============================================================================
--- libavfilter/allfilters.h	(original)
+++ libavfilter/allfilters.h	Fri Jul  6 19:57:36 2007
@@ -24,4 +24,5 @@
 extern AVFilter vsrc_dummy;
 extern AVFilter vf_crop;
 extern AVFilter vf_passthrough;
+extern AVFilter vf_slicify;
 extern AVFilter vo_sdl;

Modified: libavfilter/avfilter.c
==============================================================================
--- libavfilter/avfilter.c	(original)
+++ libavfilter/avfilter.c	Fri Jul  6 19:57:36 2007
@@ -238,6 +238,7 @@ void avfilter_init(void)
     avfilter_register(&vsrc_dummy);
     avfilter_register(&vf_crop);
     avfilter_register(&vf_passthrough);
+    avfilter_register(&vf_slicify);
     avfilter_register(&vo_sdl);
 }
 

Copied: libavfilter/vf_slicify.c (from r327, /libavfilter/vf_passthrough.c)
==============================================================================
--- /libavfilter/vf_passthrough.c	(original)
+++ libavfilter/vf_slicify.c	Fri Jul  6 19:57:36 2007
@@ -1,5 +1,5 @@
 /*
- * Video passthrough filter
+ * Video slicing filter
  * copyright (c) 2007 Bobby Bingham
  *
  * This file is part of FFmpeg.
@@ -24,24 +24,71 @@
 
 #include "avfilter.h"
 
+typedef struct {
+    int h;          ///< output slice height
+    int vshift;     ///< chroma subsampling shift
+} SliceContext;
+
+static int init(AVFilterContext *ctx, const char *args)
+{
+    SliceContext *slice = ctx->priv;
+
+    /* set slice height */
+    slice->h = 16;
+    if(args)
+        sscanf(args, "%d", &slice->h);
+
+    return 0;
+}
+
 static int *query_formats(AVFilterLink *link)
 {
     return avfilter_make_format_list(1, PIX_FMT_RGB24);
 }
 
+static int config_props(AVFilterLink *link)
+{
+    SliceContext *slice = link->dst->priv;
+    int tmp;
+
+    avcodec_get_chroma_sub_sample(link->format, &tmp, &slice->vshift);
+
+    /* ensure that slices play nice with chroma subsampling, and enforce
+     * a reasonable minimum size for the slices */
+    slice->h = FFMAX(8, slice->h & (-1 << slice->vshift));
+}
+
 static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
 {
-    avfilter_start_frame(link->dst->outputs[0], picref);
+    avfilter_default_start_frame(link, picref);
+    avfilter_start_frame(link->dst->outputs[0], avfilter_ref_pic(picref));
 }
 
 static void end_frame(AVFilterLink *link)
 {
+    avfilter_default_end_frame(link);
     avfilter_end_frame(link->dst->outputs[0]);
 }
 
 static void draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h)
 {
-    avfilter_draw_slice(link->dst->outputs[0], data, y, h);
+    SliceContext *slice = link->dst->priv;
+    uint8_t *src[4];
+    int y2, i;
+
+    memcpy(src, data, sizeof(src));
+
+    for(y2 = y; y2 + slice->h <= y + h; y2 += slice->h) {
+        avfilter_draw_slice(link->dst->outputs[0], src, y2, slice->h);
+        src[0] += link->cur_pic->linesize[0] * slice->h;
+        src[3] += link->cur_pic->linesize[3] * slice->h;
+        /* TODO: make sure this works once other filters support YUV too */
+        for(i = 1; i < 3; i ++)
+            src[i] += link->cur_pic->linesize[i] * (slice->h >> slice->vshift);
+    }
+
+    if(y2 < y + h)
+        avfilter_draw_slice(link->dst->outputs[0], src, y2, y + h - y2);
 }
 
 static void request_frame(AVFilterLink *link)
@@ -49,16 +96,19 @@ static void request_frame(AVFilterLink *
     avfilter_request_frame(link->src->inputs[0]);
 }
 
-AVFilter vf_passthrough =
+AVFilter vf_slicify =
 {
-    .name      = "passthrough",
+    .name      = "slicify",
     .author    = "Bobby Bingham",
 
+    .init      = init,
+
     .inputs    = (AVFilterPad[]) {{ .name            = "default",
                                     .type            = AV_PAD_VIDEO,
                                     .start_frame     = start_frame,
                                     .draw_slice      = draw_slice,
                                     .query_formats   = query_formats,
+                                    .config_props    = config_props,
                                     .end_frame       = end_frame, },
                                   { .name = NULL}},
     .outputs   = (AVFilterPad[]) {{ .name            = "default",



More information about the FFmpeg-soc mailing list