MPV script that adds smooth audio fade effects when pausing/unpausing
Do the immediate audio cut on pausing media bugs you? Frustrate no more -> I fade the audio on your music and video experience.
I'm an MPV Script that adds a fade-in and fade-out effect when pausing or unpausing music/video playback.
Features logarithmic and linear volume curves, MPRIS "integration" support, and robust state management for seamless operation with external pause controls.
- Smooth Audio Transitions: Configurable fade-in/fade-out effects eliminate abrupt audio cuts
- Logarithmic & Linear Curves: Choose between natural-sounding logarithmic fading or constant-rate linear fading
- MPRIS Integration: Works seamlessly with external pause/unpause triggers (media keys, system controls, remote apps)
- Zero Performance Impact: Lightweight Lua implementation with negligible CPU usage
- Highly Configurable: Fine-tune fade durations, step counts, and curve types
- Debug Mode: Built-in logging for troubleshooting
- Position Preservation: Maintains exact playback position through pause cycles
By default, MPV (and most media players) instantly cuts audio when you pause, creating a jarring listening experience. This is especially noticeable when:
- Pausing music or podcasts mid-phrase
- Using media keys or MPRIS controls
- Quickly toggling pause during video playback
gradual-pause intercepts pause/unpause events and applies smooth volume fading:
- Fade-out: Gradually reduces volume to 0 before pausing (default: 0.45s)
- Fade-in: Gradually increases volume from 0 after unpausing (default: 0.3s)
- Smart handling: Works with keyboard shortcuts, media keys, and external controls
Add to your Home Manager configuration:
programs.mpv = {
enable = true;
scripts = [ pkgs.mpvScripts.gradual-pause ];
};Then rebuild your configuration:
home-manager switchAdd to your NixOS configuration:
environment.systemPackages = with pkgs; [
(mpv.override {
scripts = [ mpvScripts.gradual-pause ];
})
];Then rebuild:
sudo nixos-rebuild switch-
Download the script:
mkdir -p ~/.config/mpv/scripts curl -o ~/.config/mpv/scripts/gradual_pause.lua \ https://raw.githubusercontent.com/gui-wf/mpv-gradual-pause/main/scripts/gradual_pause.lua
-
Download default configuration (optional):
mkdir -p ~/.config/mpv/script-opts curl -o ~/.config/mpv/script-opts/gradual_pause.conf \ https://raw.githubusercontent.com/gui-wf/mpv-gradual-pause/main/script-opts/gradual_pause.conf
-
Restart MPV - the script will load automatically
# Package pending AUR submission# Package pending Homebrew submissionThe script works out-of-the-box with sensible defaults. To customize behavior, create a configuration file:
# Create config directory
mkdir -p ~/.config/mpv/script-opts
# Edit configuration
nano ~/.config/mpv/script-opts/gradual_pause.conf| Option | Type | Default | Range | Description |
|---|---|---|---|---|
fade_out_duration |
float | 0.45 |
0.0 - 5.0 | Fade-out duration in seconds when pausing |
fade_in_duration |
float | 0.3 |
0.0 - 5.0 | Fade-in duration in seconds when unpausing |
steps |
integer | 12 |
1 - 100 | Number of volume steps (higher = smoother) |
logarithmic_fade |
boolean | yes |
yes/no | Use logarithmic curve (more natural) vs linear |
debug_mode |
boolean | no |
yes/no | Enable debug logging to MPV console |
fade_out_duration=0.2
fade_in_duration=0.15steps=24
fade_out_duration=0.6
fade_in_duration=0.4logarithmic_fade=nodebug_mode=yesThen press ` (backtick) in MPV to open the console and view debug messages.
You can override settings per-session using --script-opts:
mpv --script-opts=gradual_pause-fade_out_duration=1.0,gradual_pause-debug_mode=yes video.mp4Once installed, the script works transparently:
- Press
Spaceorpto pause → audio fades out smoothly - Press
Spaceorpagain to unpause → audio fades in smoothly - Use media keys (play/pause) → same smooth behavior
- External controls (smartphone remotes, MPRIS) → same smooth behavior
The script intercepts pause events from any source and applies fading automatically.
- Key Binding Override: Intercepts
spaceandpkeys usingadd_forced_key_binding - Property Observation: Monitors the
pauseproperty for external changes (MPRIS, media keys) - Volume Manipulation: Uses periodic timers to step volume in calculated increments
- State Management: Prevents conflicts when multiple pause events occur simultaneously
- Position Preservation: Saves and restores exact playback position to maintain continuity
Logarithmic Fade (default):
- Starts fast, ends slow (fade-out) / Starts slow, ends fast (fade-in)
- Perceived as more "natural" to human hearing
- Mimics professional audio engineering techniques
Linear Fade:
- Constant volume change rate
- Simpler, more predictable behavior
- Slightly more "mechanical" feel
- CPU Usage: <0.1% on modern systems
- Memory: ~50KB RAM footprint
- Latency: No noticeable delay (fade starts immediately)
Check if MPV detects the script:
mpv --msg-level=all=debug video.mp4 2>&1 | grep gradualYou should see: [gradual_pause] gradual_pause v1.0.0 loaded successfully
Common issues:
- Ensure script is in
~/.config/mpv/scripts/(not~/.mpv/scripts/) - Verify file is named
gradual_pause.lua(not.txtor other extension) - Check file permissions:
chmod +x ~/.config/mpv/scripts/gradual_pause.lua
-
Enable debug mode:
# ~/.config/mpv/script-opts/gradual_pause.conf debug_mode=yes
-
Watch the console (press
`in MPV):- Look for
Starting fade-out sequence/Starting fade-in sequence - Check for error messages
- Look for
-
Test with minimal config:
mpv --no-config --script=~/.config/mpv/scripts/gradual_pause.lua video.mp4
If you have other scripts that modify pause behavior, they may conflict. Try:
- Temporarily disable other scripts
- Load gradual-pause last (rename to
zzz_gradual_pause.luato load last alphabetically) - Check script compatibility in debug mode
The script restores original volume after fading. If volume changes persist:
- Check for volume normalization filters (
--af=dynaudnorm) - Verify other scripts aren't modifying volume
- Ensure MPV's
volume-maxisn't capping your volume
- Minimum: MPV 0.35.0 (released 2023)
- Recommended: MPV 0.38.0+ (latest stable)
- Tested: 0.35.x, 0.36.x, 0.37.x, 0.38.x, 0.39.x (dev)
- Linux: Full support (PulseAudio, PipeWire, ALSA)
- macOS: Full support (CoreAudio)
- Windows: Full support (WASAPI)
- BSD: Untested but should work
Works with all MPV audio output drivers (--ao):
pulse(PulseAudio)pipewire(PipeWire)alsa(ALSA)coreaudio(macOS)wasapi(Windows)
Compatible with:
mpv-mpris(MPRIS integration)autoload(playlist auto-loading)sponsorblock(YouTube sponsor skipping)quality-menu(video quality selection)
Potential conflicts:
- Custom pause/volume scripts may interfere
- Scripts that override
space/pkeybindings
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
When reporting issues, please include:
- MPV version (
mpv --version) - Operating system and audio backend
- Script configuration (
~/.config/mpv/script-opts/gradual_pause.conf) - Debug log output (with
debug_mode=yes) - Steps to reproduce
Open an issue with the enhancement label and describe:
- Use case: What problem does this solve?
- Proposed solution: How should it work?
- Alternatives: What else have you tried?
# Clone repository
git clone https://github.com/gui-wf/mpv-gradual-pause.git
cd mpv-gradual-pause
# Test script directly
mpv --script=./scripts/gradual_pause.lua --script-opts=gradual_pause-debug_mode=yes test-video.mp4
# Build Nix package locally
nix-build -E 'with import <nixpkgs> {}; callPackage ./nix/package.nix {}'# Test with different fade durations
for duration in 0.1 0.3 0.5 1.0; do
echo "Testing fade duration: $duration"
mpv --script-opts=gradual_pause-fade_out_duration=$duration,gradual_pause-debug_mode=yes video.mp4
doneSee CHANGELOG.md for version history and release notes.
This project is licensed under the MIT License - see the LICENSE file for details.
Guilherme Fontes (@gui-wf)
- MPV development team for the excellent media player and Lua scripting API
- NixOS community for packaging infrastructure and review
- Users who provided feedback and testing
- mpv - The media player this script enhances
- mpv-mpris - MPRIS integration for MPV
- mpv user scripts wiki - Collection of MPV scripts
Star this repository if you find it useful! Contributions and feedback are always welcome.