#!/bin/bash source config SCAN_COUNT=0 SCAN_ATTEMPTS=3 FFMPEG_LOGLEVEL="repeat+level+info" mkdir -p ./rec/ cleanup() { adb_pid=$(ps aux | grep 'adb' | grep ${android} | awk '{print $2}'); echo "] Killing adb services with pid: ${adb_pid}" kill -9 ${adb_pid} exit } # Trap interrupts and exit instead of continuing the loop trap cleanup SIGINT SIGTERM # check if the android host is even alive if ping -c 1 ${android} &> /dev/null then echo "] ping success :)" else echo "] ping error :(" exit 1 fi is_correct_port () { # check if port 5555 is open PORT=$(nmap -sT -P0 ${android} -p 5555 | awk -F/ '/tcp open/{print $1}') if [[ $PORT == 5555 ]]; then echo "] port 5555 is open :)" return 0 else return 1 fi } until is_correct_port || [[ $SCAN_COUNT -eq $SCAN_ATTEMPTS ]]; do # scan and set the port to 5555 if [ ! -n "$1" ]; then RANGE="30000-49999" else RANGE="$1" fi echo "] Checking port(s) ${RANGE}" adb connect ${android}:$(nmap -sT -P0 ${android} -p${RANGE} | awk -F/ '/tcp open/{print $1}') adb tcpip 5555 adb disconnect echo -e "\n] $(( SCAN_COUNT++ ))..." sleep 1 done [[ $SCAN_COUNT -eq $SCAN_ATTEMPTS ]] && echo "] could not set the tcpip port :(" && (exit 1) ### adb disconnect adb connect ${android}:5555 scrcpy -n \ --video-source=camera --no-audio --no-video-playback \ --camera-id=2 --camera-size=1920x1080 --camera-fps=30 --orientation=90 \ --v4l2-sink=/dev/video5 & while : do CURRENTDATE=`date +"%Y_%m_%d_%T"` echo "] ffmpeg start at ${CURRENTDATE}" #calf plugins #input_audio_filter="-af lv2=p=http\\\\://calf.sourceforge.net/plugins/Gate:c=threshold=0.04010706|knee=8|range=0.03148599, lv2=http\\\\://calf.sourceforge.net/plugins/Compressor:c=knee=8|threshold=0.125, lv2=http\\\\://calf.sourceforge.net/plugins/Limiter:c=level_out=0.71697748|limit=0.62763602" #load normalization #output_audio_filter="-filter:a loudnorm" ffmpeg -hide_banner -loglevel ${FFMPEG_LOGLEVEL} -threads:v 2 -threads:a 8 -filter_threads 2 \ -thread_queue_size 512 -f v4l2 -framerate 30 -pix_fmt yuv420p -i /dev/video5 \ -thread_queue_size 512 -f alsa -ac 2 -i plughw:CARD=USB ${input_audio_filter} \ -bsf:a aac_adtstoasc -c:a aac -ac 2 -b:a 192k ${output_audio_filter} \ -init_hw_device vaapi=va:/dev/dri/renderD128 -filter_hw_device va \ -vf 'format=nv12,hwupload' \ -c:v h264_vaapi -b:v 6000k -minrate:v 6000k -maxrate:v 6000k -bufsize:v 6000k \ -r:v 30 -g:v 120 -bf:v 3 -refs:v 16 \ -f tee "[f=mpegts]${srt_output}|[f=matroska]local_recording_${CURRENTDATE}.mkv" #CURRENTDATE=`date +"%Y_%m_%d_%T"` echo "] ffmpeg end at ${CURRENTDATE}" sleep 5 done