-
Notifications
You must be signed in to change notification settings - Fork 50
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
Movie storage #545
Merged
Merged
Movie storage #545
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4e246bc
A first version of the MovieStorage
david-zwicker a177321
Major improvements
david-zwicker 7b8e938
Minor improvement
david-zwicker 64d3288
Fixed a nasty bug involving the normalization
david-zwicker 3126b11
Install FFmpeg as a requirement
david-zwicker e12d6ad
Fixed color space problem
david-zwicker f5e4eff
Minor improvements
david-zwicker b3c58ff
Support videos with more bits per channel
david-zwicker 9f18ccb
Multiple smaller improvements
david-zwicker 7a9d209
Improved ffmpeg format definition
david-zwicker b4e942a
Minor improvements
david-zwicker d755511
Improved support for mkv container format
david-zwicker 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Functions for interacting with FFmpeg | ||
|
||
.. codeauthor:: David Zwicker <david.zwicker@ds.mpg.de> | ||
""" | ||
|
||
# import subprocess as sp | ||
from dataclasses import dataclass | ||
|
||
import numpy as np | ||
from numpy.typing import DTypeLike | ||
|
||
# def _run_ffmpeg(args: list[str]): | ||
# return sp.check_output(["ffmpeg"] + args) | ||
# | ||
# | ||
# def codecs() -> list[str]: | ||
# """list: all supported ffmpeg codecs""" | ||
# res = _run_ffmpeg(["-codecs"]) | ||
# | ||
# | ||
# def get_pixel_formats(encoder=None): | ||
# if encoder is None: | ||
# res = _run_ffmpeg(["-pix_fmts"]) | ||
# else: | ||
# res = _run_ffmpeg(["-h", f"encoder={encoder}"]) | ||
|
||
|
||
@dataclass | ||
class FFmpegFormat: | ||
"""defines a FFmpeg format used for storing field data in a video""" | ||
|
||
pix_fmt_file: str | ||
codec: str | ||
channels: int | ||
value_max: int | ||
dtype: DTypeLike | ||
|
||
@property | ||
def pix_fmt_data(self) -> str: | ||
return {1: "gray", 3: "rgb24", 4: "rgba"}[self.channels] | ||
|
||
def data_to_frame(self, normalized_data: np.ndarray) -> np.ndarray: | ||
return (normalized_data * self.value_max).astype(self.dtype) | ||
|
||
def data_from_frame(self, frame_data: np.ndarray): | ||
return frame_data.astype(float) / self.value_max | ||
|
||
|
||
formats = { | ||
"gray": FFmpegFormat( | ||
pix_fmt_file="gray", | ||
codec="libx264", | ||
channels=1, | ||
value_max=255, | ||
dtype=np.uint8, | ||
), | ||
"rgb24": FFmpegFormat( | ||
pix_fmt_file="rgb24", | ||
codec="libx264rgb", | ||
channels=3, | ||
value_max=255, | ||
dtype=np.uint8, | ||
), | ||
"bgr24": FFmpegFormat( | ||
pix_fmt_file="bgr24", | ||
codec="libx264rgb", | ||
channels=3, | ||
value_max=255, | ||
dtype=np.uint8, | ||
), | ||
"rgb32": FFmpegFormat( | ||
pix_fmt_file="rgb32", | ||
codec="libx264rgb", | ||
channels=4, | ||
value_max=255, | ||
dtype=np.uint8, | ||
), | ||
} |
This file contains 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
Oops, something went wrong.
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.
In this way it is much easier to understand what is going on.
Moreover, what happens if self.channels is not one of 1, 3, 4 ?
With your method: a
key-error
will be thrown but actually is avalue error
because the class work just if we haveself.channels
in [1, 3, 4].Perhaps, an idea could be to add a check in the post_init method to ensure that channels is one of the above one.
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.
Good point! I'll adjust it to throw a more useful error in the future.