Showing the changes to libavfilter/vsrc_buffer.c (1 of 3 files). Show all
Unified · Split
| @@ -37,10 +37,13 @@ typedef struct { · 36 unmodified lines | ||
| 37 | 37 | AVRational pixel_aspect; |
| 38 | 38 | } BufferSourceContext; |
| 39 | 39 | |
| 40 | −int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, | |
| 41 | − int64_t pts, AVRational pixel_aspect) | |
| 40 | +int av_vsrc_buffer_add_frame2(AVFilterContext *buffer_filter, AVFrame *frame, | |
| 41 | + int64_t pts, AVRational pixel_aspect, int width, | |
| 42 | + int height, enum PixelFormat pix_fmt, | |
| 43 | + const char *sws_param) | |
| 42 | 44 | { |
| 43 | 45 | BufferSourceContext *c = buffer_filter->priv; |
| 46 | + int ret; | |
| 44 | 47 | |
| 45 | 48 | if (c->has_frame) { |
| 46 | 49 | av_log(buffer_filter, AV_LOG_ERROR, |
| @@ -50,6 +53,42 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, · 3 unmodified lines | ||
| 50 | 53 | //return -1; |
| 51 | 54 | } |
| 52 | 55 | |
| 56 | + if(width != c->w || height != c->h || pix_fmt != c->pix_fmt){ | |
| 57 | + AVFilterContext *scale= buffer_filter->outputs[0]->dst; | |
| 58 | + AVFilterLink *link; | |
| 59 | + | |
| 60 | + av_log(buffer_filter, AV_LOG_INFO, "Changing filter graph input to accept %dx%d %d (%d %d)\n", | |
| 61 | + width,height,pix_fmt, c->pix_fmt, scale->outputs[0]->format); | |
| 62 | + | |
| 63 | + if(!scale || strcmp(scale->filter->name,"scale")){ | |
| 64 | + AVFilter *f= avfilter_get_by_name("scale"); | |
| 65 | + | |
| 66 | + av_log(buffer_filter, AV_LOG_INFO, "Inserting scaler filter\n"); | |
| 67 | + if(avfilter_open(&scale, f, "Input equalizer") < 0) | |
| 68 | + return -1; | |
| 69 | + | |
| 70 | + if((ret=avfilter_init_filter(scale, sws_param, NULL))<0){ | |
| 71 | + avfilter_free(scale); | |
| 72 | + return ret; | |
| 73 | + } | |
| 74 | + | |
| 75 | + if((ret=avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0))<0){ | |
| 76 | + avfilter_free(scale); | |
| 77 | + return ret; | |
| 78 | + } | |
| 79 | + | |
| 80 | + scale->outputs[0]->format= c->pix_fmt; | |
| 81 | + } | |
| 82 | + | |
| 83 | + c->pix_fmt= scale->inputs[0]->format= pix_fmt; | |
| 84 | + c->w= scale->inputs[0]->w= width; | |
| 85 | + c->h= scale->inputs[0]->h= height; | |
| 86 | + | |
| 87 | + link= scale->outputs[0]; | |
| 88 | + if ((ret = link->srcpad->config_props(link)) < 0) | |
| 89 | + return ret; | |
| 90 | + } | |
| 91 | + | |
| 53 | 92 | memcpy(c->frame.data , frame->data , sizeof(frame->data)); |
| 54 | 93 | memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); |
| 55 | 94 | c->frame.interlaced_frame= frame->interlaced_frame; |
| @@ -61,6 +100,16 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, · 5 unmodified lines | ||
| 61 | 100 | return 0; |
| 62 | 101 | } |
| 63 | 102 | |
| 103 | +int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, | |
| 104 | + int64_t pts, AVRational pixel_aspect) | |
| 105 | +{ | |
| 106 | + BufferSourceContext *c = buffer_filter->priv; | |
| 107 | + | |
| 108 | + return av_vsrc_buffer_add_frame2(buffer_filter, frame, | |
| 109 | + pts, pixel_aspect, c->w, | |
| 110 | + c->h, c->pix_fmt, ""); | |
| 111 | +} | |
| 112 | + | |
| 64 | 113 | static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
| 65 | 114 | { |
| 66 | 115 | BufferSourceContext *c = ctx->priv; |