cutcutcodec.core.filter.video.custom¶
Apply any user defined filter to video frames.
Classes
|
Apply any user defined filter to video frames. |
Details
- class cutcutcodec.core.filter.video.custom.FilterVideoCustom(in_streams: Iterable[Stream], func: Callable[[Tensor, Fraction], Tensor])[source]
Apply any user defined filter to video frames.
Examples¶
>>> from fractions import Fraction >>> import torch >>> from cutcutcodec.core.filter.video.custom import FilterVideoCustom >>> from cutcutcodec.core.generation.video.noise import GeneratorVideoNoise >>> >>> def func(frame: torch.Tensor, timestamp: Fraction) -> torch.Tensor: ... """Create a black border during the first 10 seconds.""" ... if timestamp <= 10: ... frame[:2, :] = frame[-2:, :] = frame[:, :2] = frame[:, -2:] = 0 ... return frame ... >>> (s_base_video,) = GeneratorVideoNoise(0).out_streams >>> (s_custom_video,) = FilterVideoCustom([s_base_video], func).out_streams >>> >>> s_custom_video.snapshot(0, (9, 9))[:, :, 0] tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], [0.0000, 0.0000, 0.3209, 0.7038, 0.6147, 0.6749, 0.5931, 0.0000, 0.0000], [0.0000, 0.0000, 0.6637, 0.7421, 0.7787, 0.8397, 0.5273, 0.0000, 0.0000], [0.0000, 0.0000, 0.0467, 0.0464, 0.3364, 0.7802, 0.2447, 0.0000, 0.0000], [0.0000, 0.0000, 0.4455, 0.7455, 0.3952, 0.1906, 0.1819, 0.0000, 0.0000], [0.0000, 0.0000, 0.9956, 0.1559, 0.8482, 0.7545, 0.7674, 0.0000, 0.0000], [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000]]) >>>
Initialise and create the class.
Parameters¶
- in_streamstyping.Iterable[Stream]
Transmitted to
cutcutcodec.core.classes.filter.Filter.- funccallable
A user-defined function that takes in input the video frame, and the frame time as a rational number and returns the new frame.