IGPenguin / mobile-toolkit

πŸ“± Terminal tool for Android & iOS device management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replace Android screen recording logic with scrcpy to allow audio recording

luispinho opened this issue Β· comments

🐞 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.

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

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

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. πŸ™

Solution proposed in new PR

Solved in #225 and #226, thank you! πŸ–€