我が家で長年使っていた、Ruby版の雑品のひとつを書き換えます。
これはアクションカメラの動画やネットで拾った動画から音声だけを抜き出すものです。ffmpegを中で呼んでいます。
#!/usr/bin/python3 import os import re import subprocess p2 = re.compile(r'\.([Ww][Aa][Vv]|[Oo][Gg][Gg])$') p = re.compile(r'\.([a-zA-Z]+)$') #p = re.compile(r'\.([Ww][Ee][Bb][Mm])$') for f in os.listdir("."): if((p.search(f) != None) and (p2.search(f) == None)): f2 = p.sub('.ogg',f) if os.path.isfile(f2): print("あり:"+f2) else: print("なし:"+f2) x = "ffmpeg " + "-vn -i \"" + f + "\" \"" + f2 + "\"" print(x) subprocess.run(x,shell=True)