Created
September 6, 2025 12:07
-
-
Save marffinn/af48e59c3029e754794380164f014984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/data/com.termux/files/usr/bin/bash | |
# Ensure storage and camera permissions | |
termux-setup-storage | |
termux-toast "Grant camera/storage permissions in Termux:API app if prompted" | |
# Install dependencies | |
pkg install ncat termux-api -y | |
# Camera ID (set based on termux-camera-info output) | |
CAMERA_ID=0 | |
PORT=8080 | |
# Create a temporary directory for images | |
mkdir -p ~/stream | |
cd ~/stream | |
# Check if termux-camera-photo is available | |
if ! command -v termux-camera-photo >/dev/null 2>&1; then | |
echo "Error: termux-camera-photo not found. Install Termux:API from F-Droid." | |
exit 1 | |
fi | |
# Test camera | |
termux-camera-info >/dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Error: Camera not accessible. Check Termux:API permissions or try a different CAMERA_ID." | |
echo "Run 'termux-camera-info' to list available cameras." | |
exit 1 | |
fi | |
echo "Starting stream on port $PORT..." | |
# Capture and stream images | |
while true; do | |
termux-camera-photo -c $CAMERA_ID frame.jpg | |
if [ ! -s frame.jpg ]; then | |
echo "Warning: Failed to capture image, retrying..." | |
sleep 1 | |
continue | |
fi | |
if ! cat frame.jpg | ncat --send-only localhost $PORT; then | |
echo "Warning: Failed to send image, retrying..." | |
fi | |
sleep 0.1 # ~10fps, adjust for faster/slower streaming (e.g., 0.05 for ~20fps) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment