Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an M4A file which is also converted to a FLAC file. I'd like to see if the conversion is lossless, namely, whether the output to pcm from M4A is exactly identical to the one from FLAC decoding.

I assume there's a way to use FFmpeg or Libav to produce some "raw" output and compare them?

share|improve this question
    
See also: superuser.com/questions/136514/… –  Mechanical snail Jan 10 '13 at 21:29
add comment

2 Answers

up vote 3 down vote accepted

I'd try converting them both to WAV and comparing their checksums.

ffmpeg -i file1.m4a file1.wav
ffmpeg -i file2.flac file2.wav
md5sum file1.wav
md5sum file2.wav
rm file?.wav

Compare the md5s produced. If they match, congratulations! Your files contain the same data. If they don't match, post the output of those commands here, and I'll look. Potentially there is a bitrate difference or something (there ought not to be... but there may be, I don't know.)

Note that the ffmpegs will generate comparatively large intermediate files.

share|improve this answer
    
It seems that the output size by ffmpeg -y -i in.m4a -ac 2 -ar 48000 -acodec flac out.flac differs from that of ffmpeg -y -i in.m4a -acodec flac out.flac. I have no idea what's going on when converting as well as the subtle paramters. Could you explain a little bit? –  Determinant Jan 10 '13 at 1:39
    
With the latter command, md5sum is the same. –  Determinant Jan 10 '13 at 1:42
    
And the former command is copied from a forum, I guess the file size has something to do with the number "48000", right? –  Determinant Jan 10 '13 at 1:45
1  
Yup. See, the -ar 48000 says to use 48000 samples per second. If that is different than the source's number of samples per second, ffmpeg interpolates (sticks additional values in between), and that makes the resulting file different. If you just let ffmpeg autodetect everthing, it tries to change as little as it can. –  thirtythreeforty Jan 10 '13 at 1:58
5  
@ymfoi WAV is not a raw file standard per se. WAV files are just containers and therefore can contain different audio codecs. In this case it will be PCM audio (pulse-code modulated), which is lossless. But there can also be compressed codecs inside a WAV file: en.wikipedia.org/wiki/Wav#WAV_file_compression_codecs_compared –  slhck Jan 10 '13 at 7:51
show 9 more comments

You can use the md5 muxer in ffmpeg to compute and print the MD5 hash of all input audio (and video) frames without the need for intermediate files. In this example the flac was created from the mp3 (lossy to lossless usually not a recommended procedure, but this is just a demonstration).

$ ffmpeg -i left_right.mp3 -map 0:a -f md5 - 2>/dev/null
MD5=a34bfd9245ad6d69eddcb92035219044

$ ffmpeg -i left_right.flac -map 0:a -f md5 - 2>/dev/null
MD5=a34bfd9245ad6d69eddcb92035219044

There is also the framemd5 muxer to compute and print the MD5 hash for each audio (and video) packet.

Also see framemd5 Intro and HowTo.

share|improve this answer
2  
+1 This is good also because it completely avoids the issue of metadata in the uncompressed file, which otherwise could make identical-audio files differ. –  Michael Kjörling Jan 10 '13 at 21:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.