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.
$ timeout 10s mpv --no-config "http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk" --ao=pcm --ao-pcm-file=test.wav
$ mpv test.wav
$ sudo pacman -U /var/cache/pacman/pkg/mpv-1:0.32.0-6-x86_64.pkg.tar.zst
The output audio files can be played properly.
The output audio files are broken.
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
None.
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.
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;tostate->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'