Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve record_adb.py and combine-videos-side-by-side.sh for startup comparisons #41

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion combine-videos-side-by-side.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ USAGE="USAGE: ./combine-videos-side-by-side.sh input1 input2 output"
: ${2?$USAGE}
: ${3?$USAGE}

INTERMEDIATE_FILE=intermediate-$3
INTERMEDIATE_FILE=$3.intermediate.mp4

# Combine videos side-by-side, adapted from https://stackoverflow.com/a/42257415/2219998
ffmpeg -i $1 -i $2 -filter_complex hstack -vsync cfr -r:v 30 $INTERMEDIATE_FILE
Expand Down
36 changes: 20 additions & 16 deletions record_adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,34 @@
# The consistency allows us to compare said video.
def main(args):
method = args.input
recording_name = './sdcard/output.mp4'
device_path = './sdcard/output.mp4'

if args.output is not None:
recording_name = './sdcard/' + args.output
if method in 'touch' and (args.coordinate_x is None or args.coordinate_y is None):
print('--touch requires --coordinate-x <coordinate> --coordinate-y <coordinate> to use the touch input')
sys.exit()
# if method in 'intent' and args.package is None:
# print('--intent requires --package <your.package.name>')
# sys.exit()

check_for_existing_process()
record_process = subprocess.Popen(['adb', 'shell', 'screenrecord'] + [recording_name])
kill_existing_processes("org.mozilla")
kill_existing_processes("com.android.chrome")
kill_existing_processes("org.chromium.chrome")
time.sleep(3)

# Start the recording. screenrecord --bugreport puts timestamps at the top of the video and adds
# a frame with device information at the beginning.
record_process = subprocess.Popen(['adb', 'shell', 'screenrecord', '--bugreport'] + [device_path])
time.sleep(3)

# TODO allow intent trigger
# if method in 'intent':
# record_with_intent(args.package)
# else:
simulate_input(args.coordinate_x, args.coordinate_y)
pull_recording(record_process, recording_name)
time.sleep(5)
record_process.kill()
time.sleep(5)
pull_recording(device_path, args.output)

# def record_with_intent(package):
# activity_start = subprocess.Popen(['adb', 'shell', 'am', 'start-activity', package +'/.App',
Expand All @@ -48,28 +55,25 @@ def simulate_input(x, y):
tap_event.wait()


def pull_recording(record_process, recording_name):
time.sleep(5)
record_process.kill()
time.sleep(5)
proc = subprocess.Popen(['adb', 'pull'] + [recording_name])
def pull_recording(device_path, output):
proc = subprocess.Popen(['adb', 'pull', device_path, output])
proc.wait()


def check_for_existing_process():
def kill_existing_processes(package_substr):
adb_ps_command = subprocess.Popen(['adb', 'shell', 'ps', '-A', '-o', 'NAME'], stdout=subprocess.PIPE)
try:
mozilla_processes = subprocess.check_output(('grep', 'org.mozilla'), stdin=adb_ps_command.stdout)
matching_processes = subprocess.check_output(('grep', package_substr), stdin=adb_ps_command.stdout)
adb_ps_command.wait()
packages_found = mozilla_processes.decode('utf-8').split('\n')
packages_found = matching_processes.decode('utf-8').split('\n')
for package in packages_found:
if package is '':
if package == '':
continue
kill_process = subprocess.Popen(['adb', 'shell', 'am', 'force-stop'] + [package])
kill_process.wait()
print('Successfully killed process %s' % package)
except subprocess.CalledProcessError as e:
print("no mozilla processes found")
print("no processes matching %s found, not killing any" % package_substr)
return


Expand Down
Loading