Index: tools/telemetry/telemetry/core/video.py |
diff --git a/tools/telemetry/telemetry/core/video.py b/tools/telemetry/telemetry/core/video.py |
index c4211e4fe55712267657c6fe6d7a9c955fb353f2..4eb4cab3bbcf3714d1e69d18644de58d5c24ecd2 100644 |
--- a/tools/telemetry/telemetry/core/video.py |
+++ b/tools/telemetry/telemetry/core/video.py |
@@ -18,13 +18,9 @@ |
"""Utilities for storing and interacting with the video capture.""" |
def __init__(self, video_file_obj): |
- """Initializes the Video object. |
- |
- args: |
- video_file: A file-like object.""" |
- assert(hasattr(video_file_obj, 'name')) |
+ assert video_file_obj.delete |
+ assert not video_file_obj.close_called |
self._video_file_obj = video_file_obj |
- |
self._tab_contents_bounding_box = None |
def UploadToCloudStorage(self, bucket, target_path): |
@@ -47,7 +43,7 @@ |
time_ms is milliseconds since navigationStart. |
bitmap is a telemetry.core.Bitmap. |
""" |
- frame_generator = self._FramesFromMp4() |
+ frame_generator = self._FramesFromMp4(self._video_file_obj.name) |
# Flip through frames until we find the initial tab contents flash. |
content_box = None |
@@ -117,7 +113,7 @@ |
return self._tab_contents_bounding_box |
- def _FramesFromMp4(self): |
+ def _FramesFromMp4(self, mp4_file): |
host_platform = platform.GetHostPlatform() |
if not host_platform.CanLaunchApplication('avconv'): |
host_platform.InstallApplication('avconv') |
@@ -155,15 +151,14 @@ |
if 'pts=' in line: |
return int(1000 * float(line.split('=')[-1])) |
- dimensions = GetDimensions(self._video_file_obj.name) |
+ dimensions = GetDimensions(mp4_file) |
frame_length = dimensions[0] * dimensions[1] * 3 |
frame_data = bytearray(frame_length) |
# Use rawvideo so that we don't need any external library to parse frames. |
- proc = subprocess.Popen(['avconv', '-i', self._video_file_obj.name, |
- '-vcodec', 'rawvideo', '-pix_fmt', 'rgb24', |
- '-dump', '-loglevel', 'debug', '-f', 'rawvideo', |
- '-'], |
+ proc = subprocess.Popen(['avconv', '-i', mp4_file, '-vcodec', |
+ 'rawvideo', '-pix_fmt', 'rgb24', '-dump', |
+ '-loglevel', 'debug', '-f', 'rawvideo', '-'], |
stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
while True: |
num_read = proc.stdout.readinto(frame_data) |