Index: allfilters.c
===================================================================
--- allfilters.c	(revision 2168)
+++ allfilters.c	(working copy)
@@ -36,6 +36,7 @@
 
     REGISTER_FILTER(CROP,crop,vf);
     REGISTER_FILTER(DRAWBOX,drawbox,vf);
+    REGISTER_FILTER(EXPAND,expand,vf);
     REGISTER_FILTER(FIFO,fifo,vf);
     REGISTER_FILTER(FORMAT,format,vf);
     REGISTER_FILTER(FPS,fps,vf);
Index: vf_expand.c
===================================================================
--- vf_expand.c	(revision 0)
+++ vf_expand.c	(revision 0)
@@ -0,0 +1,432 @@
+/*
+ * video expand filter (alternative to pad syntax)
+ * copyright (c) 2008 Ryo Hirafuji <http://ledyba.ddo.jp>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+
+#include "avfilter.h"
+
+#define ARG_DELIM ":"
+
+typedef struct{
+    int  x,  y;
+    int ew, eh;
+
+    int osd; //checked, but not used in this version.
+    double aspect;
+    int round;
+
+    int bpp;                // bytes per pixel
+    int is_yuv;
+    int x_shift[4];
+    int y_shift[4];
+} Context;
+
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+    Context *expand = ctx->priv;
+
+    /* default parameters */
+    expand->x =  -1;
+    expand->y =  -1;
+    expand->ew = -1;
+    expand->eh = -1;
+    expand->osd = 0;
+    expand->aspect = 0.0f;
+    expand->round = 0;
+
+    expand->bpp = 0;
+    expand->is_yuv = 0;
+
+    expand->x_shift[0] = 0;
+    expand->x_shift[1] = 0;
+    expand->x_shift[2] = 0;
+    expand->x_shift[3] = 0;
+
+    expand->y_shift[0] = 0;
+    expand->y_shift[1] = 0;
+    expand->y_shift[2] = 0;
+    expand->y_shift[3] = 0;
+
+    if(args){
+        int length = strlen(args);
+        char* copy_arg = av_malloc(length+1);
+        char* item;
+
+        memcpy(copy_arg,args,length);
+        copy_arg[length] = '\0';
+
+        item = strtok(copy_arg, ARG_DELIM);/* 1 */
+        if(item && strlen(item) > 0){
+            expand->ew = atoi(item);
+        }
+        item = strtok(0, ARG_DELIM);/* 2 */
+        if(item && strlen(item) > 0){
+            expand->eh = atoi(item);
+        }
+        item = strtok(0, ARG_DELIM);/* 3 */
+        if(item && strlen(item) > 0){
+            expand->x = atoi(item);
+        }
+        item = strtok(0, ARG_DELIM);/* 4 */
+        if(item && strlen(item) > 0){
+            expand->y = atoi(item);
+        }
+        item = strtok(0, ARG_DELIM);/* 5 */
+        if(item && strlen(item) > 0){ //checked, but not used in this version.
+            if(!strncmp(item,"true",4)){
+                expand->osd = 1;
+            }else{
+                expand->osd = atoi(item);
+            }
+        }
+        item = strtok(0, ARG_DELIM);/* 6 */
+        if(item && strlen(item) > 0){
+            char* cp = strchr(item, '/');
+            if(cp){ // rational
+                AVRational rat;
+                char* cpp;
+                rat.num = strtol(item, &cpp, 10);
+                if(cpp != item || cpp == cp){
+                    rat.den = strtol(cp+1, &cpp, 10);
+                }else{
+                    rat.num = 0;
+                }
+                if(rat.num && rat.den){
+                    double eval = ((double)rat.num) / rat.den;
+                    if(eval > 0.0f){
+                        expand->aspect = eval;
+                    }
+                }
+            }else{ // double
+                double eval = strtod(item, 0);
+                if(eval > 0.0f){
+                    expand->aspect = eval;
+                }
+            }
+        }
+
+        item = strtok(0, ARG_DELIM );/* 7 */
+        if(item && strlen(item) > 0){
+            expand->round = atoi(item);
+        }
+
+        av_log(ctx, AV_LOG_INFO, "Expand: %dx%d , (%d,%d) , osd: %d, aspect: %lf, round: %d\n",
+        expand->ew, expand->eh, expand->x, expand->y, expand->osd, expand->aspect, expand->round);
+
+        av_free(copy_arg);
+    }
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx){
+    avfilter_set_common_formats(ctx,avfilter_make_format_list(32, // out of 38
+         PIX_FMT_YUV420P,
+         PIX_FMT_YUV422P,
+         PIX_FMT_YUV444P,
+         PIX_FMT_YUV410P,
+         PIX_FMT_YUV411P,
+         PIX_FMT_YUV440P,
+         PIX_FMT_YUVJ420P,
+         PIX_FMT_YUVJ422P,
+         PIX_FMT_YUVJ444P,
+         PIX_FMT_YUVJ440P,
++         PIX_FMT_YUVA420P,
++         PIX_FMT_NV12,
+         PIX_FMT_NV21,
++         PIX_FMT_RGB24,
+         PIX_FMT_BGR24,
++         PIX_FMT_RGB32,
+         PIX_FMT_BGR32,
+         PIX_FMT_RGB32_1,
+         PIX_FMT_BGR32_1,
++         PIX_FMT_GRAY16BE,
+         PIX_FMT_GRAY16LE,
+         PIX_FMT_BGR555,
+         PIX_FMT_BGR565,
+         PIX_FMT_RGB555,
+         PIX_FMT_RGB565,
+         PIX_FMT_YUYV422,
+         PIX_FMT_UYVY422,
++         //PIX_FMT_UYYVYY411, // not supported.
+         PIX_FMT_RGB8,
+         PIX_FMT_BGR8,
+         PIX_FMT_RGB4_BYTE,
+         PIX_FMT_BGR4_BYTE,
+         PIX_FMT_GRAY8
++         //PIX_FMT_RGB4, //not supported
+         //PIX_FMT_BGR4, //not supported
+         //PIX_FMT_MONOWHITE, // not supported
+         //PIX_FMT_MONOBLACK, // not supported
+         //PIX_FMT_PAL8, // not supported
+    ));
+    return 0;
+}
+
+
+static int config_input(AVFilterLink *link)
+{
+    Context *expand = link->dst->priv;
+    int width = link->w, height = link->h;
+    int hsub,vsub;
+
+    if (expand->ew == -1){
+        expand->ew=width;
+    } else if (expand->ew < -1){
+        expand->ew=width - expand->ew;
+    } else if (expand->ew < width){
+        expand->ew=width;
+    }
+
+    if (expand->eh == -1){
+        expand->eh=height;
+    } else if (expand->eh < -1){
+        expand->eh=height - expand->eh;
+    } else if (expand->eh < height){
+        expand->eh=height;
+    }
+
+    if (expand->aspect > 0.0f) {
+        if (expand->eh < (expand->ew / expand->aspect)) {
+            expand->eh = (expand->ew / expand->aspect) + 0.5;
+        } else {
+            expand->ew = (expand->eh * expand->aspect) + 0.5;
+        }
+    }
+    if (expand->round > 1) {
+        expand->ew = (1+(expand->ew-1)/expand->round)*expand->round;
+        expand->eh = (1+(expand->eh-1)/expand->round)*expand->round;
+    }
+    if(expand->x < 0 || (expand->x+width) > expand->ew){
+        expand->x = (expand->ew - width)>>1;
+    }
+    if(expand->y < 0 || (expand->y+height) > expand->eh){
+        expand->y = (expand->eh - height)>>1;
+    }
+
+    avcodec_get_chroma_sub_sample(link->format, &hsub, &vsub);
+    expand->ew &= ~((1 << hsub) - 1);
+    expand->eh &= ~((1 << vsub) - 1);
+    switch(link->format) {
+        case PIX_FMT_YUV420P:
+        case PIX_FMT_YUV422P:
+        case PIX_FMT_YUV444P:
+        case PIX_FMT_YUV410P:
+        case PIX_FMT_YUV411P:
+        case PIX_FMT_YUV440P:
+        case PIX_FMT_YUVJ420P:
+        case PIX_FMT_YUVJ422P:
+        case PIX_FMT_YUVJ444P:
+        case PIX_FMT_YUVJ440P:
+            expand->is_yuv = 1;
+            expand->bpp = 1;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            expand->x_shift[1] = expand->x_shift[2] = hsub;
+            expand->y_shift[1] = expand->y_shift[2] = vsub;
+            break;
+        case PIX_FMT_YUVA420P:
+            expand->is_yuv = 1;
+            expand->bpp = 1;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            expand->x_shift[1] = expand->x_shift[2] = hsub;
+            expand->y_shift[1] = expand->y_shift[2] = vsub;
+            expand->x_shift[3] = 0;
+            expand->y_shift[3] = 0;
+            break;
+        case PIX_FMT_NV12:
+        case PIX_FMT_NV21:
+            expand->is_yuv = 1;
+            expand->bpp = 1;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            expand->x_shift[1] = hsub;
+            expand->y_shift[1] = vsub;
+            break;
+        case PIX_FMT_RGB24:
+        case PIX_FMT_BGR24:
+            expand->bpp = 3;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            break;
+        case PIX_FMT_RGB32:
+        case PIX_FMT_BGR32:
+        case PIX_FMT_RGB32_1:
+        case PIX_FMT_BGR32_1:
+            expand->bpp = 4;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            break;
+        case PIX_FMT_YUYV422:
+        case PIX_FMT_UYVY422:
+            expand->is_yuv = 1;
+        case PIX_FMT_GRAY16BE:
+        case PIX_FMT_GRAY16LE:
+        case PIX_FMT_BGR555:
+        case PIX_FMT_BGR565:
+        case PIX_FMT_RGB555:
+        case PIX_FMT_RGB565:
+            expand->bpp = 2;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            break;
+        //case PIX_FMT_UYYVYY411: // not supported.
+        case PIX_FMT_RGB8:
+        case PIX_FMT_BGR8:
+        case PIX_FMT_RGB4_BYTE:
+        case PIX_FMT_BGR4_BYTE:
+        case PIX_FMT_GRAY8:
+            expand->bpp = 1;
+            expand->x_shift[0] = 0;
+            expand->y_shift[0] = 0;
+            break;
+        //case PIX_FMT_RGB4: //not supported
+        //case PIX_FMT_BGR4: //not supported
+        //depth: 4
+
+        //case PIX_FMT_MONOWHITE: // not supported
+        //case PIX_FMT_MONOBLACK: // not supported
+        //depth: 1
+
+        //case PIX_FMT_PAL8: // not supported
+        default:
+            return -1;
+    }
+
+    return 0;
+}
+
+static int config_output(AVFilterLink *link)
+{
+    Context *expand = link->src->priv;
+
+    link->w = expand->ew;
+    link->h = expand->eh;
+
+    return 0;
+}
+
+static void start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+{
+    AVFilterLink *out = link->dst->outputs[0];
+    out->outpic      = avfilter_get_video_buffer(out, AV_PERM_WRITE);
+    out->outpic->pts = picref->pts;
+    avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0));
+}
+
+static void draw_slice(AVFilterLink *link, int y, int h)
+{
+    Context *expand = link->dst->priv;
+    AVFilterPicRef *outpic = link->dst->outputs[0]->outpic;
+    AVFilterPicRef *inpic = link->cur_pic;
+    int i;
+    int is_first = (y == 0);
+    int is_end = (y+h == inpic->h);
+
+    for(i=0;i<4;i++) {
+        if(outpic->data[i]) {
+            int j;
+                  char* out_buff = outpic->data[i];
+            const char* in_buff  = inpic->data[i];
+            int copy_length = (inpic->w >> expand->x_shift[i]) * expand->bpp;
+            int y_add = 1<<expand->y_shift[i];
+            int color;
+            if(!expand->is_yuv || i == 3){
+                color = 0;
+            }else{
+                color = (i == 0) ? 16 : 128;
+            }
+
+            if(is_first){
+                for(j=0;j<expand->y;j+=y_add){
+                    memset(out_buff,color,outpic->linesize[i]);
+                    out_buff += outpic->linesize[i];
+                }
+            }else{
+                int y_skip = (expand->y >> expand->y_shift[i]);
+                out_buff += outpic->linesize[i] * y_skip;
+                in_buff += inpic->linesize[i] * y_skip;
+            }
+
+            for(j=0;j<h;j+=y_add){
+                int size,total_size = 0;
+                size = (expand->x >> expand->x_shift[i]) * expand->bpp;
+                memset(out_buff,color,size);
+                out_buff += size;
+                total_size += size;
+
+                memcpy(out_buff,in_buff,copy_length);
+                out_buff += copy_length;
+                total_size += copy_length;
+
+                size = outpic->linesize[i]-total_size;
+                memset(out_buff,color,size);
+                out_buff += size;
+
+                in_buff += inpic->linesize[i];
+            }
+
+            if(is_end){
+                for(j=0;j<outpic->h-expand->y-inpic->h;j+=y_add){
+                    memset(out_buff,color,outpic->linesize[i]);
+                    out_buff += outpic->linesize[i];
+                }
+            }
+
+        }
+    }
+    if(is_first && is_end){
+        avfilter_draw_slice(link->dst->outputs[0], 0, outpic->h);
+    }else if(is_first){
+        avfilter_draw_slice(link->dst->outputs[0], 0, expand->y + h);
+    }else if(is_end){
+        avfilter_draw_slice(link->dst->outputs[0], expand->y + y, outpic->h - expand->y - y);
+    }else{
+        avfilter_draw_slice(link->dst->outputs[0], expand->y+y, h);
+    }
+}
+
+AVFilter avfilter_vf_expand = {
+    .name      = "expand",
+    .priv_size = sizeof(Context),
+
+    .init      = init,
+    .query_formats   = query_formats,
+
+    .inputs    = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = CODEC_TYPE_VIDEO,
+                                    .start_frame     = start_frame,
+                                    .draw_slice      = draw_slice,
+                                    .config_props    = config_input, },
+                                  { .name = NULL}},
+    .outputs   = (AVFilterPad[]) {{ .name            = "default",
+                                    .type            = CODEC_TYPE_VIDEO,
+                                    .config_props    = config_output, },
+                                  { .name = NULL}},
+};
+
Index: Makefile
===================================================================
--- Makefile	(revision 2168)
+++ Makefile	(working copy)
@@ -15,6 +15,7 @@
 
 OBJS-$(CONFIG_CROP_FILTER)       += vf_crop.o
 OBJS-$(CONFIG_DRAWBOX_FILTER)    += vf_drawbox.o
+OBJS-$(CONFIG_EXPAND_FILTER)     += vf_expand.o
 OBJS-$(CONFIG_FPS_FILTER)        += vf_fps.o
 OBJS-$(CONFIG_HFLIP_FILTER)      += vf_hflip.o
 OBJS-$(CONFIG_NEGATE_FILTER)     += vf_negate.o
