Skip to content

Instantly share code, notes, and snippets.

@alrafiabdullah
Created April 5, 2021 11:00
Show Gist options
  • Save alrafiabdullah/b9db080163cefd3f5d44a03b2659ed75 to your computer and use it in GitHub Desktop.
Save alrafiabdullah/b9db080163cefd3f5d44a03b2659ed75 to your computer and use it in GitHub Desktop.
import os
import subprocess
if not os.path.exists("assets"):
raise Exception("Please create and put all your vidoes in assets folder!")
mkv_list = os.listdir("assets")
if not os.path.exists("result"):
os.mkdir("result")
for mkv in mkv_list:
name, ext = os.path.splitext(mkv)
if ext != ".mkv":
raise Exception("Please add MKV files only!")
output_name = name + ".mp4"
try:
subprocess.run(
["ffmpeg", "-i", f"assets/{mkv}", "-codec", "copy", f"result/{output_name}"], check=True
)
except:
raise Exception(
"Please DOWNLOAD, INSTALL & ADD the path of FFMPEG to Environment Variables!"
)
print(f"{len(mkv_list)} video(s) converted to MP4!")
os.startfile("result")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment