Unified · Split
| @@ -297,18 +297,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 296 unmodified lines | |||
| 297 | AVFilterLink *outlink = ctx->outputs[0]; | 297 | AVFilterLink *outlink = ctx->outputs[0]; |
| 298 | AVFrame *out; | 298 | AVFrame *out; |
| 299 | 299 | ||
| 300 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); | 300 | if (av_frame_is_writable(in)) { |
| 301 | if (!out) { | 301 | out = in; |
| 302 | av_frame_free(&in); | 302 | } else { |
| 303 | return AVERROR(ENOMEM); | 303 | out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
| 304 | if (!out) { | ||
| 305 | av_frame_free(&in); | ||
| 306 | return AVERROR(ENOMEM); | ||
| 307 | } | ||
| 308 | av_frame_copy_props(out, in); | ||
| 304 | } | 309 | } |
| 305 | av_frame_copy_props(out, in); | ||
| 306 | 310 | ||
| 307 | for (int plane = 0; plane < s->nb_planes; plane++) { | 311 | for (int plane = 0; plane < s->nb_planes; plane++) { |
| 308 | if (!(s->planes & (1 << plane))) { | 312 | if (!(s->planes & (1 << plane))) { |
| 309 | av_image_copy_plane(out->data[plane], out->linesize[plane], | 313 | if (out != in) |
| 310 | in->data[plane], in->linesize[plane], | 314 | av_image_copy_plane(out->data[plane], out->linesize[plane], |
| 311 | s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]); | 315 | in->data[plane], in->linesize[plane], |
| 316 | s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]); | ||
| 312 | continue; | 317 | continue; |
| 313 | } | 318 | } |
| 314 | 319 | ||
| @@ -322,7 +327,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 7 unmodified lines | |||
| 322 | in->linesize[plane] / 2, out->linesize[plane] / 2); | 327 | in->linesize[plane] / 2, out->linesize[plane] / 2); |
| 323 | } | 328 | } |
| 324 | 329 | ||
| 325 | av_frame_free(&in); | 330 | if (out != in) |
| 331 | av_frame_free(&in); | ||
| 326 | return ff_filter_frame(outlink, out); | 332 | return ff_filter_frame(outlink, out); |
| 327 | } | 333 | } |
| 328 | 334 | ||