This was accidentally comparing s->colorspace against out->colorspace, which is wrong - the intent was to compare in->colorspace against out->colorspace. We also forgot to strip mastering metadata. Finally, the order is sort of wrong - we should strip this side data *before* process_frames, because otherwise it may end up being seen and used by libplacebo.
Unified · Split
| @@ -390,7 +390,7 @@ fail: · 389 unmodified lines | ||
| 390 | 390 | |
| 391 | 391 | static int filter_frame(AVFilterLink *link, AVFrame *in) |
| 392 | 392 | { |
| 393 | − int err, changed; | |
| 393 | + int err, changed_csp; | |
| 394 | 394 | AVFilterContext *ctx = link->dst; |
| 395 | 395 | LibplaceboContext *s = ctx->priv; |
| 396 | 396 | AVFilterLink *outlink = ctx->outputs[0]; |
| @@ -426,22 +426,25 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 29 unmodified lines | ||
| 426 | 426 | if (s->color_primaries >= 0) |
| 427 | 427 | out->color_primaries = s->color_primaries; |
| 428 | 428 | |
| 429 | − RET(process_frames(ctx, out, in)); | |
| 430 | − | |
| 431 | − int changed_csp = s->colorspace != out->colorspace || | |
| 432 | − s->color_range != out->color_range || | |
| 433 | − s->color_trc != out->color_trc || | |
| 434 | − s->color_primaries != out->color_primaries; | |
| 429 | + changed_csp = in->colorspace != out->colorspace || | |
| 430 | + in->color_range != out->color_range || | |
| 431 | + in->color_trc != out->color_trc || | |
| 432 | + in->color_primaries != out->color_primaries; | |
| 435 | 433 | |
| 434 | + /* Strip side data if no longer relevant */ | |
| 435 | + if (changed_csp) { | |
| 436 | + av_frame_remove_side_data(out, AV_FRAME_DATA_MASTERING_DISPLAY_METADATA); | |
| 437 | + av_frame_remove_side_data(out, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL); | |
| 438 | + } | |
| 436 | 439 | if (s->apply_dovi || changed_csp) { |
| 437 | − /* Strip side data if no longer relevant */ | |
| 438 | 440 | av_frame_remove_side_data(out, AV_FRAME_DATA_DOVI_RPU_BUFFER); |
| 439 | 441 | av_frame_remove_side_data(out, AV_FRAME_DATA_DOVI_METADATA); |
| 440 | 442 | } |
| 441 | − | |
| 442 | 443 | if (s->apply_filmgrain) |
| 443 | 444 | av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS); |
| 444 | 445 | |
| 446 | + RET(process_frames(ctx, out, in)); | |
| 447 | + | |
| 445 | 448 | av_frame_free(&in); |
| 446 | 449 | |
| 447 | 450 | return ff_filter_frame(outlink, out); |