Add comprehensive video playback optimization for smooth performance
Environment variable optimizations: - KIVY_WINDOW='pygame' - Better window backend performance - KIVY_AUDIO='ffpyplayer' - Optimized audio playback - KIVY_GL_BACKEND='gl' - Use OpenGL for better graphics - FFMPEG_THREADS='4' - Multi-threaded video decoding - LIBPLAYER_BUFFER='2048000' - 2MB buffer for smooth playback - SDL_AUDIODRIVER='alsa' - Better audio on Raspberry Pi Kivy configuration optimizations: - multisampling=0 - Disable for better performance - fast_rgba=1 - Enable fast RGBA mode - Stereo audio (channels=2) - Reduced logging overhead (warning level) Video widget enhancements: - FFmpeg buffer optimization (2MB) - Multi-threaded decoding (4 threads) - Ignore index for better seeking - Allow codec fallback - 60 FPS animation delay New video optimization script (.video-optimization.sh): - GPU memory increased to 256MB - Install video codec libraries - Optimize swappiness to 30 (better memory management) - CPU forced to performance mode - Filesystem cache optimization Installation integration: - Runs video optimization automatically on Raspberry Pi - Configures GPU memory, libraries, and system settings - Improves overall video playback smoothness This addresses video stuttering, frame drops, and playback lag by optimizing at multiple levels: environment, application, and system.
This commit is contained in:
61
.video-optimization.sh
Normal file
61
.video-optimization.sh
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
# Video playback optimization script for Raspberry Pi
|
||||
# Improves video smoothness and reduces stuttering
|
||||
|
||||
echo "Optimizing system for smooth video playback..."
|
||||
|
||||
# 1. Increase GPU memory split for better video performance
|
||||
if [ -f /boot/config.txt ]; then
|
||||
echo "Checking GPU memory configuration..."
|
||||
if grep -q "gpu_mem=" /boot/config.txt; then
|
||||
# GPU memory already configured, check if it's sufficient
|
||||
CURRENT_GPU_MEM=$(grep "gpu_mem=" /boot/config.txt | head -1 | cut -d'=' -f2)
|
||||
if [ "$CURRENT_GPU_MEM" -lt 256 ]; then
|
||||
sudo sed -i 's/gpu_mem=.*/gpu_mem=256/' /boot/config.txt
|
||||
echo "✓ GPU memory increased to 256MB for video"
|
||||
fi
|
||||
else
|
||||
# Add GPU memory setting
|
||||
echo "gpu_mem=256" | sudo tee -a /boot/config.txt > /dev/null
|
||||
echo "✓ GPU memory set to 256MB for video"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2. Install video codec support
|
||||
echo "Installing video codec libraries..."
|
||||
sudo apt-get install -y \
|
||||
libva-drm2 \
|
||||
libva2 \
|
||||
libavcodec-extra \
|
||||
libavutil-dev \
|
||||
2>/dev/null || true
|
||||
|
||||
# 3. Optimize swappiness for better memory management
|
||||
echo "Optimizing memory management..."
|
||||
if [ -f /proc/sys/vm/swappiness ]; then
|
||||
CURRENT_SWAP=$(cat /proc/sys/vm/swappiness)
|
||||
if [ "$CURRENT_SWAP" -gt 30 ]; then
|
||||
echo 30 | sudo tee /proc/sys/vm/swappiness > /dev/null
|
||||
echo "vm.swappiness=30" | sudo tee -a /etc/sysctl.conf > /dev/null
|
||||
echo "✓ Swappiness optimized"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 4. Disable CPU frequency scaling for consistent performance
|
||||
echo "Ensuring CPU performance mode..."
|
||||
for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
|
||||
if [ -f "$cpu/cpufreq/scaling_governor" ]; then
|
||||
echo performance | sudo tee "$cpu/cpufreq/scaling_governor" > /dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
echo "✓ CPU set to performance mode"
|
||||
|
||||
# 5. Optimize file system cache
|
||||
echo "Optimizing filesystem cache..."
|
||||
echo 50 | sudo tee /proc/sys/vm/vfs_cache_pressure > /dev/null
|
||||
echo "vm.vfs_cache_pressure=50" | sudo tee -a /etc/sysctl.conf > /dev/null
|
||||
echo "✓ Filesystem cache optimized"
|
||||
|
||||
echo ""
|
||||
echo "✅ Video playback optimization complete!"
|
||||
echo "Note: Some changes require a reboot to take effect."
|
||||
Reference in New Issue
Block a user