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