enot-vp 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
enot_vp/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from enot_vp.video_processor import VideoProcessor as VideoProcessor
@@ -0,0 +1,75 @@
1
+ import av
2
+ import numpy as np
3
+
4
+
5
+ class VideoProcessor:
6
+ def __init__(self, input_video: str, output_video: str | None = None):
7
+ self.input_video = input_video
8
+ self.output_video = output_video
9
+ self.input_container = None
10
+ self.output_container = None
11
+ self.input_stream = None
12
+ self.output_stream = None
13
+ self._frame_iterator = None
14
+
15
+ def __enter__(self):
16
+ # Open input video
17
+ self.input_container = av.open(self.input_video)
18
+ self.input_stream = self.input_container.streams.video[0]
19
+
20
+ # Set up output if specified
21
+ if self.output_video:
22
+ self.output_container = av.open(self.output_video, mode="w")
23
+ self.output_stream = self.output_container.add_stream(
24
+ codec_name="hevc",
25
+ rate=self.input_stream.average_rate,
26
+ width=self.input_stream.width,
27
+ height=self.input_stream.height,
28
+ )
29
+ self.output_stream.pix_fmt = "yuv420p"
30
+
31
+ # Create frame iterator with progress bar
32
+ self._frame_iterator = self.input_container.decode(self.input_stream)
33
+
34
+ return self
35
+
36
+ def __exit__(self, exc_type, exc_val, exc_tb):
37
+ del exc_tb
38
+
39
+ if self.output_container:
40
+ # Flush any remaining frames in the encoder
41
+ for packet in self.output_stream.encode():
42
+ self.output_container.mux(packet)
43
+ self.output_container.close()
44
+
45
+ self.input_container.close()
46
+
47
+ if exc_type is not None:
48
+ print(f"Error occurred: {exc_val}")
49
+
50
+ return True
51
+
52
+ def __iter__(self):
53
+ return self
54
+
55
+ def __next__(self):
56
+ if self._frame_iterator is None:
57
+ raise RuntimeError("VideoProcessor not initialized. Use in a 'with' block.")
58
+
59
+ try:
60
+ return next(self._frame_iterator)
61
+ except StopIteration:
62
+ self._frame_iterator.close()
63
+ raise
64
+
65
+ def put(self, processed_frame: av.VideoFrame | np.ndarray):
66
+ """Add video frame to output video."""
67
+ if self.output_container is None:
68
+ raise RuntimeError("No output video specified in constructor")
69
+
70
+ # Convert frame to AV VideoFrame and encode
71
+ if not isinstance(processed_frame, av.VideoFrame):
72
+ processed_frame = av.VideoFrame.from_ndarray(processed_frame)
73
+
74
+ for packet in self.output_stream.encode(processed_frame):
75
+ self.output_container.mux(packet)
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: enot-vp
3
+ Version: 0.1.0
4
+ Summary: ENOT video processor package for iterating over video frames easily.
5
+ Author-email: Malofeev Ivan <ruhrozz@bk.ru>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.9
11
+ Requires-Dist: av>=14.4.0
12
+ Requires-Dist: numpy>=2.0.2
@@ -0,0 +1,6 @@
1
+ enot_vp/__init__.py,sha256=0jTdY7p0CdAbF2pqIZZpC_3nFvnUgQolDAl_cWfqoc0,69
2
+ enot_vp/video_processor.py,sha256=FsHiBCFQoWpT942I9_L0pVZIzM9j45crceSmLrPeaWA,2494
3
+ enot_vp-0.1.0.dist-info/METADATA,sha256=ZlAuvBXEvvLgDIqj3Z71QgKZupXV3G6JUVUgiyyzx3s,391
4
+ enot_vp-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ enot_vp-0.1.0.dist-info/licenses/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
6
+ enot_vp-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.