Exemplo n.º 1
0
 def test_video_read_write_odd_dimensions(self):
     video = media.moving_circle((35, 97), num_images=4, dtype=np.uint8)
     fps = 60
     bps = 40_000_000
     with tempfile.TemporaryDirectory() as directory_name:
         path = pathlib.Path(directory_name) / 'test5.mp4'
         media.write_video(path, video, fps=fps, bps=bps)
         new_video = media.read_video(path)
     self.assertEqual(new_video.dtype, np.uint8)
     self._check_similar(video, new_video, max_rms=5.0)
Exemplo n.º 2
0
 def test_video_non_streaming_write_read_roundtrip(self, use_generator):
     shape = (240, 320)
     num_images = 10
     fps = 40
     qp = 20
     original_video = media.to_uint8(media.moving_circle(shape, num_images))
     video = (
         image
         for image in original_video) if use_generator else original_video
     with tempfile.TemporaryDirectory() as directory_name:
         filename = os.path.join(directory_name, 'test.mp4')
         media.write_video(filename, video, fps=fps, qp=qp)
         new_video = media.read_video(filename)
         self._check_similar(original_video, new_video, 3.0)
Exemplo n.º 3
0
    def test_video_streaming_read_write(self):
        shape = (400, 400)
        num_images = 4
        fps = 60
        bps = 40_000_000
        video = media.to_uint8(media.moving_circle(shape, num_images))
        with tempfile.TemporaryDirectory() as directory_name:
            filename1 = os.path.join(directory_name, 'test1.mp4')
            filename2 = os.path.join(directory_name, 'test2.mp4')
            media.write_video(filename1, video, fps=fps, bps=bps)

            with media.VideoReader(filename1) as reader:
                with media.VideoWriter(filename2,
                                       reader.shape,
                                       fps=reader.fps,
                                       bps=reader.bps,
                                       encoded_format='yuv420p') as writer:
                    for image in reader:
                        writer.add_image(image)

            new_video = media.read_video(filename2)
            self._check_similar(video, new_video, 3.0)
Exemplo n.º 4
0
 def test_video_read_write_10bit(self):
     shape = (256, 256)
     num_images = 4
     fps = 60
     bps = 40_000_000
     horizontal_gray_ramp = media.to_type(
         np.indices(shape)[1] / shape[1], np.uint16)
     video = np.broadcast_to(horizontal_gray_ramp, (num_images, *shape))
     with tempfile.TemporaryDirectory() as directory_name:
         filename = os.path.join(directory_name, 'test3.mp4')
         media.write_video(filename,
                           video,
                           fps=fps,
                           bps=bps,
                           encoded_format='yuv420p10le')
         new_video = media.read_video(filename,
                                      dtype=np.uint16,
                                      output_format='gray')
     self.assertEqual(new_video.dtype, np.uint16)
     value_1_of_10bit_encoded_in_16bits = 64
     self._check_similar(video,
                         new_video,
                         max_rms=value_1_of_10bit_encoded_in_16bits * 0.8)