Musepack Forums

Musepack Forums (
-   Tech (
-   -   Error when piping WAV from ffmpeg to musepack mpcenc.exe (

doppletune 17 February 2016 07:02 pm

Error when piping WAV from ffmpeg to musepack mpcenc.exe
I am getting an error message in mpcenc, "WAVE file has incorrect header", when input from stdin coming from ffmpeg.

This is running on a Windows Vista machine, under cygwin, using the current versions of musepack (MPC Encoder 1.30.0) and ffmpeg (N-78410-g588e2e3 / in other words, downloaded yesterday).

I am ripping audiobook CDs; then using ffmpeg to downmix to mono; and piping the 44.1 kHz mono WAV output to mpcenc:

ffmpeg.exe -i d01\ 11.wav -ac 1 -f wav pipe: | mpcenc.exe --quality 0.8 - d01\ 11.mpc

The errors:
WAVE file has incorrect header: header: 62519.262 s, contents: 191.893 s
WAVE file has incorrect header: header: 191.893 s, contents: 191.893 s
WAVE file has incorrect header: header: 191.893 s, contents: 191.893 s

mpcenc.exe gives these errors, but still produces a usable .mpc file. The source example file above is 3m:11S, so the "contents:" parts of the error messages show the correct duration.

The same error messages appear if I pipe the output of ffmpeg to stdout and cat that output to a new WAV file on disk, then use that WAV file as input for mpcenc. However, if I output from ffmpeg to a disk-based WAV file (that is, without using stdout), then that file does not produce errors in mpcenc.

In each case, the WAV file outputs from ffmpeg play properly in Winamp and Media Player Classic.

r2d 19 February 2016 09:21 pm

This error is (almost) normal. ffmpeg is sending the wave header with a very high number of samples, as if it didn't know the real file length. It is probably doing the same thing with a file output, but it rewrite the file header when closing it with the real number of samples written. But it is not possible to rewrite the header with a pipe.

doppletune 20 February 2016 10:39 pm

Thanks, that was what I had guessed, including the "(almost) normal" description of the error.

If FFMPEG outputs a WAV header with the incorrect duration, this looks like a bug with FFMPEG (because its input is a file with known duration). Then Musepack is correctly reading incorrect input data and producing error messages.

Is there a reason for mpcenc producing _two_ error messages? The first makes sense, with the large duration that disagrees with the duration of the contents. The second message is nonsensical. For example:
"WAVE file has incorrect header: header: 3119.752 s, contents: 3119.752 s"

doppletune 22 February 2016 12:49 am

I discovered that this is a well-known problem with output from ffmpeg to stdout. I would like to suggest an option for mpcenc, which is a --ignorelength flag. This informs the encoder to disregard the "length" field in the header of the input WAV file. Apparently some codecs when piping to streams will write zero for length, and others write 0xfff.... to represent infinity. These are meant as flags or placeholders to represent unknown duration. So an encoder that receives WAV data like this could have an option to disregard the fictional duration in the input WAV header, then figure out the real duration based on actual data.

This is what is discussed in the following thread, regarding two other encoders (qaac and lossywav) handling input from a pipe from ffmpeg:,103191.0.html

I think it is worthwhile having this option, as WAV is the expected intermediate format that gets piped from one codec to another.

All times are GMT. The time now is 03:42 am.

Powered by vBulletin® Version 3.8.11 Beta 2
Copyright ©2000 - 2021, vBulletin Solutions Inc.