HydrogenAudio

Lossless Audio Compression => FLAC => Topic started by: HisDudeness on 2015-03-28 10:09:07

Title: --ignore-chunk-size and non-zero 'data' chunk size
Post by: HisDudeness on 2015-03-28 10:09:07
Hi everyone! I use Recforge II to record my university's lectures (it records to WAV), then I convert to FLAC and quality 0 Mp3 to upload the files to my cloud.

Having to do this everyday as my phone space always gets low, I autmated it via a script, which is as follows:

Quote
#!/bin/bash
for f in *.wav; do
flac -8 --ignore-chunk-size "$f"
lame -V 0 "$f"
rm "$f"
done


I need this script not only because it's annoying to repeat manually for each folder (every exam has a separate folder) and both formats, but also because I need to save space on my PC: after converting each WAV to both formats, I delete it before converting the next one.

So, I appended --ignore-chunk-size to avoid the file being deleted without being converted, as sometimes Recforge II screws up and I find myself with a WAV having a 'data' chunk size of 0. I don't have much time to learn how to add a control sequence.

Long story short: every time, flac appends this warning:

Quote
WARNING: 'data' chunk has non-zero size, using --ignore-chunk-sizes is probably a bad idea


My question is: how is it a bad idea? What happens, and why flac advices me not to use that option on a regular file?

Thanks, have a great day!
Title: --ignore-chunk-size and non-zero 'data' chunk size
Post by: Octocontrabass on 2015-03-28 16:13:46
WAV files (and other RIFF formats) are divided into chunks, each with a length to tell the program reading it where one chunk ends and the next begins.

If you tell flac to ignore the length, it will assume everything following the start of the data chunk is audio, even if it's not.

It sounds like it's not a problem, because all of the WAV files you're using have nothing after the data chunk. However, WAV files with additional chunks after the data chunk do exist. If you encode one of those with --ignore-chunk-size, you'll get a bunch of noise after the audio ends.
Title: --ignore-chunk-size and non-zero 'data' chunk size
Post by: lothario15 on 2015-03-30 18:30:34
So, I appended --ignore-chunk-size to avoid the file being deleted without being converted, as sometimes Recforge II screws up and I find myself with a WAV having a 'data' chunk size of 0. I don't have much time to learn how to add a control sequence.


You're using the BASH shell so you don't need to append --ignore-chunk-size to avoid the file being deleted.  In this instance you should use the ampersand.  A single ampersand allows commands to be executed concurrently, while double ampersand allows a command to be executed only where the previous command had been completed.

Your script currently has three sequential stages; first, it encodes to flac level 8, when this is finished (successfully or not) it encodes to lame mp3, then finally removes the wav file:
Code: [Select]
#!/bin/bash
for f in *.wav; do
flac -8 --ignore-chunk-size "$f"
lame -V 0 "$f"
rm "$f"
done

Using ampersands would make it more efficient, as well as preventing deletion when Recforge has screwed up.  The following has two stages; it encodes to flac and mp3 concurrently then deletes the wav ONLY IF the encodes have been completed succesfully:
Code: [Select]
#!/bin/bash
for f in *.wav; do
flac -8 "$f" & lame -V 0 "$f" && rm "$f";
done