Skip to content

Instantly share code, notes, and snippets.

@psiie
Last active May 29, 2017 07:23
Show Gist options
  • Save psiie/430448b6ee26256d0b48cd849027bad2 to your computer and use it in GitHub Desktop.
Save psiie/430448b6ee26256d0b48cd849027bad2 to your computer and use it in GitHub Desktop.
Converting videos using python and FFMPEG
import os, subprocess
inDir = 'ka-lite-en/content/'
outDir = 'ka-lite-en-converted/content/'
ffmpeg = [
"ffmpeg",
"-i",
"in.mp4",
"-r",
"15",
"-vcodec",
"libx264",
"-crf",
"32",
"-preset",
"veryfast",
"-profile:v",
"baseline",
"-level",
"3",
"-refs",
"6",
"-vf",
"scale=720:-2,format=yuv420p",
"-acodec",
"copy",
"output.mp4",
"-y"
]
with open('progress.log', 'a') as log:
count = 0
for fn in os.listdir(inDir):
count = count + 1
ext = fn.split('.')
if (ext and len(ext) > 1 and ext[1] == 'mp4'):
filename = ext[0] + '.' +ext[1]
ffmpeg[2] = inDir + filename
ffmpeg[-2] = outDir + filename
subprocess.call(ffmpeg)
print ('converted ' + filename)
log.write(filename + ' converted. ' + str(count) + '\n')
log.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment