As music files in a folder, convert them from .ogg to .mp3 (pytnon)

Viewed 180

There is a folder with music files how to convert them from .ogg to .mp3

I know there is a way to convert to ffmpeg

How to do this in Python 3 so that it converts all files from a folder (test_music/01.ogg,02.ogg, ...09.ogg)

1 Answers

You can use python module os and subprocess for this if you have ffmpeg in PATH:

import os
import subprocess

os.chdir(r'FILE_PATH')
for ogg in [x for x in os.listdir() if x.endswith('.ogg')]:
  subprocess.run(["ffmpeg", "-i", ogg, ogg.split(".")[0]+".mp3"])
Related