Ejemplo n.º 1
0
def main():
    random.seed(0)
    if len(adb.get_devices()) > 0:
        suite = unittest.TestLoader().loadTestsFromName(__name__)
        unittest.TextTestRunner(verbosity=3).run(suite)
    else:
        print('Test suite must be run with attached devices')
def main():
    random.seed(0)
    if len(adb.get_devices()) > 0:
        suite = unittest.TestLoader().loadTestsFromName(__name__)
        unittest.TextTestRunner(verbosity=3).run(suite)
    else:
        print('Test suite must be run with attached devices')
Ejemplo n.º 3
0
def run(filename=None, size=None, fps=None, video_quality=None):
    """
    Records Android device screen to an optimized GIF or MP4 file. The type of the output is chosen depending on the file extension.
    """

    print("RoboGif Recorder v%s" % (VERSION,))
    check_requirements()
    output_video_mode = False

    if not (filename.lower().endswith(".mp4") or filename.lower().endswith(".gif")):
        print("Usage: %s [output filename].[mp4|gif]" % (sys.argv[0],))
        print(
            t.red("Filename must either end with"),
            t.green("mp4"),
            t.red("for video or"),
            t.green("gif"),
            t.red("for a GIF."),
        )
        print
        sys.exit(-4)

    if filename.lower().endswith(".mp4"):
        output_video_mode = True

    if fps is None:
        if output_video_mode:
            fps = 60
        else:
            fps = 15

    # Show device chooser if more than one device is selected
    device_id = None
    devices = get_devices()
    if len(devices) == 0:
        print(t.red("No adb devices found, connect one."))
        sys.exit(-3)
    elif len(devices) == 1:
        device_id = list(devices.keys())[0]
    else:
        device_id = get_chosen_device(devices)

    print(t.green("Starting recording on %s..." % (device_id,)))
    print(t.yellow("Press Ctrl+C to stop recording."))

    recorder = subprocess.Popen(
        ["adb", "-s", device_id, "shell", "screenrecord", "--bit-rate", "8000000", "/sdcard/tmp_record.mp4"]
    )
    try:
        while recorder.poll() is None:
            time.sleep(0.2)
    except KeyboardInterrupt:
        pass

    try:
        recorder.send_signal(signal.SIGTERM)
        recorder.wait()
    except OSError:
        print
        print(t.red("Recording has failed, it's possible that your device does not support recording."))
        print(t.normal + "Recording is supported on devices running KitKat (4.4) or newer.")
        print(t.normal + "Genymotion and stock emulator do not support it.")
        print
        sys.exit(-3)
    # We need to wait for MOOV item to be written
    time.sleep(2)

    print(t.green("Recording done, downloading file...."))
    tmp_video_file = get_new_temp_file_path("mp4")

    # Download file and cleanup
    try:
        subprocess.check_call(["adb", "-s", device_id, "pull", "/sdcard/tmp_record.mp4", tmp_video_file])
        subprocess.check_call(["adb", "-s", device_id, "shell", "rm", "/sdcard/tmp_record.mp4"])

        if output_video_mode:
            create_optimized_video(tmp_video_file, filename, size, fps, video_quality)
        else:
            create_optimized_gif(tmp_video_file, filename, size, fps)

    except subprocess.CalledProcessError:
        print(t.red("Could not download recording from the device."))
        sys.exit(-1)
    finally:
        os.remove(tmp_video_file)
Ejemplo n.º 4
0
def run(filename=None, size=None, fps=None, video_quality=None):
    """
    Records Android device screen to an optimized GIF or MP4 file. The type of the output is chosen depending on the file extension.
    """

    print("RoboGif Recorder v%s" % (VERSION,))
    check_requirements()
    output_video_mode = False

    if not (filename.lower().endswith(".mp4") or filename.lower().endswith(".gif")):
        print("Usage: %s [output filename].[mp4|gif]" % (sys.argv[0], ))
        print(t.red("Filename must either end with"), t.green("mp4"), t.red("for video or"), t.green("gif"), t.red("for a GIF."))
        print
        sys.exit(-4)

    if filename.lower().endswith(".mp4"):
        output_video_mode = True

    if fps is None:
        if output_video_mode:
            fps = 60
        else:
            fps = 15

    # Show device chooser if more than one device is selected
    device_id = None
    devices = get_devices()
    if len(devices) == 0:
        print(t.red("No adb devices found, connect one."))
        sys.exit(-3)
    elif len(devices) == 1:
        device_id = list(devices.keys())[0]
    else:
        device_id = get_chosen_device(devices)

    print(t.green("Starting recording on %s..." % (device_id, )))
    print(t.yellow("Press Ctrl+C to stop recording."))

    recorder = subprocess.Popen(["adb", "-s", device_id, "shell", "screenrecord", "--bit-rate", "8000000", "/sdcard/tmp_record.mp4"])
    try:
        while recorder.poll() is None:
            time.sleep(0.2)
    except KeyboardInterrupt:
        pass

    try:
        recorder.send_signal(signal.SIGTERM)
        recorder.wait()
    except OSError:
        print
        print(t.red("Recording has failed, it's possible that your device does not support recording."))
        print(t.normal + "Recording is supported on devices running KitKat (4.4) or newer.")
        print(t.normal + "Genymotion and stock emulator do not support it.")
        print
        sys.exit(-3)
    # We need to wait for MOOV item to be written
    time.sleep(2)

    print(t.green("Recording done, downloading file...."))
    tmp_video_file = get_new_temp_file_path("mp4")

    # Download file and cleanup
    try:
        subprocess.check_call(["adb", "-s", device_id, "pull", "/sdcard/tmp_record.mp4", tmp_video_file])
        subprocess.check_call(["adb", "-s", device_id, "shell", "rm", "/sdcard/tmp_record.mp4"])

        if output_video_mode:
            create_optimized_video(tmp_video_file, filename, size, fps, video_quality)
        else:
            create_optimized_gif(tmp_video_file, filename, size, fps)

    except subprocess.CalledProcessError:
        print(t.red("Could not download recording from the device."))
        sys.exit(-1)
    finally:
        os.remove(tmp_video_file)