Index: tools/telemetry/telemetry/core/platform/android_platform_backend.py |
diff --git a/tools/telemetry/telemetry/core/platform/android_platform_backend.py b/tools/telemetry/telemetry/core/platform/android_platform_backend.py |
index 64c8f645c1a32d5ddc20604bf48c99d5dc9d8440..bbae1e6dbaa40b90e10d091b7476745c60f10b7a 100644 |
--- a/tools/telemetry/telemetry/core/platform/android_platform_backend.py |
+++ b/tools/telemetry/telemetry/core/platform/android_platform_backend.py |
@@ -3,10 +3,9 @@ |
# found in the LICENSE file. |
import logging |
-import subprocess |
import tempfile |
-from telemetry.core import bitmap |
+from telemetry.core import bitmapiter |
from telemetry.core import exceptions |
from telemetry.core import platform |
from telemetry.core import util |
@@ -213,62 +212,9 @@ class AndroidPlatformBackend( |
self._video_recorder.Stop() |
self._video_output = self._video_recorder.Pull() |
self._video_recorder = None |
- for frame in self._FramesFromMp4(self._video_output): |
- yield frame |
- |
- def _FramesFromMp4(self, mp4_file): |
if not self.CanLaunchApplication('avconv'): |
self.InstallApplication('avconv') |
- |
- def GetDimensions(video): |
- proc = subprocess.Popen(['avconv', '-i', video], stderr=subprocess.PIPE) |
- dimensions = None |
- output = '' |
- for line in proc.stderr.readlines(): |
- output += line |
- if 'Video:' in line: |
- dimensions = line.split(',')[2] |
- dimensions = map(int, dimensions.split()[0].split('x')) |
- break |
- proc.wait() |
- assert dimensions, ('Failed to determine video dimensions. output=%s' % |
- output) |
- return dimensions |
- |
- def GetFrameTimestampMs(stderr): |
- """Returns the frame timestamp in integer milliseconds from the dump log. |
- |
- The expected line format is: |
- ' dts=1.715 pts=1.715\n' |
- |
- We have to be careful to only read a single timestamp per call to avoid |
- deadlock because avconv interleaves its writes to stdout and stderr. |
- """ |
- while True: |
- line = '' |
- next_char = '' |
- while next_char != '\n': |
- next_char = stderr.read(1) |
- line += next_char |
- if 'pts=' in line: |
- return int(1000 * float(line.split('=')[-1])) |
- |
- 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', 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) |
- if not num_read: |
- raise StopIteration |
- assert num_read == len(frame_data), 'Unexpected frame size: %d' % num_read |
- yield (GetFrameTimestampMs(proc.stderr), |
- bitmap.Bitmap(3, dimensions[0], dimensions[1], frame_data)) |
+ return bitmapiter.BitmapIter(self._video_output) |
def _GetFileContents(self, fname): |
if not self._can_access_protected_file_contents: |