# Video Screensaver Tweaking Guide

This guide provides instructions for customizing and tweaking your video screensaver setup.

## Table of Contents

1. [Changing Timeout Settings](#changing-timeout-settings)
2. [Video Playback Options](#video-playback-options)
3. [Appearance Customization](#appearance-customization)
4. [Adding Multiple Videos](#adding-multiple-videos)
5. [Advanced Options](#advanced-options)

## Changing Timeout Settings

### Adjust Inactivity Timeout

The default setting activates the screensaver after 1 minute of inactivity. To change this:

```bash
# Edit the xscreensaver configuration file
nano ~/.xscreensaver

# Look for the line that starts with "timeout:" and change the value
# Format is hours:minutes:seconds
# Examples:
# timeout:    0:01:00    # 1 minute
# timeout:    0:05:00    # 5 minutes
# timeout:    0:30:00    # 30 minutes

# Save the file (Ctrl+O, Enter, Ctrl+X)
```

### Apply Changes

```bash
# Restart xscreensaver to apply the changes
systemctl --user restart xscreensaver.service
```

## Video Playback Options

### Video Quality and Performance

Edit the video playback script to adjust quality and performance:

```bash
# Edit the video playback script
nano ~/screensaver/play_video.sh
```

#### Performance Options

Add these options to the mplayer command for better performance:

- `-lavdopts fast:skiploopfilter=all` - Faster decoding, might reduce quality
- `-vo gl` - Try different video output methods if you have display issues
- `-cache 8192` - Increase cache size for smoother playback
- `-framedrop` - Drop frames to maintain sync on slower systems

#### Quality Options

For better quality (may affect performance):

- `-vo gl:swapinterval=1` - Enables vsync for smoother playback
- `-demuxer lavf` - Alternative demuxer that may work better with some files
- `-noborder` - Removes window borders (already using fullscreen)

### Audio Settings

Control volume and audio options:

```bash
# Add these options to the mplayer command line:
-af volume=10 # Increase volume by 10dB
-volume 75    # Set volume to 75%
-mute         # Start muted
-nosound      # Disable sound completely
```

## Appearance Customization

### Fade Effects

To control fade in/out effects, edit the `.xscreensaver` file:

```
# Enable/disable fade
fade:       True  # or False to disable

# Set fade duration
fadeSeconds:    0:00:03  # Format is hours:minutes:seconds
```

### Screen Blanking

If you want a brief blank screen before the video starts:

```bash
# Edit play_video.sh and add a sleep command before mplayer starts
sleep 1  # Add a 1-second delay
```

## Adding Multiple Videos

To play a different video each time or cycle through videos:

1. Create a directory for your videos:
   ```bash
   mkdir -p ~/screensaver/videos
   ```

2. Copy your videos there:
   ```bash
   cp ~/video1.mp4 ~/video2.mp4 ~/screensaver/videos/
   ```

3. Modify the play_video.sh script:
   ```bash
   #!/bin/bash

   # Directory containing videos
   VIDEO_DIR="/home/sanman/screensaver/videos"

   # Get a random video file from the directory
   VIDEO_FILES=( "$VIDEO_DIR"/*.mp4 )
   RANDOM_VIDEO="${VIDEO_FILES[RANDOM % ${#VIDEO_FILES[@]}]}"

   # Function to clean up when receiving termination signal
   cleanup() {
       pkill -P $$ mplayer
       exit 0
   }

   # Set up signal handling
   trap cleanup TERM INT HUP QUIT EXIT

   # Play the random video
   mplayer -fs -loop 0 -quiet -nolirc -noconfig all "$RANDOM_VIDEO" &

   # Wait for mplayer to exit or for signals
   wait $!
   ```

## Advanced Options

### Watchdog Sensitivity

To adjust how often the watchdog checks the screensaver status:

```bash
# Edit the watchdog script
nano ~/screensaver/watchdog.sh

# Change the CHECK_INTERVAL value (in seconds)
# Default is 60 seconds
CHECK_INTERVAL=30  # Check every 30 seconds
```

### Display Detection

For multi-monitor setups or custom resolutions:

```bash
# Edit the auto-display-setup script
nano ~/auto-display-setup.sh

# You can specify exact resolutions for specific outputs
# Example: Force HDMI-2 to 1080p
# xrandr --output HDMI-2 --mode 1920x1080 --primary
```

### Disable Mouse Cursor

For a cleaner screensaver experience:

```bash
# Install unclutter if not already installed
sudo apt-get install unclutter

# Add to autostart
echo '[Desktop Entry]
Type=Application
Name=Unclutter
Exec=unclutter -idle 1
Hidden=false
X-GNOME-Autostart-enabled=true' > ~/.config/autostart/unclutter.desktop
```

## Troubleshooting Tweaks

### If Video Doesn't Play Smoothly

Try different video formats:
```bash
# Convert your video to a more efficient format
sudo apt-get install ffmpeg
ffmpeg -i Parts_Portal_Refresh_Video.mp4 -vcodec libx264 -crf 23 -preset medium -acodec aac -strict -2 ~/screensaver/optimized_video.mp4
```

Then update your play_video.sh to use the optimized video.

### System Resource Usage

If the screensaver is using too many resources:

```bash
# Edit play_video.sh to add resource constraints
# Add before the mplayer command:
nice -n 19 mplayer # Lower CPU priority
```

---

For any further customization needs, consult the MPlayer, XScreenSaver or systemd documentation.
