lordmulder / DynamicAudioNormalizer

Dynamic Audio Normalizer
Other
251 stars 36 forks source link

Feature request: wav output to stdout #23

Closed tnt closed 3 years ago

tnt commented 3 years ago

I don't know how hard or easy this would be to implement - I suppose it's not quite extensive.

I have asked a question on Stackoverflow regarding this issue.

When I just want to directly pipe the output into e.g. lame the file-format would convey lots of information about the audio data like sampling frequency, etc. that are not in the stdout stream so that I not only had to set lots of options but of course first had to figure out these details which makes it quite inconvenient.

When executing

 DynamicAudioNormalizerCLI.bin -i 03-1-03.mp3 -o - -t wav | lame ....

I get the error

Failed to open file for writing: "Error : this file format does not support pipe write."

Maybe it would work with another format but - as far as I can see - it is not documented which formats the --output-fmt option accepts.


From the mentioned Stackoverflow question:

DynamicAudioNormalizerCLI.bin -i 03-1-03.mp3 -o - | lame -V 8 - 03-1-03_1.mp3
...
Warning: unsupported audio format
Can't init infile '-'

When I do essentially the same but direct the output of the normalizer to a file and then cat the file into lame it works.

DynamicAudioNormalizerCLI.bin -i 03-1-03.mp3 -o - > 03-1-03.wav
cat 03-1-03.wav | lame -V 8 - 03-1-03_1.mp3
lordmulder commented 3 years ago

Hello,

if you don't specify the output file format explicitly, then DynamicAudioNormalizer will try to guess the format from the file name. The default output format for "piped" output is raw PCM format, as that is the common way to pass audio data over a pipe.

LAME needs extra options for this. Please see the section Input options for raw PCM here: https://svn.code.sf.net/p/lame/svn/trunk/lame/USAGE

Note that sending WAVE files over a pipe is not really possible, because WAVE is a file-based format. A WAVE file is composed of so-called "chunks" and each chunk begins with a header containing the type and the total size of the chunk. Obviously, when writing out the WAVE header, you cannot know the final total size yet! This is solved in practice by writing a fake/dummy (placeholder) WAVE header first, then writing all the data, and, at the very the end - when the total size is known - seek back to the beginning of the file and overwrite the fake/dummy header with the actual WAVE header. Obviously, you cannot do this with a pipe 😏

The AU format, for example, is suitable for streaming over a pipe. But I don't know whether LAME can read that (from a pipe).

Regards MuldeR


BTW, encoding with LAME is possible via FFmpeg:

DynamicAudioNormalizerCLI.exe -i "input.wav" -o - |
  ffmpeg.exe -loglevel quiet -f s16le -ar 44100 -ac 2 -i - -c:a libmp3lame -qscale:a 2 "output.mp3"
tnt commented 3 years ago

Thanks for the thorough explanation. That file size thing makes it of course impossible. So it looks I'll actually have to put up with ffmpeg. Thank you!