mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.17k stars 2.89k forks source link

Muting is delayed with ao_avfoundation #15014

Open MarioMastr opened 1 week ago

MarioMastr commented 1 week ago

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

output.txt

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

Akemi commented 1 week ago

@ruihe774 mentioning you, in the case you didn't see this issue.

ruihe774 commented 1 week ago

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)