• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import argparse, common, datetime
6
7from autotest_lib.client.common_lib import file_utils
8from autotest_lib.client.common_lib.cros import chrome
9from autotest_lib.client.cros.video import media_test_factory, \
10    sequence_generator
11
12
13def main():
14    """
15    Loads specified video in a chrome HTML5 player and collects its screenshots
16    at specified time instances.
17    """
18
19    parser = argparse.ArgumentParser(
20        formatter_class=argparse.RawDescriptionHelpFormatter,
21
22        description='Capture images of a video.',
23
24        epilog='''
25        This tool supports image-comparison-based video glitch detection tests.
26
27        Use this tool to capture golden/reference images that will be used to
28        verify test images captured during a video playback.
29
30        Run this tool directly on the device.
31
32        Copy tool first into /usr/local/autotest/cros so that autotest's
33        common.py is imported so as to resolve autotest references correctly.
34
35        Output images will be placed under /tmp/test. Images will be saved as
36        hh_mm_ss_mss.png denoting the moment in time it was captured.
37
38        ''')
39
40    parser.add_argument("name",
41                        help="Name of video to use.")
42
43    parser.add_argument("format",
44                        choices=['mp4', 'webm'],
45                        help="Video format to use.")
46
47    parser.add_argument("definition",
48                        choices=['480p', '720p', '1080p', '720p_1080p'],
49                        help="Video definition to use.")
50
51    parser.add_argument("--start",
52                        default="00:01",
53                        help="Time to start taking screenshots. (mm:ss)")
54
55    parser.add_argument("--stop",
56                        help="Time to stop taking screenshots. (mm:ss).")
57
58    parser.add_argument("interval",
59                        type=int,
60                        help="Seconds between two successive captures.")
61
62    args = parser.parse_args()
63
64    time_format = '%M:%S'
65
66    # Parse time arguments from user
67    # Start time has a default argument of 01:00, parse right away
68    # Parse stop time later as we don't know the length of the video,
69    # the factory does
70    tmp = datetime.datetime.strptime(args.start, time_format)
71    start = datetime.timedelta(minutes=tmp.minute, seconds=tmp.second)
72
73    with chrome.Chrome() as cr:
74        bindir = '/usr/local/autotest/cros/video'
75
76        cr.browser.platform.SetHTTPServerDirectories(bindir)
77
78        factory = media_test_factory.MediaTestFactory(
79                      cr.browser.tabs[0],
80                      cr.browser.platform.http_server,
81                      bindir,
82                      'dev',
83                      args.name,
84                      args.format,
85                      args.definition)
86
87        # if stop time is not specified, use the length of the video
88        if args.stop is None:
89            stop = factory.media_length
90        else:
91            tmp = datetime.datetime.strptime(args.stop, time_format)
92            stop = datetime.timedelta(minutes=tmp.minute, seconds=tmp.second)
93
94        file_utils.rm_dir_if_exists(factory.test_working_dir)
95
96        file_utils.make_leaf_dir(factory.test_working_dir)
97
98        seq = sequence_generator.generate_interval_sequence(start,
99                                                            stop,
100                                                            args.interval)
101
102        collector = factory.make_video_screenshot_collector()
103
104        collector.ensure_player_is_ready()
105
106        collector.collect_multiple_screenshots(seq)
107
108
109if __name__ == '__main__':
110    main()