-
Notifications
You must be signed in to change notification settings - Fork 0
/
ffmpeg-script.py
61 lines (50 loc) · 1.71 KB
/
ffmpeg-script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# ffmpeg-encoder-script
#
# Recurses through a directory to encode all video files using ffmpeg
#
# Place this file in the top level of the directory you want to encode
#
# Note: Video files to be encoded should contain the string "RAW" in
# their name or be within a subfolder that contains the string "RAW".
#
# author: mrracine
import os, re, subprocess
def printLogo():
print("###############################\n" +
"## ##\n" +
"## ffmpeg-script ##\n" +
"## ##\n" +
"## author: Mike Racine ##\n" +
"## ##\n" +
"###############################\n")
print("Encoding files in {}".format(os.getcwd()))
def encode(fIn, fOut):
subprocess.call(["ffmpeg", "-i", fIn,
"-map", "0",
"-map_metadata", "0",
"-c:v", "libx264", "-crf", "20",
"-c:a", "libfdk_aac", "-vbr", "5",
"-c:a:0", "copy",
"-c:s", "copy",
fOut])
if __name__ == "__main__":
printLogo()
ffmpegDefaultCmd = "ffmpeg -i "
rawToken = "RAW"
encodeToken = "ENCODED"
for dirpath, dirnames, filenames in os.walk(os.curdir):
# Check for directories containing raw files, encode to parent dir
if rawToken in dirpath:
for f in filenames:
encode(f, os.pardir + os.sep + f)
break
# Check for raw files, encode in same dir
for f in filenames:
if rawToken in f:
fName, ext = os.path.splitext(f)
fName.strip(rawToken)
fName.strip()
encode(f, fName + ext)
else:
fName, ext = os.path.splitext(f)
encode(f, fName + encodeToken + ext)