Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Problems with ffmpeg piping (Read 7489 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Problems with ffmpeg piping

Hello,
I was trying to create a batch command to easily convert popular lossless file formats (flac, tak, ape, ...) to lossyFLACs.
The plan was to use ffmpeg for the decoding stage - but I failed...

I started to create lossy WAVs first:
Can someone shed some light why this command doesn't work:
Code: [Select]
ffmpeg -i test.flac -f wav - | lossywav -

Error:
Code: [Select]
Could not write header for output file #0 (incorrect codec parameters ?): Error number -22 occurred

While this one works (and produces a "stdin.lossy.wav" output file as expected):
Code: [Select]
flac -d test.flac -c | lossywav -

Maybe it's the way lossyWAV works, because this one is working (though it doesn't make much sense):
Code: [Select]
ffmpeg -i test.flac -f wav - | qaac - -o test.m4a


.sundance.

 

Problems with ffmpeg piping

Reply #1
When piping to stdout, ffmpeg writes zero in size field of data chunk.
Therefore, receiver usually requires option like --ignorelength to read it.

As for qaac, it will automatically falls back into ignore length mode if size field of data chunk is zero. Strictly speaking it may not be spec compliant, but I think it's much likely the case that data is coming from ffmpeg than user actually wants to pass zero length audio to qaac, so I think it's more "convenient" for users.

Problems with ffmpeg piping

Reply #2
So, since lossyWAV hasn't got an option like "ignore-length", is there a solution for ffmpeg to output correct length information?
Or is using a temporary WAV file the only way to go?

Problems with ffmpeg piping

Reply #3
So, since lossyWAV hasn't got an option like "ignore-length", is there a solution for ffmpeg to output correct length information?
Or is using a temporary WAV file the only way to go?

Try something like the following, it seems to work here:
Code: [Select]
ffmpeg -v 0 -i foo.flac -f wav - | qaac --silent -D - -o - | lossywav -

Here, qaac plays a role to convert size field of data chunk coming from ffmpeg to 0xffffffff, which qaac uses as a placeholder when input length is unknown.
Maybe other commands can do this as long as it has --ignorelenth like option, and writes sane size field to the pipe.

Problems with ffmpeg piping

Reply #4
Code: [Select]
ffmpeg.exe -i "lossless.flac" -f wav - | lossyWAV.exe - -I -- | flac.exe --ignore-chunk-sizes -8 -b 512 - -o "lossy.flac"

This works for me.

Problems with ffmpeg piping

Reply #5
Oh, thanks. I should have checked lossywav command line.
-I is shown by --longhelp.

Problems with ffmpeg piping

Reply #6
I'm using lossyWAV v1.3.0 and -I is not shown @ --longhelp.
What version are you guys using?

Problems with ffmpeg piping

Reply #7
In lossyWAV v1.3.0 a zero length file would cause an error. This has been changed in recent beta versions, along with added handling of WAVE64 and RF64 file formats.
lossyWAV -q X -a 4 -s h -A --feedback 2 --limit 15848 --scale 0.5 | FLAC -5 -e -p -b 512 -P=4096 -S- (having set foobar to output 24-bit PCM; scaling by 0.5 gives the ANS headroom to work)

Problems with ffmpeg piping

Reply #8
Thanks Nick, nu774 and CoRoNe for the valuable pointers - will try the latest beta...


Re: Problems with ffmpeg piping

Reply #10
I am trying to pipe M4A to WAV and back to M4A applying SoX equalization during the WAV phase:
Code: [Select]
... | [ffmpeg] -i - -c:a aac -strict -2 -b:a 320k -f adts -
This last part is not working and it may be because I do not know how to specify the stdout file type is M4A.  Is it possible to do so?