Why do these two ffmpeg files differ (piping vs file output)?

Viewed 370

I have a source sound audio.mp3 and I want to convert it into audio.aiff. When I do

ffmpeg -i audio.mp3 -acodec pcm_s16le -ac 1 -ar 44100 -vn audio.aiff

I get output a file tim_tum.aiff exactly as I expect it which is playable. However, what I found is that when I do

ffmpeg -i audio.mp3 -acodec pcm_s16le -ac 1 -ar 44100 -vn -f aiff pipe:1 > audio_pipe.aiff

I get an audio_pipe.aiff file which is unplayable and is different from the original audio.aiff file, as evidenced by

$ diff audio.aiff audio_pipe.aiff
Binary files audio.aiff and audio_pipe.aiff differ

I would expect both files to be identical and cannot figure out why they would come out differently, but most importantly, why is one file playable while the other isn't?

1 Answers

By making a comparision on the header of these two AIFF encoded files, you can observe that they differ at 3-4 columns in the first line

xxd audio.aiff | head

not piped

00000000: 464f 524d 0199 9040 4149 4643 4656 4552  FORM...@AIFCFVER

piped

00000000: 464f 524d 0000 0000 4149 4643 4656 4552  FORM....AIFCFVER

The data at this position according to AIFF's file specification should be ckDataSize, which specifies the size of the data portion of the chunk. Since the piped version had a value of zero, my best guess is that by using pipe, ffmpeg cannot properly determine the data size of the output stream beforehand, therefore it was left blank, leaving the encoded file somewhat malformed.

Several tools like flac can work around these malformed header by using options such as --ignore-chunk-sizes to correctly read the file regardless, however I would probably suggest to avoid using pipes during media file conversion whenever possible.

Related