Initial commit

This commit is contained in:
2026-05-14 19:22:48 +02:00
commit ef0d17680f
21 changed files with 362 additions and 0 deletions
Executable
+62
View File
@@ -0,0 +1,62 @@
#!/system/bin/sh
CONFIG_FILE="/data/local/tmp/virtualcam_config.json"
MODDIR=$(dirname "$0")
load_config() {
[ -f "$CONFIG_FILE" ] && . /data/adb/modules/alias/system/bin/shflags 2>/dev/null || true
SOURCE_TYPE=$(grep -o '"source_type":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
RTSP_URL=$(grep -o '"rtsp_url":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
MP4_PATH=$(grep -o '"mp4_path":"[^"]*"' "$CONFIG_FILE" 2>/dev/null | cut -d'"' -f4)
RES_W=$(grep -o '"res_w":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
RES_H=$(grep -o '"res_h":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
FPS=$(grep -o '"fps":[0-9]*' "$CONFIG_FILE" 2>/dev/null | cut -d: -f2)
: ${SOURCE_TYPE:=rtsp} ${RTSP_URL:=rtsp://192.168.1.100:8554/stream}
: ${MP4_PATH:=/sdcard/Download/video.mp4} ${RES_W:=1920} ${RES_H:=1080} ${FPS:=30}
}
case "${1:-help}" in
status)
PROVIDER_PID=$(pgrep -f virtual_camera_provider | head -1)
FEEDER_PID=$(pgrep -f "ffmpeg.*video0\|gst-launch.*video0" | head -1)
V4L2=$(lsmod 2>/dev/null | grep -q v4l2loopback && echo 1 || echo 0)
SVC=$(service list 2>/dev/null | grep -q "virtual/0" && echo 1 || echo 0)
VIDEO=$(cat /sys/class/video4linux/video0/name 2>/dev/null || echo "not found")
echo "{\"provider_pid\":${PROVIDER_PID:-0},\"feeder_pid\":${FEEDER_PID:-0},\"v4l2_loaded\":$V4L2,\"service_registered\":$SVC,\"video0\":\"$VIDEO\"}"
;;
start)
insmod "$MODDIR/v4l2loopback.ko" devices=1 video_nr=0 card_label="VirtualCam" exclusive_caps=1 2>/dev/null || true
pkill -9 -f virtual_camera_provider 2>/dev/null || true
"$MODDIR/vendor/bin/virtual_camera_provider" -d /dev/video0 -w 1920 -h 1080 -i virtual &
echo '{"status":"started"}'
;;
stop)
pkill -9 -f virtual_camera_provider 2>/dev/null || true
echo '{"status":"stopped"}'
;;
start_feeder)
load_config
pkill -9 -f "ffmpeg.*video0\|gst-launch.*video0" 2>/dev/null || true
if [ "$SOURCE_TYPE" = "rtsp" ]; then
ffmpeg -rtsp_transport tcp -i "$RTSP_URL" -f v4l2 -input_format nv21 \
-video_size "${RES_W}x${RES_H}" -framerate "$FPS" -pix_fmt nv21 /dev/video0 &
elif [ "$SOURCE_TYPE" = "mp4" -a -f "$MP4_PATH" ]; then
ffmpeg -stream_loop -1 -re -i "$MP4_PATH" -f v4l2 -input_format nv21 \
-video_size "${RES_W}x${RES_H}" -framerate "$FPS" -pix_fmt nv21 /dev/video0 &
fi
echo '{"status":"feeder_started"}'
;;
stop_feeder)
pkill -9 -f "ffmpeg.*video0\|gst-launch.*video0" 2>/dev/null || true
echo '{"status":"feeder_stopped"}'
;;
get_config)
load_config
echo "{\"source_type\":\"$SOURCE_TYPE\",\"rtsp_url\":\"$RTSP_URL\",\"mp4_path\":\"$MP4_PATH\",\"res_w\":$RES_W,\"res_h\":$RES_H,\"fps\":$FPS}"
;;
set_config|save)
cat > "$CONFIG_FILE" << DATA
{"source_type":"$2","rtsp_url":"$3","mp4_path":"$4","res_w":$5,"res_h":$6,"fps":$7}
DATA
echo '{"status":"saved"}'
;;
esac