Converts a directory of low bitrate mp4 audio files to window media audio with ffmpeg.
This is a quick conversion for my car's CD player as it doesn't support mp4.
Converts a directory of low bitrate mp4 audio files to window media audio with ffmpeg.
This is a quick conversion for my car's CD player as it doesn't support mp4.
| import json | |
| import os | |
| import re | |
| rename_command = \ | |
| "ffmpeg -nostats -loglevel 0 -i {mp4} -codec:a wmav2 -b:a 64k {wma}" | |
| root_path = "." | |
| dest_path = "converts" | |
| root_re = re.escape(root_path) | |
| dest_re = re.escape(dest_path) | |
| for root, dirs, files in os.walk(root_path): | |
| path = root.split(os.sep) | |
| for f in files: | |
| if(f.endswith('.mp4')): | |
| mp4_fn = os.path.join(root, f) | |
| wma_fn = re.sub(r"^{}(.*)(\.mp4)$".format(root_re), | |
| r"{}\1.wma".format(dest_re), | |
| mp4_fn) | |
| if(not os.path.isfile(wma_fn)): | |
| cmd = rename_command.format( | |
| mp4=json.dumps(mp4_fn), | |
| wma=json.dumps(wma_fn), | |
| ) | |
| if not os.path.isdir(os.path.dirname(wma_fn)): | |
| os.makedirs(os.path.dirname(wma_fn)) | |
| print("generating {}".format(wma_fn)) | |
| os.system(cmd) | |
| else: | |
| print("wma exists skipping {}".format(wma_fn)) |