How to batch convert .wav to .mp3 with a script?

Plug-in hosts and other software applications discussion
RELATED
PRODUCTS
User avatar
DJ Warmonger
KVRAF
Topic Starter
4549 posts since 7 Jun, 2012 from Warsaw

Post Tue Sep 27, 2022 1:49 am

I'm looking for a tool (preferably free) that would allow to convert a large number of .wav files to .mp3 and can be triggered by command line, or one-click script at most.

Could you help with any suggetsions?
Blog ------------- YouTube channel
Tricky-Loops wrote: (...)someone like Armin van Buuren who claims to make a track in half an hour and all his songs sound somewhat boring(...)

User avatar
BertKoor
KVRAF
14094 posts since 8 Mar, 2005 from Utrecht, Holland

Post Tue Sep 27, 2022 1:59 am

lame.exe was always the best in class. You only need to figure out the CLI options and write a .bat / .cmd / .ps1 around it.

How's your folder structure: include subdirectories?
What about adding ID3 tags with artist, title & genre?
We are the KVR collective. Resistance is futile. You will be assimilated. Image
My MusicCalc is served over https!!

User avatar
whyterabbyt
Beware the Quoth
31607 posts since 4 Sep, 2001 from R'lyeh Oceanic Amusement Park and Funfair

Post Tue Sep 27, 2022 2:27 am

sox
:?:

User avatar
DJ Warmonger
KVRAF
Topic Starter
4549 posts since 7 Jun, 2012 from Warsaw

Post Tue Sep 27, 2022 5:53 am

BertKoor wrote: Tue Sep 27, 2022 1:59 am lame.exe was always the best in class. You only need to figure out the CLI options and write a .bat / .cmd / .ps1 around it.
Not much to say about that:

Code: Select all

lame -b 320 filename.wav filename.mp3
How's your folder structure: include subdirectories?
What about adding ID3 tags with artist, title & genre?
I've got another script for that :ud:
Blog ------------- YouTube channel
Tricky-Loops wrote: (...)someone like Armin van Buuren who claims to make a track in half an hour and all his songs sound somewhat boring(...)

User avatar
BertKoor
KVRAF
14094 posts since 8 Mar, 2005 from Utrecht, Holland

Post Tue Sep 27, 2022 7:19 am

So, problem solved then? ;-)
We are the KVR collective. Resistance is futile. You will be assimilated. Image
My MusicCalc is served over https!!

husker37
KVRist
290 posts since 24 Dec, 2016

Post Tue Sep 27, 2022 6:35 pm

Dbpoweramp Converter is what I use for this exact thing.

User avatar
DJ Warmonger
KVRAF
Topic Starter
4549 posts since 7 Jun, 2012 from Warsaw

Post Tue Sep 27, 2022 11:15 pm

It was more difficult than expected, but I wrote a Python script that runs lame.exe concurrently in multiple processes. Because 12 cores are better than one.

Warning: It deletes input .wavs afterwards.

Code: Select all

from asyncio import subprocess
import os
import subprocess
import multiprocessing
from multiprocessing.pool import ThreadPool

FOLDER = "G:\\Na przemiał"

# Find files

fileList = []
results = []

for name in os.listdir(FOLDER):
	if name.endswith('.wav'):
		fileList.append(name)

print("\nFound file names:\n\n" + '\n'.join(fileList))

def call_proc(name):
	""" This runs in a separate thread. """
	
	cmd = f"lame -b 320 \"{name}\" \"{name.replace('.wav', '.mp3')}\""

	p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
	out, err = p.communicate()
	print(f"Finished conversion of {name}")
	return (out, err)


pool = ThreadPool(multiprocessing.cpu_count())

for name in fileList:
	results.append(pool.apply_async(call_proc, (name,)))

# Close the pool and wait for each running task to complete
pool.close()
pool.join()
for result in results:
	out, err = result.get()

for name in fileList:

	newName = name.replace('.wav', '.mp3')

	if (os.path.exists(newName)):
		#file has been converted properly
		print(f"Deleting {name}")
		os.remove(name)
Blog ------------- YouTube channel
Tricky-Loops wrote: (...)someone like Armin van Buuren who claims to make a track in half an hour and all his songs sound somewhat boring(...)

Return to “Hosts & Applications (Sequencers, DAWs, Audio Editors, etc.)”