Skip to content

Instantly share code, notes, and snippets.

@enBonnet
Created November 1, 2024 15:41
Show Gist options
  • Save enBonnet/09e4468ee5af154dada369b726edd62a to your computer and use it in GitHub Desktop.
Save enBonnet/09e4468ee5af154dada369b726edd62a to your computer and use it in GitHub Desktop.
Microsoft LifeCam Studio Optomizer script
#!/bin/bash
CAMERA_DEV="/dev/video2"
# Function to apply settings
apply_settings() {
echo "Applying optimal settings for Microsoft LifeCam Studio..."
# Set resolution to 1080p
v4l2-ctl --device=$CAMERA_DEV --set-fmt-video=width=1920,height=1080,pixelformat=MJPG
# Base settings
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=133
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=7
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=120
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_automatic=1
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=power_line_frequency=2
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=35
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=1
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=auto_exposure=3
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=focus_automatic_continuous=1
echo "Settings applied successfully!"
}
# Function to show current settings
show_settings() {
echo "Current LifeCam Studio settings:"
v4l2-ctl --device=$CAMERA_DEV --list-ctrls
}
# Function to create a preset
create_preset() {
echo "Select lighting preset:"
echo "Bright Room Presets:"
echo "1. Balanced Bright (reduces red/orange tint)"
echo "2. Cool Bright (stronger red/orange compensation)"
echo "3. Soft Bright (slightly dimmed for yellow light)"
echo "4. Natural Bright (minimal color correction)"
echo "5. Vivid Bright (enhanced clarity)"
echo ""
echo "Low Light Presets:"
echo "6. Balanced Low Light"
echo "7. Warm Low Light"
echo "8. Sharp Low Light"
echo "9. Soft Low Light"
echo "10. Natural Low Light"
read -p "Select preset (1-10): " preset_choice
# Disable auto white balance for manual adjustments
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_automatic=0
case $preset_choice in
1) # Balanced Bright - reduces red/orange tint
echo "Applying Balanced Bright settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=120
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=6
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=100 # Reduced saturation
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4800 # Cooler to combat yellow
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=30
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
2) # Cool Bright - stronger red/orange compensation
echo "Applying Cool Bright settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=115
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=5
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=90 # Further reduced saturation
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=5200 # Even cooler
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=25
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
3) # Soft Bright - slightly dimmed for yellow light
echo "Applying Soft Bright settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=110
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=4
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=95
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4600
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=20
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=1
;;
4) # Natural Bright - minimal color correction
echo "Applying Natural Bright settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=125
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=5
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=110
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4200
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=30
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
5) # Vivid Bright - enhanced clarity
echo "Applying Vivid Bright settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=130
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=7
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=105
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4700
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=40
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
6) # Balanced Low Light
echo "Applying Balanced Low Light settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=150
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=8
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=120
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4300
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=25
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
7) # Warm Low Light
echo "Applying Warm Low Light settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=160
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=7
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=110
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4000
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=20
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
8) # Sharp Low Light
echo "Applying Sharp Low Light settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=155
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=9
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=130
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4500
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=45
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
9) # Soft Low Light
echo "Applying Soft Low Light settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=145
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=6
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=100
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4200
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=15
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
10) # Natural Low Light
echo "Applying Natural Low Light settings..."
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=brightness=140
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=contrast=7
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=saturation=115
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=white_balance_temperature=4100
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=sharpness=30
v4l2-ctl --device=$CAMERA_DEV --set-ctrl=backlight_compensation=0
;;
*) echo "Invalid choice. Using default settings." ;;
esac
# Show applied settings
echo -e "\nApplied settings:"
show_settings
}
# Function to test the camera
test_camera() {
if ! command -v ffplay &> /dev/null; then
echo "Installing ffmpeg..."
sudo apt-get update
sudo apt-get install -y ffmpeg
fi
echo "Opening camera preview (press Q to exit)..."
ffplay -f video4linux2 -framerate 30 -video_size 1920x1080 -i $CAMERA_DEV
}
# Main menu
while true; do
echo -e "\nMicrosoft LifeCam Studio Optimizer"
echo "--------------------------------"
echo "1. Show current settings"
echo "2. Apply lighting presets"
echo "3. Test camera"
echo "4. Exit"
read -p "Select an option (1-4): " choice
case $choice in
1) show_settings ;;
2) create_preset ;;
3) test_camera ;;
4) exit 0 ;;
*) echo "Invalid option" ;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment