Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to add blur filter with max matrix size #4259

Closed
1 task done
low-batt opened this issue Mar 11, 2023 · 2 comments · Fixed by #4261
Closed
1 task done

Unable to add blur filter with max matrix size #4259

low-batt opened this issue Mar 11, 2023 · 2 comments · Fixed by #4261

Comments

@low-batt
Copy link
Contributor

System and IINA version:

  • macOS 13.2.1
  • IINA 1.3.1

Expected behavior:
The matrix size slider for a blur filter only permits setting valid values.

Actual behavior:
Attempts to add a Blur filter with the Matrix size slider knob moved all the way to the right:
issue-add-blur

Fail reporting Error occured when setting filters. Please check our parameter format:
issue-blur-failed

IINA log:
18:52:25.623 [player0][d] Adding video filter lavfi=[unsharp=23:23:-0.0:23:23:-0.0]...
18:52:25.623 [iina][w] mpv log: [ffmpeg] error: Parsed_unsharp_0: luma or chroma matrix size too big
18:52:25.623 [iina][w] mpv log: [ffmpeg] error: AVFilterGraph: Error initializing filter 'unsharp' with args '23:23:-0.0:23:23:-0.0'
18:52:25.623 [iina][w] mpv log: [lavfi] fatal: parsing the filter graph failed
18:52:25.624 [player0][d] Failed
18:52:25.624 [iina][w] mpv log: [user_filter_wrapper] error: Creating filter 'lavfi' failed.

mpv log:
18:52:25.623 [iina][w] mpv log: [ffmpeg] error: Parsed_unsharp_0: luma or chroma matrix size too big
18:52:25.623 [iina][w] mpv log: [ffmpeg] error: AVFilterGraph: Error initializing filter 'unsharp' with args '23:23:-0.0:23:23:-0.0'
18:52:25.623 [iina][w] mpv log: [lavfi] fatal: parsing the filter graph failed
18:52:25.624 [player0][d] Failed
18:52:25.624 [iina][w] mpv log: [user_filter_wrapper] error: Creating filter 'lavfi' failed.

Steps to reproduce:

  • Play a video
  • Click Video filters… under the Video menu
  • In the Video Filters window click +
  • In the pop-up click Blur
  • Slide the Matrix size slider knob all the way to the right
  • Click the Add button
  • MPV does not have this problem.

This is an IINA problem.

How often does this happen?
Every time.

@low-batt
Copy link
Contributor Author

Analysis

The FFmpeg unsharp filter documentation indicates 23 is the maximum value permitted:

luma_msize_x, lx
Set the luma matrix horizontal size. It must be an odd integer between 3 and 23. The default value is 5.

luma_msize_y, ly
Set the luma matrix vertical size. It must be an odd integer between 3 and 23. The default value is 5.

IINA is enforcing the minimum and maximum values:

// blur
FilterPreset("blur", params: [
  "amount": PM.float(min: 0, max: 1.5),
  "msize": PM.int(min: 3, max: 23, step: 2, defaultValue: 5)
]) { instance in
   return MPVFilter.unsharp(amount: -instance.value(for: "amount").floatValue,
                           msize: instance.value(for: "msize").intValue)
},

The FFmpeg code generating the error looks like:

if (s->luma.scalebits >= 26 || s->chroma.scalebits >= 26 || s->alpha.scalebits >= 26) {
    av_log(ctx, AV_LOG_ERROR, "luma or chroma or alpha matrix size too big\n");
    return AVERROR(EINVAL);
}

The error message is slightly different because FFmpeg has added an alpha parameter to this filter.

The code calculating scalebits looks like:

fp->steps_x = msize_x / 2;
fp->steps_y = msize_y / 2;
fp->scalebits = (fp->steps_x + fp->steps_y) * 2;

The FFmpeg documentation does not mention that if both the horizontal and the vertical size are set to their maximum values this restriction on the combined size will be exceeded.

@low-batt low-batt added the bug label Mar 11, 2023
@low-batt low-batt self-assigned this Mar 11, 2023
low-batt added a commit that referenced this issue Mar 11, 2023
This commit will change the construction of the sharpen and blur
FilterPreset objects to impose a maximum value of 13 for the matrix
size in order to adhere to the undocumented FFmpeg limit on the sum of
the unsharp luma matrix horizontal and vertical matrix sizes.
@low-batt low-batt linked a pull request Mar 11, 2023 that will close this issue
2 tasks
uiryuu pushed a commit that referenced this issue Mar 30, 2023
This commit will change the construction of the sharpen and blur
FilterPreset objects to impose a maximum value of 13 for the matrix
size in order to adhere to the undocumented FFmpeg limit on the sum of
the unsharp luma matrix horizontal and vertical matrix sizes.
@uiryuu uiryuu reopened this Mar 30, 2023
@low-batt
Copy link
Contributor Author

IINA 1.3.2 contains the fix for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants