numpyimage 2.5.0__tar.gz → 2.6.0__tar.gz
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.
- {numpyimage-2.5.0 → numpyimage-2.6.0}/PKG-INFO +1 -1
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/core.py +55 -55
- {numpyimage-2.5.0 → numpyimage-2.6.0}/numpyimage.egg-info/PKG-INFO +1 -1
- {numpyimage-2.5.0 → numpyimage-2.6.0}/pyproject.toml +1 -1
- {numpyimage-2.5.0 → numpyimage-2.6.0}/LICENSE +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/README.md +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/__init__.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/align.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/graphics.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/nrrd_utils.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/operations.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/npimage/utils.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/numpyimage.egg-info/SOURCES.txt +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/numpyimage.egg-info/dependency_links.txt +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/numpyimage.egg-info/requires.txt +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/numpyimage.egg-info/top_level.txt +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/setup.cfg +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/tests/test_heic.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/tests/test_pbm.py +0 -0
- {numpyimage-2.5.0 → numpyimage-2.6.0}/tests/test_video.py +0 -0
|
@@ -409,8 +409,10 @@ def load_video(filename,
|
|
|
409
409
|
data = np.empty((num_frames, *first_img.shape), dtype=first_img.dtype)
|
|
410
410
|
# Then fill it up frame by frame
|
|
411
411
|
data[0] = first_img
|
|
412
|
-
for i, frame in tqdm(enumerate(frame_iter
|
|
412
|
+
for i, frame in tqdm(enumerate(frame_iter), total=num_frames,
|
|
413
413
|
desc='Loading video', disable=not progress_bar):
|
|
414
|
+
if i == 0:
|
|
415
|
+
continue
|
|
414
416
|
img = frame.to_ndarray(format='rgb24')
|
|
415
417
|
data[i] = img
|
|
416
418
|
if return_framerate:
|
|
@@ -459,8 +461,7 @@ codec_aliases = {
|
|
|
459
461
|
}
|
|
460
462
|
|
|
461
463
|
|
|
462
|
-
|
|
463
|
-
codec: Literal['libx264', 'libx265'] = 'libx264') -> 'VideoWriter':
|
|
464
|
+
class VideoWriter:
|
|
464
465
|
"""
|
|
465
466
|
Create a video writer object for saving frames to a video file.
|
|
466
467
|
|
|
@@ -478,59 +479,57 @@ def video_writer(filename, framerate=30, crf=23, compression_speed='medium',
|
|
|
478
479
|
codec : Literal['libx264', 'libx265'], default 'libx264'
|
|
479
480
|
The video codec to use for encoding. Can be any of a number of aliases for
|
|
480
481
|
these two codecs, including avc1/h264 vs hevc/hvc1/hev1/h265.
|
|
481
|
-
|
|
482
|
-
Returns
|
|
483
|
-
-------
|
|
484
|
-
VideoWriter
|
|
485
|
-
The video writer object supporting context manager protocol.
|
|
486
482
|
"""
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
483
|
+
def __init__(self, filename, framerate=30, crf=23, compression_speed='medium',
|
|
484
|
+
codec: Literal['libx264', 'libx265'] = 'libx264',
|
|
485
|
+
overwrite=False):
|
|
486
|
+
try:
|
|
487
|
+
import av
|
|
488
|
+
except ImportError:
|
|
489
|
+
raise ImportError('Missing optional dependency for video processing,'
|
|
490
|
+
' run `pip install av tqdm`')
|
|
491
|
+
self.av = av
|
|
492
|
+
filename = os.path.expanduser(str(filename))
|
|
493
|
+
if os.path.exists(filename) and not overwrite:
|
|
494
|
+
raise FileExistsError(f'File {filename} already exists. '
|
|
495
|
+
'Set overwrite=True to overwrite.')
|
|
496
|
+
self.filename = filename
|
|
497
|
+
self.framerate = framerate
|
|
498
|
+
self.crf = crf
|
|
499
|
+
self.compression_speed = compression_speed
|
|
500
|
+
self.codec = codec_aliases[codec.lower()]
|
|
501
|
+
self.container = av.open(filename, mode='w')
|
|
502
|
+
self.stream = self.container.add_stream(self.codec, rate=framerate)
|
|
503
|
+
self.stream.pix_fmt = 'yuv420p'
|
|
504
|
+
self.stream.options = {'crf': str(crf), 'preset': compression_speed}
|
|
505
|
+
self._closed = False
|
|
506
|
+
self.stream.width = 0
|
|
507
|
+
self.stream.height = 0
|
|
508
|
+
|
|
509
|
+
def write(self, frame):
|
|
510
|
+
if not isinstance(frame, self.av.VideoFrame):
|
|
511
|
+
if frame.ndim == 3 and frame.shape[-1] == 3:
|
|
512
|
+
frame = self.av.VideoFrame.from_ndarray(frame, format='rgb24')
|
|
513
|
+
elif frame.ndim == 2:
|
|
514
|
+
frame = self.av.VideoFrame.from_ndarray(frame, format='gray')
|
|
515
|
+
else:
|
|
516
|
+
raise ValueError(f'Frame must be (H, W) or (H, W, 3) but was {frame.shape}')
|
|
517
|
+
if self.stream.width == 0:
|
|
518
|
+
self.stream.width = frame.width
|
|
519
|
+
if self.stream.height == 0:
|
|
520
|
+
self.stream.height = frame.height
|
|
521
|
+
for packet in self.stream.encode(frame):
|
|
522
|
+
self.container.mux(packet)
|
|
525
523
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
for packet in self.stream.encode():
|
|
529
|
-
self.container.mux(packet)
|
|
530
|
-
self.container.close()
|
|
531
|
-
self._closed = True
|
|
524
|
+
def __enter__(self):
|
|
525
|
+
return self
|
|
532
526
|
|
|
533
|
-
|
|
527
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
528
|
+
# Flush stream
|
|
529
|
+
for packet in self.stream.encode():
|
|
530
|
+
self.container.mux(packet)
|
|
531
|
+
self.container.close()
|
|
532
|
+
self._closed = True
|
|
534
533
|
|
|
535
534
|
|
|
536
535
|
def save_video(data, filename, time_axis=0, color_axis=None, overwrite=False,
|
|
@@ -634,8 +633,9 @@ def save_video(data, filename, time_axis=0, color_axis=None, overwrite=False,
|
|
|
634
633
|
if pad != [[0, 0], [0, 0], [0, 0]]:
|
|
635
634
|
data = np.pad(data, pad, mode='edge')
|
|
636
635
|
|
|
637
|
-
with
|
|
638
|
-
|
|
636
|
+
with VideoWriter(filename, framerate=framerate, crf=crf,
|
|
637
|
+
compression_speed=compression_speed, codec=codec,
|
|
638
|
+
overwrite=overwrite) as writer:
|
|
639
639
|
for frame_i in tqdm(range(n_frames), total=n_frames,
|
|
640
640
|
desc='Saving video', disable=not progress_bar):
|
|
641
641
|
writer.write(data[frame_i])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|