-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import argparse | ||
import subprocess | ||
|
||
def convert_audio_to_mp4(file_path): | ||
output_file = f"{os.path.splitext(file_path)[0]}.mp4" | ||
command = [ | ||
"ffmpeg", | ||
"-i", file_path, | ||
"-c:a", "aac", | ||
"-b:a", "320k", | ||
"-dither_method", "rectangular", | ||
"-ar", "44100", | ||
output_file | ||
] | ||
subprocess.run(command, check=True) | ||
|
||
def process_directory(directory): | ||
for root, _, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith((".wav", ".flac")): | ||
file_path = os.path.join(root, file) | ||
convert_audio_to_mp4(file_path) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Convert .wav or .flac files to .mp4 using ffmpeg.") | ||
parser.add_argument("-d", "--directory", required=True, help="Directory to process.") | ||
|
||
args = parser.parse_args() | ||
|
||
process_directory(args.directory) | ||
|
||
if __name__ == "__main__": | ||
main() |