def testFramesFromMp4(self): host_platform = platform.GetHostPlatform() try: host_platform.InstallApplication('avconv') finally: if not host_platform.CanLaunchApplication('avconv'): logging.warning('Test not supported on this platform') return # pylint: disable=W0150 vid = os.path.join(util.GetUnittestDataDir(), 'vid.mp4') expected_timestamps = [ 0, 763, 783, 940, 1715, 1732, 1842, 1926, ] video_obj = video.Video(vid) # Calling _FramesFromMp4 should return all frames. # pylint: disable=W0212 for i, timestamp_bitmap in enumerate(video_obj._FramesFromMp4(vid)): timestamp, bmp = timestamp_bitmap self.assertEquals(timestamp, expected_timestamps[i]) expected_bitmap = image_util.FromPngFile( os.path.join(util.GetUnittestDataDir(), 'frame%d.png' % i)) self.assertTrue(image_util.AreEqual(expected_bitmap, bmp))
def _ExtractCompletenessRecordFromVideo(video_path): """Extracts the completeness record from a video. The video must start with a filled rectangle of orange (RGB: 222, 100, 13), to give the view-port size/location from where to compute the completeness. Args: video_path: Path of the video to extract the completeness list from. Returns: list(CompletenessPoint) """ video_file = tempfile.NamedTemporaryFile() shutil.copy(video_path, video_file.name) video_capture = video.Video(video_file) histograms = [(time, image_util.GetColorHistogram(image, ignore_color=rgba_color.WHITE, tolerance=8)) for time, image in video_capture.GetVideoFrameIter()] start_histogram = histograms[1][1] final_histogram = histograms[-1][1] total_distance = start_histogram.Distance(final_histogram) def FrameProgress(histogram): if total_distance == 0: if histogram.Distance(final_histogram) == 0: return 1.0 else: return 0.0 return 1 - histogram.Distance(final_histogram) / total_distance return [(time, FrameProgress(hist)) for time, hist in histograms]
def StopVideoCapture(self): assert self.is_video_capture_running, 'Must start video capture first' self._video_recorder.Stop() video_file_obj = tempfile.NamedTemporaryFile() self._video_recorder.Pull(video_file_obj.name) self._video_recorder = None return video.Video(video_file_obj)
def StopVideoCapture(self): self._is_video_capture_running = False return video.Video(tempfile.NamedTemporaryFile())