Skip to content

Instantly share code, notes, and snippets.

@drewja
Created October 24, 2023 17:15
Show Gist options
  • Save drewja/0ac697fd25ca069730a44b6a4e0e23c6 to your computer and use it in GitHub Desktop.
Save drewja/0ac697fd25ca069730a44b6a4e0e23c6 to your computer and use it in GitHub Desktop.
#!/bin/env python
import os
import subprocess
import shutil
exe = shutil.which('ffmpeg')
def usage():
print("Call ffmpeg to convert audio to AC3 for playback on ruku devices")
print("Video is left untouched")
print(f"{__name__} [-r dir]")
print(f"{__name__} video.avi movie.mkv")
def ffmpeg(files):
for file in files:
ouf = '_' + file
cmd = [exe, "-i", file, "-vcodec", "copy", "-acodec", "ac3", ouf]
subprocess.run(cmd)
os.rename(ouf, file)
if __name__ == '__main__':
import sys
files = []
args = sys.argv[1:]
if args[0].lower() == '-r':
try:
files = os.listdir(args[1])
except:
print("[ERROR] [-r] argument must be directory")
usage()
exit(1)
else: files = args
files = [fil for fil in files if os.path.isfile(fil)]
if not files:
usage()
exit(1)
ffmpeg(files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment