[Libav-user] How to make output frame with 2 times width and height than those of input frame and How to access the data?

정세윤 jsy at etri.re.kr
Tue Aug 5 14:53:36 CEST 2014


Dear Experts,

I am developing a Super-resolution filter for ffmpeg.

I would like to access the output frame by pointer.

I tried to access the data of outframe, so I write simple code as below.
The below is the main parts of my code.


1.     config_output function

(“ I would like to know other things required to make outlink with frame Size of 2xWidth and 2xHeigth of input frame “ )
First, I added config_output function in myfiter.c
config_output(AVFilterLinek *outlink)
{
int config_output(AVFilterLink *outlink)
{
        AVFilterContext *ctx = outlink->src;
        AVFilterLink *inlink = outlink->src->inputs[0];
        SR1Context *s = (SR1Context *)outlink->src->priv;
        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get((AVPixelFormat)inlink->format);
        int64_t w, h;
        w = inlink->w;
        h = inlink->h;

        w = w << 1;
        h = h << 1;
        if (w < 0 || h < 0){
               av_log(ctx, AV_LOG_ERROR, "Size values less thank 0 are not acceptalbe. \n");
               return AVERROR(EINVAL);
        }

        outlink->w = w;
        outlink->h = h;
        outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
        return 0;
}



2.     filter_frame : Then, I access the data of outframe by pointer in fiter_frame as below
(Is this right method to access the data of outframe? If it is not right method, please let me know that. )

int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
SR1Context *s = (SR1Context *)inlink->dst->priv;
        AVFilterLink *outlink = inlink->dst->outputs[0];
        AVFrame *out;
        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get((AVPixelFormat)inlink->format);

        out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
        if (!out){
               av_frame_free(&frame);
               return AVERROR(ENOMEM);
        }
        av_frame_copy_props(out, frame);


int plane, x, y, xb = s->x, yb = s->y;
    unsigned char *row_in[4]; // Y,U,V,A
        unsigned char *row_out[4]; // Y.U,V,A
        int full_height = frame->height;
int full_width = frame->linesize[0];
        int twice_width = full_width << 1;

for (y = 0; y < frame->height; y++) {
                 row_in[0] = frame->data[0] + y * full_width;
               row_out[0] = out->data[0] + y *twice_width;

               memcpy(row_out, row_in, full_width);
               memcpy(row_out + full_width, row_in, full_width);
memcpy(row_out + twice_width*(full_height), row_in, full_width);
                 memcpy(row_out + twice_width*(full_height)+full_width, row_in, full_width);

    }

          return ff_filter_frame(outlink, out);
}


Best Regards,
Seyoon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140805/2212893b/attachment.html>


More information about the Libav-user mailing list