Convert aac to mp3 and maintain the original directory structure
FFmpeg needs to be installed in advance
import os import subprocess import time from import ThreadPoolExecutor, as_completed def convert_file(input_path, output_path): command = [ 'ffmpeg', '-y', # Automatically overwrite existing files '-i', input_path, '-acodec', 'libmp3lame', '-b:a', '192k', output_path ] try: (command, check=True, stderr=, timeout=300) #5 minutes timeout return f"Converted: {output_path}" except as e: return f"Error converting {input_path}: {()}" except : return f"Timeout converting {input_path}" def convert_aac_to_mp3(input_dir, output_dir): start_time = () total_files = 0 processed_files = 0 converted_files = 0 with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor: futures = [] for root, _, files in (input_dir): for filename in files: if ().endswith('.aac'): total_files += 1 input_path = (root, filename) rel_path = (root, input_dir) output_filename = (filename)[0] + '.mp3' output_path = (output_dir, rel_path, output_filename) ((output_path), exist_ok=True) ((convert_file, input_path, output_path)) for future in as_completed(futures): result = () print(result) processed_files += 1 if "Converted" in result: converted_files += 1 print(f"Progress: {processed_files}/{total_files} files processed") end_time = () print(f"\nConversion completed.") print(f"Total files: {total_files}") print(f"Converted files: {converted_files}") print(f"Failed conversions: {total_files - converted_files}") print(f"Total time: {end_time - start_time:.2f} seconds")
Using scripts
input_dir = input("Please enter the directory path that contains the AAC file: ") output_dir = input("Please enter the output directory path of the MP3 file: ") convert_aac_to_mp3(input_dir, output_dir)
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.