numpyimage 2.7.0__tar.gz → 2.9.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: numpyimage
3
- Version: 2.7.0
3
+ Version: 2.9.0
4
4
  Summary: Load, save, & manipulate image files as numpy arrays
5
5
  Author-email: Jasper Phelps <jasper.s.phelps@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -439,8 +439,16 @@ class VideoWriter:
439
439
  self.stream.height = 0
440
440
 
441
441
  def write(self, frame):
442
+ if self._closed:
443
+ raise RuntimeError('VideoWriter is closed, cannot write more frames.')
442
444
  if not isinstance(frame, self.av.VideoFrame):
443
- if frame.ndim == 3 and frame.shape[-1] == 3:
445
+ if not isinstance(frame, np.ndarray):
446
+ frame = np.array(frame)
447
+ if frame.ndim == 4:
448
+ for i in range(frame.shape[0]):
449
+ self.write(frame[i])
450
+ return
451
+ elif frame.ndim == 3 and frame.shape[-1] == 3:
444
452
  frame = self.av.VideoFrame.from_ndarray(frame, format='rgb24')
445
453
  elif frame.ndim == 3 and frame.shape[-1] == 4:
446
454
  # While some video codecs support an alpha channel, most don't,
@@ -449,7 +457,8 @@ class VideoWriter:
449
457
  elif frame.ndim == 2:
450
458
  frame = self.av.VideoFrame.from_ndarray(frame, format='gray')
451
459
  else:
452
- raise ValueError(f'Frame must be (H, W) (H, W, 3) or (H, W, 4) but was {frame.shape}')
460
+ raise ValueError('Frame must have shape (H, W) (H, W, 3) (H, W, 4)'
461
+ f' (t, H, W, 3) or (t, H, W, 4) but was {frame.shape}')
453
462
  if self.stream.width == 0:
454
463
  self.stream.width = frame.width
455
464
  if self.stream.height == 0:
@@ -461,6 +470,9 @@ class VideoWriter:
461
470
  return self
462
471
 
463
472
  def __exit__(self, exc_type, exc_val, exc_tb):
473
+ self.close()
474
+
475
+ def close(self):
464
476
  # Flush stream
465
477
  for packet in self.stream.encode():
466
478
  self.container.mux(packet)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: numpyimage
3
- Version: 2.7.0
3
+ Version: 2.9.0
4
4
  Summary: Load, save, & manipulate image files as numpy arrays
5
5
  Author-email: Jasper Phelps <jasper.s.phelps@gmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'
4
4
 
5
5
  [project]
6
6
  name = 'numpyimage'
7
- version = '2.7.0'
7
+ version = '2.9.0'
8
8
  description = 'Load, save, & manipulate image files as numpy arrays'
9
9
  readme.file = 'README.md'
10
10
  readme.content-type = 'text/markdown'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes