Skip to content

Instantly share code, notes, and snippets.

@Qman11010101

Qman11010101/wav2flac.py

Last active Jan 31, 2021
Embed
What would you like to do?
ffmpegを使ってwavをflacに変えるやつ
# Copyright 2021 Kjuman Enobikto
# Version: 3.8以上
# FFmpegのパスが通っている必要があります
# 配布: https://qmainconts.f5.si/index.html#wav2flac
import glob
import os
import subprocess
import sys
files = glob.glob("*.wav")
remove_origin = True
if len(arg := sys.argv) == 2:
if arg[1] in ["-s", "--save-origin"]:
remove_origin = False
print(files)
current_dir = os.getcwd()
for wavfile in files:
filename = wavfile.replace(".wav", "")
commandstr = f'ffmpeg -i "{current_dir}\\{filename}.wav" -vn -ar 44100 -ac 2 -acodec flac -f flac "{current_dir}\\{filename}.flac"'
subprocess.run(commandstr, shell=True)
if remove_origin:
os.remove(wavfile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment