mpv
mpv copied to clipboard
Muting is delayed with ao_avfoundation
mpv Information
mpv 0.39.0 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
libplacebo version: v7.349.0
FFmpeg version: 7.1
FFmpeg library versions:
libavcodec 61.3.100 (runtime 61.19.100)
libavdevice 61.1.100 (runtime 61.3.100)
libavfilter 10.1.100 (runtime 10.4.100)
libavformat 61.1.100 (runtime 61.7.100)
libavutil 59.8.100 (runtime 59.39.100)
libswresample 5.1.100 (runtime 5.3.100)
libswscale 8.1.100 (runtime 8.3.100)
Other Information
- macOS version: Sequoia 15.0.1
- Source of mpv: Homebrew
- Introduced in version: 0.39.0
Reproduction Steps
Play any video with --no-config --ao=avfoundation and toggle mute (either by using the keybind or using the menu bar).
Expected Behavior
Same behaviour as ao_coreaudio, which mutes as soon as toggled.
Actual Behavior
It takes at least a second to actually mute the audio.
Log File
Sample Files
No response
I carefully read all instruction and confirm that I did the following:
- [X] I tested with the latest mpv version to validate that the issue is not already fixed.
- [X] I provided all required information including system and mpv version.
- [X] I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of
--log-file=output.txt. - [X] I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
- [X] I attached the full, untruncated log file.
- [X] I attached the backtrace in the case of a crash.
@ruihe774 mentioning you, in the case you didn't see this issue.
No easy fix I'm afraid. Surely we can clear ao buffer on softvol mute:
diff --git a/player/audio.c b/player/audio.c
index e86547c30e..229458da4d 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -186,6 +186,11 @@ void audio_update_volume(struct MPContext *mpctx)
gain = 0.0;
ao_set_gain(ao_c->ao, gain);
+
+ if (opts->softvol_mute) {
+ ao_reset(ao_c->ao);
+ ao_start(ao_c->ao);
+ }
}
// Call this if opts->playback_speed or mpctx->speed_factor_* change.
But this it bound to cause some AV desync.
FWIW this is not a problem specific to ao_avfoundation; all pull-based AOs have this issue if they are used with large device buffers.
For now, a simple workaround is not to use softvol mute but to use ao mute instead; ao_avfoundation works well with ao volume and ao mute with no issues that were encountered in other AOs; I don't think there are reasons not to use them. Simply put this config into your input.conf (or put some similar config into other places if you are not using keybindings to toggle mute):
m cycle ao-mute
# if you also want to use ao volume, add and uncomment these as well:
# WHEEL_UP add ao-volume 2
# WHEEL_DOWN add ao-volume -2
Some AOs (e.g. pipewire) remember ao volume and ao mute even after mpv quits. If you want to prevent this behavior, you can use the following lua script. This does not apply to ao_avfoundation as it does not remember.
mp.register_event("audio-reconfig", function()
mp.set_property_number("ao-volume", 100)
mp.set_property_bool("ao-mute", false)
end)
@MarioMastr @low-batt I've added a new option --avfoundation-buffer in #14058. Setting it to a lower value can make the AO reacts quicker; though lower value may lead to underruns. You can have a try.
Some AOs (e.g. pipewire) remember ao volume and ao mute even after mpv quits.
Nitpick: this is not done by mpv itself but by the pipewire session manager (most likely wireplumber) If this behavior is undesired it would be cleaner to disable it there.