def thread_function(thread_id, thread_segments): print_function = thread_print_function(thread_id) for i, segment in enumerate(thread_segments): print_function('{}: ({} / {})'.format(segment.ytid, i + 1, len(thread_segments))) print_function('{}: Extracting frames'.format(segment.ytid), wait=True) ops.extract_frames(segment.raw, segment.frames_dir, segment.start_seconds) print_function('{}: Extracting frames (finished)'.format( segment.ytid)) print_function('{}: Computing spectrograms'.format(segment.ytid), wait=True) waveform, sr = segment.waveform for j in range(segment.start_frames, min(segment.end_frames, len(segment))): if workers == 1: print_function('{}: Computing spectrograms ({})'.format( segment.ytid, j), wait=True) if not os.path.exists(segment.spectrogram(j)): start_samples = segment.get_sample_index(j) samples_slice = slice(start_samples, start_samples + segment.sample_rate) ops.compute_spectrogram(waveform[samples_slice], segment.spectrogram(j)) print_function('{}: Computing spectrograms (finished)'.format( segment.ytid))
def load_frame(self, index): if not os.path.exists(self.frame(index)): ops.extract_frames(self.raw, self.frames_dir, self.start_seconds) return tp.load_image(self.frame(index))
def test_extract_frames_with_start_time_offset(test_video_file, output_dir): ops.extract_frames(test_video_file, output_dir, start_time=3) assert 100 <= len(os.listdir(output_dir)) < 125 shutil.rmtree(os.path.dirname(output_dir))
def test_extract_frames_should_create_output_parent_dir( test_video_file, output_dir): ops.extract_frames(test_video_file, output_dir) assert os.path.exists(output_dir) shutil.rmtree(os.path.dirname(output_dir))
def test_extract_frames_with_non_dir_output_dir(test_video_file, non_existing_test_video_file): with open(non_existing_test_video_file, 'a'): with pytest.raises(NotADirectoryError): ops.extract_frames(test_video_file, non_existing_test_video_file) os.remove(non_existing_test_video_file)
def test_extract_frames_with_non_existing_video(non_existing_test_video_file, output_dir): os.makedirs(output_dir, exist_ok=True) with pytest.raises(FileNotFoundError): ops.extract_frames(non_existing_test_video_file, output_dir) os.removedirs(output_dir)
def test_extract_frames(test_video_file, output_dir): os.makedirs(output_dir, exist_ok=True) ops.extract_frames(test_video_file, output_dir) assert os.path.exists(output_dir) assert len(os.listdir(output_dir)) == 184 shutil.rmtree(os.path.dirname(output_dir))