How to batch convert .wav to .mp3 with a script?
- KVRAF
- 4589 posts since 7 Jun, 2012 from Warsaw
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?
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(...)
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(...)
- KVRAF
- 16828 posts since 8 Mar, 2005 from Utrecht, Holland
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?
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. 
My MusicCalc is served over https!!
My MusicCalc is served over https!!
- Beware the Quoth
- 35449 posts since 4 Sep, 2001 from R'lyeh Oceanic Amusement Park and Funfair
sox
An idiot on Set Theory:
"In some cases there is an object called red that contains everything that is red. In much the same way a pot is a plate."
"In some cases there is an object called red that contains everything that is red. In much the same way a pot is a plate."
- KVRAF
- Topic Starter
- 4589 posts since 7 Jun, 2012 from Warsaw
Not much to say about that:BertKoor wrote: Tue Sep 27, 2022 9: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.
Code: Select all
lame -b 320 filename.wav filename.mp3I've got another script for thatHow's your folder structure: include subdirectories?
What about adding ID3 tags with artist, title & genre?
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(...)
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(...)
- KVRAF
- Topic Starter
- 4589 posts since 7 Jun, 2012 from Warsaw
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.
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(...)
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(...)