Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import subprocess | 5 import subprocess |
| 6 import tempfile | |
| 6 | 7 |
| 7 from telemetry.core import bitmap | 8 from telemetry.core import bitmap |
| 8 from telemetry.core import platform | 9 from telemetry.core import platform |
| 9 from telemetry.page import cloud_storage | 10 from telemetry.page import cloud_storage |
| 10 | 11 |
| 11 HIGHLIGHT_ORANGE_FRAME = bitmap.WEB_PAGE_TEST_ORANGE | 12 HIGHLIGHT_ORANGE_FRAME = bitmap.WEB_PAGE_TEST_ORANGE |
| 12 | 13 |
| 13 class BoundingBoxNotFoundException(Exception): | 14 class BoundingBoxNotFoundException(Exception): |
| 14 pass | 15 pass |
| 15 | 16 |
| 16 | 17 |
| 17 class Video(object): | 18 class Video(object): |
| 18 """Utilities for storing and interacting with the video capture.""" | 19 """Utilities for storing and interacting with the video capture.""" |
| 19 | 20 |
| 20 def __init__(self, video_file_path): | 21 def __init__(self, video_file_obj): |
| 21 # TODO(satyanarayana): Figure out when to delete this file. | 22 assert isinstance(video_file_obj, tempfile.NamedTemporaryFile) |
|
nednguyen
2014/07/08 23:24:20
You may also want to assert that video_file_obj.cl
Satyanarayana N H Manyam
2014/07/09 00:58:02
class name here (tempfile._TemporaryFileWrapper) i
Satyanarayana N H Manyam
2014/07/09 00:58:02
Done.
| |
| 22 self._video_file_path = video_file_path | 23 self._video_file_obj = video_file_obj |
| 23 self._tab_contents_bounding_box = None | 24 self._tab_contents_bounding_box = None |
| 24 | 25 |
| 25 def UploadToCloudStorage(self, bucket, target_path): | 26 def UploadToCloudStorage(self, bucket, target_path): |
| 26 """Uploads video file to cloud storage. | 27 """Uploads video file to cloud storage. |
| 27 | 28 |
| 28 Args: | 29 Args: |
| 29 target_path: Path indicating where to store the file in cloud storage. | 30 target_path: Path indicating where to store the file in cloud storage. |
| 30 """ | 31 """ |
| 31 cloud_storage.Insert(bucket, target_path, self._video_file_path) | 32 cloud_storage.Insert(bucket, target_path, self._video_file_obj.name) |
| 32 | 33 |
| 33 def GetVideoFrameIter(self): | 34 def GetVideoFrameIter(self): |
| 34 """Returns the iteration for processing the video capture. | 35 """Returns the iteration for processing the video capture. |
| 35 | 36 |
| 36 This looks for the initial color flash in the first frame to establish the | 37 This looks for the initial color flash in the first frame to establish the |
| 37 tab content boundaries and then omits all frames displaying the flash. | 38 tab content boundaries and then omits all frames displaying the flash. |
| 38 | 39 |
| 39 Yields: | 40 Yields: |
| 40 (time_ms, bitmap) tuples representing each video keyframe. Only the first | 41 (time_ms, bitmap) tuples representing each video keyframe. Only the first |
| 41 frame in a run of sequential duplicate bitmaps is typically included. | 42 frame in a run of sequential duplicate bitmaps is typically included. |
| 42 time_ms is milliseconds since navigationStart. | 43 time_ms is milliseconds since navigationStart. |
| 43 bitmap is a telemetry.core.Bitmap. | 44 bitmap is a telemetry.core.Bitmap. |
| 44 """ | 45 """ |
| 45 frame_generator = self._FramesFromMp4(self._video_file_path) | 46 frame_generator = self._FramesFromMp4(self._video_file_obj.name) |
| 46 | 47 |
| 47 # Flip through frames until we find the initial tab contents flash. | 48 # Flip through frames until we find the initial tab contents flash. |
| 48 content_box = None | 49 content_box = None |
| 49 for _, bmp in frame_generator: | 50 for _, bmp in frame_generator: |
| 50 content_box = self._FindHighlightBoundingBox( | 51 content_box = self._FindHighlightBoundingBox( |
| 51 bmp, HIGHLIGHT_ORANGE_FRAME) | 52 bmp, HIGHLIGHT_ORANGE_FRAME) |
| 52 if content_box: | 53 if content_box: |
| 53 break | 54 break |
| 54 | 55 |
| 55 if not content_box: | 56 if not content_box: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 'rawvideo', '-pix_fmt', 'rgb24', '-dump', | 160 'rawvideo', '-pix_fmt', 'rgb24', '-dump', |
| 160 '-loglevel', 'debug', '-f', 'rawvideo', '-'], | 161 '-loglevel', 'debug', '-f', 'rawvideo', '-'], |
| 161 stderr=subprocess.PIPE, stdout=subprocess.PIPE) | 162 stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
| 162 while True: | 163 while True: |
| 163 num_read = proc.stdout.readinto(frame_data) | 164 num_read = proc.stdout.readinto(frame_data) |
| 164 if not num_read: | 165 if not num_read: |
| 165 raise StopIteration | 166 raise StopIteration |
| 166 assert num_read == len(frame_data), 'Unexpected frame size: %d' % num_read | 167 assert num_read == len(frame_data), 'Unexpected frame size: %d' % num_read |
| 167 yield (GetFrameTimestampMs(proc.stderr), | 168 yield (GetFrameTimestampMs(proc.stderr), |
| 168 bitmap.Bitmap(3, dimensions[0], dimensions[1], frame_data)) | 169 bitmap.Bitmap(3, dimensions[0], dimensions[1], frame_data)) |
| OLD | NEW |