IGPenguin / mobile-toolkit

📱 Terminal tool for Android & iOS device management
MIT License
356 stars 43 forks source link

Replace Android screen recording logic with scrcpy to allow audio recording #223

Closed luispinho closed 1 year ago

luispinho commented 1 year ago

🐞 Whats wrong

Using arecord allows us to record the video, but not the audio.

🌈 Desired state

When using this command, record both video and audio (or give a flag to only record video, for example).

📏 Challenges

Replace usage of screenrecord utility within ADB shell with scrcpy (we're already using it for acontrol, we can use it here as well).

📂 Sources

scrcpy documentation about recording

For a start, I would suggest the following:

#!/bin/bash
LOCATION=$(dirname "$0")
source "$LOCATION"/../common_tools
trap 'ctrlc $@' 1 2 3 6 15

ctrlc(){
  adb -s "$SELECTED_DEVICE" shell settings put system show_touches 0
  if $RECORDING ; then
    sleep 1
    echo "✅ Saved into ~/Desktop/$FILENAME.mp4"
  fi
  exit
}

RECORDING=false
android_choose_device

android_get_device_sdk "$SELECTED_DEVICE"
android_get_storage_location_per_SDK "$SDK"

RECORDING=true
echo "📹 Recording screen on $SELECTED_DEVICE, stop it using ctrl^c"
adb -s "$SELECTED_DEVICE" shell settings put system show_touches 1

if [ -z "$1" ] ; then
      android_device_info "$SELECTED_DEVICE"
      FILENAME=$MANUFACTURER-$MODEL-API$SDK-$(date +%Y-%m-%d-%H-%M-%S)
else
      FILENAME=$1
fi

OUTPUT_PATH=~/Desktop/"$FILENAME".mp4

scrcpy -s "$SELECTED_DEVICE" --verbosity=error --no-playback --audio-codec=aac --record=file.mp4 --record=$OUTPUT_PATH

Eventually we could also add a flag to allow using the existing recording method.

IGPenguin commented 1 year ago

Hello @luispinho, thanks for your suggestion. I'll look into that as soon as I have some spare time. 👍

luispinho commented 1 year ago

Sure. I can open a PR with the base change (already have it working on my machine). Just need some input on which flags (if any) you feel would be a good addition to this. Other than that, I can contribute with what I've already shown in the issue's description

IGPenguin commented 1 year ago

I think it would be good to retain the original implementation under -l (legacy) flag in case scrcpy does not work for some devices/setups.

Other then that audio capture can be on by default. Feel free to open a PR. 🙏

luispinho commented 1 year ago

Solution proposed in new PR

IGPenguin commented 1 year ago

Solved in #225 and #226, thank you! 🖤