I have a bunch of .au-files linked to an Audacity project, but I don’t have the project file itself. Luckily, the files can be sorted by creation date (the left and right mono files are created at the same time as a pair, I guess). I wrote a python script to rename the files according to their creation date, let Audacity convert them to mp3, then used ffmpeg -filter_complex amix=inputs=2:duration=longest to merge the two monos into one and then ffmpeg -i “concat:…|…|…” to append them all to one file. You can hear distinct cut-noises after each file, though. Any tips on how to do this right?
Yeah, using a different format did solve the problem. ffmpeg doesn’t support concatenating wav files though, so I converted au to mpeg (2x mono) to mpeg (1x mono) to mp3. That works okay. Here’s the code:
import os
from tkinter import filedialog
import subprocess
ffmpegPath = input("Where is ffmpeg.exe located? Press Enter if it's added to PATH, otherwise"\
" enter the full path to the executable.\n>> ")
if ffmpegPath == "\n":
ffmpegPath = "ffmpeg"
#Search for the au files and
auFolder = filedialog.askdirectory() +"/"
files = [auFolder+file for file in os.listdir(auFolder) if file.endswith(".au")]
#sort them by creation time
files = sorted(files, key=lambda file: os.stat(file).st_mtime)
#rename them according to creation time, so audacity conversion can't mess them up
i = 0
while i <= len(files)-2:
try:
os.rename(files[i], auFolder+str(i+1)+".au")
os.rename(files[i+1], auFolder+str(i+2)+".au")
except FileExistsError:
break #This script apparently has already been run once
i += 2
input("Now convert everything in " + auFolder + " to wav using audacity and press enter.\n"\
"Use File-Apply Chain... for this (preferably wav format)")
#Convert the mono canals into one
files = [auFolder+"cleaned/"+file for file in os.listdir(auFolder+"cleaned/")]
files = sorted(files, key=lambda file: int(file.split("/")[-1][:-4]))
try:
os.mkdir("converted")
except FileExistsError:
for file in os.listdir("converted"):
os.remove("converted/"+file)
i = 0
while i <= len(files)-2:
subprocess.run(ffmpegPath+" -i \""+files[i]+"\" -i \""+files[i+1] +\
"\" -filter_complex amix=inputs=2:duration=longest -y converted/"+str(i)+".mpeg")
i += 2
#concatenate with the created files
files = ["converted/"+file for file in os.listdir("converted/")]
files = sorted(files, key=lambda file: int(file.split("/")[-1][:-5]))
command = ffmpegPath+" -i concat:\""
for i in range(len(files)):
if i == len(files)-1:
command += files[i]+"\" "
else:
command += files[i]+"|"
command += " -y converted.mp3"
#The file is created where this script is run
subprocess.run(command)