Skip to main content

Mobly Android Screen Recorder

Mobly Android Screen Recorder service for using Python code to screencast the Android devices in Mobly tests (https://github.com/google/mobly).

This tool is upgraded to scrcpy v3.3 and adds audio recording feature.

Responsible Use

This tool is designed for legitimate testing and debugging purposes within the context of Mobly. It should only be used in situations where you have:

  • Explicit consent: Obtain clear and informed consent from any individuals
  • whose screens might be recorded.
  • Legitimate purpose: Use the tool for legitimate testing, debugging,
  • or development activities related to Mobly.
  • Data security: Handle recorded screen data responsibly. Store it
  • securely and delete it when it's no longer needed.
  • Transparency: Be transparent about how the tool is being used and what
  • data is being collected.

Misuse of this tool for unauthorized surveillance or any other malicious activity is strictly prohibited.

Remember: Recording someone's screen without their knowledge or consent is a serious breach of privacy and may have legal consequences.

Requirements

  • Python 3.11+
  • Mobly 1.12.2+
  • FFMPEG 6.1.1+

Please make sure your FFMPEG support H.264 (run ffmpeg -codecs and look for libx264 encoder in the output) and the OpenCV in Python built with the H.264 encoder(print(cv2.getBuildInformation()) then look at the Video I/O section).

Note: To use the audio recording feature, you must have ffmpeg installed and available in your system's PATH.

Installation

pip install mobly-android-screen-recorder

Start to Use

After initializing the Android device, you can register the screen recorder service with the following code:

from mobly.controllers.android_device_lib.services import screen_recorder
...

self.dut = self.register_controller(android_device)[0]
# To enable audio recording, set `enable_audio=True` in the configs.
configs = screen_recorder.Configs(enable_audio=True)
self.dut.services.register('screen_recorder', screen_recorder.ScreenRecorder, configs=configs)

Then the screen recorder will start recording the screen when the test starts and stop recording when the test finishes. The screen recording will be saved to the test output folder as a video file during teardown process for each test case with create_output_excerpts_all for all registered Mobly services.

Example 1: Hello World!

Let's start with the simple example of posting "Hello World" on the Android device's screen. Create the following files: sample_config.yml

TestBeds:
  # A test bed where adb will find Android devices.
  - Name: SampleTestBed
    Controllers:
        AndroidDevice: '*'

hello_world_test.py

from mobly import base_test
from mobly import test_runner
from mobly.controllers import android_device
from mobly.controllers.android_device_lib.services import screen_recorder

class HelloWorldTest(base_test.BaseTestClass):

  def setup_class(self):
    # Registering android_device controller module declares the test's
    # dependency on Android device hardware. By default, we expect at least one
    # object is created from this.
    self.ads = self.register_controller(android_device)
    self.dut = self.ads[0]
    # Start Mobly Bundled Snippets (MBS).
    self.dut.load_snippet('mbs', android_device.MBS_PACKAGE)
    # Register screen recorder service, it will start recording when the test
    # starts and stop recording when the test finishes.
    # To enable audio recording, set `enable_audio=True` in the configs.
    configs = screen_recorder.Configs(enable_audio=True)
    self.dut.services.register('screen_recorder', screen_recorder.ScreenRecorder, configs=configs)

  def test_hello(self):
    self.dut.mbs.makeToast('Hello World!')

  def teardown_test(self):
    self.dut.services.create_output_excerpts_all(self.current_test_info)

if __name__ == '__main__':
  test_runner.main()

To execute:

$ python hello_world_test.py -c sample_config.yml

Expect:

A "Hello World!" toast notification appears on your device's screen. And a video file named video,{device_serial},{device_model},{timestamp}.mp4 is created in the test output folder.

Disclaimer

This tool, owned by Google and its developers, provides screen recording functionality for Android devices within the context of Mobly testing. It is essential to use this tool responsibly and ethically.

Privacy Warning: Screen recording can capture sensitive information. Always obtain explicit consent before recording anyone's screen. Unauthorized screen recording may violate privacy laws and ethical guidelines. Neither Google nor the developers of this tool are responsible for any misuse or illegal activity conducted with this software.

Users of this tool are solely responsible for ensuring compliance with all applicable laws and regulations regarding privacy and data protection.

Licensing

This project is licensed under the Apache License 2.0.

This project uses scrcpy, which is licensed under the Apache License 2.0. See the NOTICE file for details.

Metadata

Release files for mobly-android-screen-recorder 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mobly-android-screen-recorder 1.0.4
File Size Uploaded Provenance Actions
mobly_android_screen_recorder-1.0.4.tar.gz 3.7 MB With provenance Details for mobly_android_screen_recorder-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mobly-android-screen-recorder 1.0.4
File Interpreter ABI Platform Actions
mobly_android_screen_recorder-1.0.4-py3-none-any.whl Python 3 none any Details for mobly_android_screen_recorder-1.0.4-py3-none-any.whl

Total release size: 7.5 MB

Release files / mobly_android_screen_recorder-1.0.4.tar.gz

Download URL mobly_android_screen_recorder-1.0.4.tar.gz
Size 3.7 MB
Tags Source
SHA-256 checksum
How to use checksums
22e41522a973582c5a4be4fa4e19d8fefa75e1c9cd43591839d38f9f0f31a724
BLAKE2b-256 checksum
How to use checksums
0e78bd5836d72c20eb2b5694b85e6d30475d4d76fcfee481269d892de5a34032
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 27, 2026.

Transparency log

Release files / mobly_android_screen_recorder-1.0.4-py3-none-any.whl

Download URL mobly_android_screen_recorder-1.0.4-py3-none-any.whl
Size 3.7 MB
Tags Python 3
SHA-256 checksum
How to use checksums
753d5dcb466755783953888c3d5aeb682e72921937906b60069d2baecf81d15a
BLAKE2b-256 checksum
How to use checksums
fc94d33d9fcb550b50c877921f57d683ef080376b1359124539daa55969c657a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 27, 2026.

Transparency log

Security for mobly-android-screen-recorder 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mobly_android_screen_recorder-1.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page