Repository navigation
fix(utils): stabilize segmented video reversal #668
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
Open
rusetiq
wants to merge
8
commits into
jeertmans:main
Choose a base branch
from
rusetiq:fix/segmented-video-reversal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
badda87
fix(utils): stabilize segmented video reversal
rusetiq 4df47fa
docs: add segmented reversal fix to changelog
rusetiq 19b4ae0
test(utils): use numpy assertion for frame order
rusetiq e15f61c
fix(ci): update ty suppression codes
rusetiq 9a3ecfa
fix(ci): exempt intentional Windows file opener
rusetiq 2030a56
chore: remove Codacy-specific accommodations
rusetiq fb018bb
test(utils): reproduce reversal deadlock and merge current main
rusetiq 4eeaef0
chore(fmt): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| from collections.abc import Iterator | ||
| from pathlib import Path | ||
|
|
||
| from manim_slides.utils import merge_basenames | ||
| import av | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from manim_slides.utils import merge_basenames, reverse_video_file | ||
|
|
||
|
|
||
| def test_merge_basenames(paths: list[Path]) -> None: | ||
|
|
@@ -20,3 +25,49 @@ def test_merge_basenames_same_with_different_parent_directories( | |
| p4 = d2 / "d/e/f/two.txt" | ||
|
|
||
| assert merge_basenames([p1, p2]).name == merge_basenames([p3, p4]).name | ||
|
|
||
|
|
||
| def test_reverse_video_file_with_unordered_segments( | ||
| tmp_path: Path, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| src = tmp_path / "src.mp4" | ||
| dest = tmp_path / "dest.mp4" | ||
|
|
||
| with av.open(str(src), mode="w") as container: | ||
| stream = container.add_stream("libx264", rate=2) | ||
| stream.width = 16 | ||
| stream.height = 16 | ||
| stream.pix_fmt = "yuv420p" | ||
| stream.codec_context.gop_size = 1 | ||
|
|
||
| for value in range(6): | ||
| array = np.full((16, 16, 3), value * 40, dtype=np.uint8) | ||
| frame = av.VideoFrame.from_ndarray(array, format="rgb24") | ||
| for packet in stream.encode(frame): | ||
| container.mux(packet) | ||
|
|
||
| for packet in stream.encode(): | ||
| container.mux(packet) | ||
|
|
||
| original_iterdir = Path.iterdir | ||
|
|
||
| def reversed_iterdir(path: Path) -> Iterator[Path]: | ||
| return iter(reversed(list(original_iterdir(path)))) | ||
|
|
||
| monkeypatch.setattr(Path, "iterdir", reversed_iterdir) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the context manager and only call the function that should be affected inside the scope :-) |
||
|
|
||
| reverse_video_file( | ||
| src, | ||
| dest, | ||
| max_segment_duration=1.0, | ||
| num_processes=1, | ||
| disable=True, | ||
| ) | ||
|
|
||
| with av.open(str(dest)) as container: | ||
| values = [ | ||
| float(frame.to_ndarray(format="gray").mean()) | ||
| for frame in container.decode(video=0) | ||
| ] | ||
|
|
||
| np.testing.assert_array_equal(values, sorted(values, reverse=True)) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What tool did you use to report a security issue? Because this error should not be raised by the linters used for this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i used codacy’s public pr api for that as an external pr check before pushing, ill revert the unrelated stuff