def test_encode_video(raw_video_fixture, tmp_path):
    output_path = tmp_path / 'test_video.webm'

    fps = raw_video_fixture["fps"]
    expected_video = raw_video_fixture["raw_video"]

    transformations.encode_video(video=expected_video,
                                 output_path=output_path.as_posix(),
                                 fps=fps),

    compare_videos(output_path, expected_video)
def encoded_videos_fixture(request, tmp_path):
    num_videos = request.param.get('num_videos', 2)
    video_shape = request.param.get('video_shape', (32, 32))
    nframes = request.param.get('nframes', 30)
    fps = request.param.get('fps', 30)

    rng = np.random.default_rng(0)
    test_videos = defaultdict(list)

    for i in range(num_videos):
        data = np.array([rng.integers(0, 256, size=video_shape, dtype='uint8')
                         for _ in range(nframes)])

        test_video_path = tmp_path / f"test_video_{i}.webm"
        transformations.encode_video(video=data,
                                     output_path=test_video_path.as_posix(),
                                     fps=fps)

        test_videos['raw_data'].append(data)
        test_videos['encoded_videos'].append(test_video_path)

    return test_videos
Exemplo n.º 3
0
    def run(self):
        self.logger.name = type(self).__name__
        self.logger.setLevel(self.args['log_level'])

        # create and write the summary png
        motion_offset_df = pd.read_csv(self.args['motion_diagnostics_output'])
        png_out_path = make_png(Path(self.args['max_projection_output']),
                                Path(self.args['avg_projection_output']),
                                motion_offset_df,
                                Path(self.args['registration_summary_output']))
        self.logger.info(f"wrote {png_out_path}")

        # downsample and normalize the input movies
        ds_partial = partial(downsample_normalize,
                             frame_rate=self.args['movie_frame_rate_hz'],
                             bin_size=self.args['preview_frame_bin_seconds'],
                             lower_quantile=self.args['movie_lower_quantile'],
                             upper_quantile=self.args['movie_upper_quantile'])
        processed_vids = [
            ds_partial(i) for i in [
                Path(self.args['uncorrected_path']),
                Path(self.args['motion_corrected_output'])
            ]
        ]
        self.logger.info("finished downsampling motion corrected "
                         "and non-motion corrected movies")

        # tile into 1 movie, raw on left, motion corrected on right
        tiled_vids = np.block(processed_vids)

        # make into a viewable artifact
        playback_fps = (self.args['preview_playback_factor'] /
                        self.args['preview_frame_bin_seconds'])
        encode_video(tiled_vids, self.args['motion_correction_preview_output'],
                     playback_fps)
        self.logger.info("wrote "
                         f"{self.args['motion_correction_preview_output']}")

        return