Mpv: PCM audio output produce broken file after v0.33.0 update

Created on 25 Nov 2020  ·  6Comments  ·  Source: mpv-player/mpv

I'm using mpv to record audio streaming by specifying --ao=pcm --ao-pcm-file=test.wav options. However, the output files can't be played properly after v0.33.0 update.

Important Information

  • mpv version: v0.33.0
  • Linux Distribution and Version: Arch Linux 5.9.10-arch1-1
  • Source of the mpv binary: Arch repository
  • If known which version of mpv introduced the problem: v0.33.0
  • Window Manager and version: sway version 1.5-96578aa9 (Oct 31 2020, branch 'master')
  • GPU driver and version: 00:02.0 VGA compatible controller: Intel Corporation 3rd Gen Core processor Graphics Controller (rev 09)
  • Possible screenshot or video of visual glitches: None

Reproduction steps

  1. Execute the following commnad to record audio for 10 seconds
$ timeout 10s mpv --no-config "http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk" --ao=pcm --ao-pcm-file=test.wav
  1. Play the output file, but audio is broken
$ mpv test.wav
  1. By downgrading mpv to the previous version, the output audio file works fine.
$ sudo pacman -U /var/cache/pacman/pkg/mpv-1:0.32.0-6-x86_64.pkg.tar.zst

Expected behavior

The output audio files can be played properly.

Actual behavior

The output audio files are broken.

Log file

mpv_output.log

Log generation command

$ timeout 10s mpv --no-config "http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk" --ao=pcm --ao-pcm-file=test.wav --log-file=mpv_output.log

Sample files

None.

linux

Most helpful comment

Bisected to b74c09efbf7c6969fc053265f72cc0501b840ce1. (@biopsin v0.32.0 works fine for me, but your sample sounds like what I get from b74c09efbf7c6969fc053265f72cc0501b840ce1 forward.)

On a hunch, I tried changed state->free_samples = ao->device_buffer; to state->free_samples = 1; in ao_pcm.c, matching wm4's change in ao_lavc.c. It seems to work. I want to take a few minutes to understand why before making a PR. Edit: That makes it write one sample at a time, which would be terrible for performance. lavc writes frame at a time and has special logic. I wasn't able to figure out the real problem yet. Gonna look more later into fixing it properly. Something to do with it being an untimed ao?

Also, as a workaround -- or maybe a better solution anyway? -- encoding mode seems to work: mpv --o=test.wav 'http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk'

All 6 comments

Tested it on 0.32 too and first 3 sec it sounds fine, but then everything after gets bitcrushed..
removing --ao=pcm it sound fine tho
wav file sample @ https://tknk.io/kFbU (link expires in 1 month)

Bisected to b74c09efbf7c6969fc053265f72cc0501b840ce1. (@biopsin v0.32.0 works fine for me, but your sample sounds like what I get from b74c09efbf7c6969fc053265f72cc0501b840ce1 forward.)

On a hunch, I tried changed state->free_samples = ao->device_buffer; to state->free_samples = 1; in ao_pcm.c, matching wm4's change in ao_lavc.c. It seems to work. I want to take a few minutes to understand why before making a PR. Edit: That makes it write one sample at a time, which would be terrible for performance. lavc writes frame at a time and has special logic. I wasn't able to figure out the real problem yet. Gonna look more later into fixing it properly. Something to do with it being an untimed ao?

Also, as a workaround -- or maybe a better solution anyway? -- encoding mode seems to work: mpv --o=test.wav 'http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk'

@qmega Thank you for the quick reply, indeed the workaround works fine and is a good solution.
I usually just sample audio from loopback, therefore I have never experimentet saving it this way until I read this post and got curious.

@qmega
Wow, I didn't know the option. That works fine in my use case even at mpv 0.33.0.
Thank you for your investigation and suggestion.
I should've read the manual more carefully :).

Hah I actually am on 0.33.0, so that puzzel solved. Must have built it intoxicated and forgot about it, geez..

I can confirm I noticed the same behaviour on my system with mpv 0.33.0: using --ao=pcm --ao-pcm-file=test.wav results in the first seconds of test.wav playing OK, but the rest is significantly corrupted, exactly like in @biopsin sample.

Also thanks @qmega for your investigation.

Was this page helpful?
0 / 5 - 0 ratings