I have tons of small flac files, which I need to merge into tons of slightly bigger flac files, while also appending random silence at the beginning of each file. For example, I need to merge: a) 125ms of silence + 01.flac + 02.flac + 03.flac b) 36ms of silence + 03.flac + 01.flac + 02.flac and so on. I gave 2 examples above, but I need to create almost 900 of them. I have a database of what to merge with what and I can output it into 1 big text file, in pretty much any format. So my obvious choice is to go and create a batch file that would execute some kind of command line tool.
Now what I don't know is, which of them to use.
I already tried flac.exe and while it does allow working on multiple files at once, it doesn't merge them, so something like flac.exe -8 -o output.flac 01.flac 02.flac
simply won't work
I can use anything else as long as it doesn't lower the quality. Ability to generate silence would be a big bonus too, because those silences at the beginning are pretty random in length, so for 900 file combinations I have about 125 lenghts of silence.
Turns out it can be done on FLAC, without converting it to WAV.
The contents of my BAT file look like this (except instead of 2 files per line I have like 8, and instead of 2 lines I have like 800-900:
::here merging track 001
(echo file './in/01.flac'&&echo file './in/02.flac')>temp.txt&&ffmpeg -y -f concat -safe 0 -i temp.txt -af adelay=delays=216:all=1 ".\out\output_001.flac"
::here merging track 002
(echo file './in/02.flac'&&echo file './in/01.flac')>temp.txt&&ffmpeg -y -f concat -safe 0 -i temp.txt -af adelay=delays=216:all=1 ".\out\output_001.flac"
::here merging track 003 (this one has no silence at the beginning)
(echo file './in/02.flac'&&echo file './in/03.flac')>temp.txt&&ffmpeg -y -f concat -safe 0 -i temp.txt ".\out\output_001.flac"
@del temp.txt
echo Press any key to exit... && pause>nul
The setup is:
The main workhorse of this is the concat command of ffmpeg, which merges together the files provided in the text file. -y is optional, it overwrites without asking if output exists (made testing easier) The (echo ...)>file.txt part inputs the list of tracks into the text file that concat will later use. Each echo is a new line and && merges them together. Can't add spaces for readability or they will end up in the text file. Next -i means input, I provide the text file for concat to work with. Contents of text file should follow this pattern:
file track_name1.flac
file track_name2.flac
file track_name3.flac
Lastly, I use the delay command on output to add the silence at the beginning of it. Length given in ms, so 1000 = 1 sec.
Oh, and the @del temp.txt
part at the end deletes the temporary text files to restore law and order in your folder :)
As a fun fact I can add that my database outputs data as CSV, so I use MS Excel to arrange it into BAT commands. Then I just paste it into a BAT file and remove all the \t - that's why having 1 line of commands per 1 file is so important to my work.