Fix GIF encoding with lavfi current filters - #231
Merged
Merged
Conversation
mpv reports libavfilter bridge filters such as "--vf=lavfi-crop" with positional parameters named @0, @1, ... Serializing them as "lavfi-crop:@0=value" is only understood by mpv's own option parser: the GIF format rewrites the command line into a raw libavfilter graph, where the placeholder names are invalid and graph parsing fails. Rebuild bridge filters in libavfilter argument syntax ("lavfi-crop=w:h:x:y", "lavfi-eq=key=value") and drop mpv's raw string quoting there, since property expansion does not run inside the bracketed graph the GIF format builds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #230.
Problem
Applying a libavfilter bridge filter to playback (e.g.
--vf=lavfi-crop=1920:800:0:140) and encoding a GIF withapply_current_filters = truefails:apply_current_filtersre-serializes the nativevflist asname:key=value. mpv reports bridge filters aslavfi-<name>with positional arguments exposed under placeholder keys:{ name = "lavfi-crop", params = { ["@0"]="320", ["@1"]="100", ["@2"]="0", ["@3"]="40" } }so it produced
lavfi-crop:@0=320:@1=100.... That happens to be accepted by mpv's own option parser (which is why non-GIF formats survived), but the GIF format rewrites every--vf-add=lavfi-*entry into one raw libavfilter graph, where@0=is not valid ffmpeg syntax, so the graph fails to parse.Fix
Rebuild bridge filters in libavfilter argument syntax before handing them off:
lavfi-crop->lavfi-crop=320:100:0:40(positional@Nsorted)lavfi-eq->lavfi-eq=contrast=1.5:saturation=1.5(named keys sorted)lavfi=[graph]->lavfi=[graph]Values are emitted unquoted because property expansion (and therefore mpv's
%N%raw string syntax) does not run inside the bracketed graph the GIF format builds.Tests
Added regression coverage in
tests/testcases/test_video_filters.py:lavfi-cropcurrent filter: encodes and the crop is actually applied (288x90)lavfi=[crop=...]graph current filter: samelavfi-eq(named args): encodeslavfi-crop: still applies the crop (320x100), guarding the mpv-option pathVerified the GIF tests fail on the pre-fix build and pass after; full suite: 42 tests, OK (2 pre-existing skips).