-
Notifications
You must be signed in to change notification settings - Fork 1
/
squarify.py
42 lines (34 loc) · 1009 Bytes
/
squarify.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
'''
Transcode the files...
to 720x520 and SAR=1:1
'''
import os
import subprocess
import sys
def transcode(local_filepath):
# ffmpeg -i local_filepath -vf scale=720x540,setsar=1:1 local_filepath_sq.mp4
# delete original
# return temp_vids/transcoded_filepath
transcoded_filepath = False
splitpath = list(os.path.splitext(local_filepath))
splitpath.insert(1,"_square-pixel")
transcoded_filepath = ''.join(splitpath)
command = "ffmpeg -i {} -vf scale=720x540,setsar=1:1 {}".format(local_filepath,transcoded_filepath).split()
output = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# print(output.stdout.decode('utf-8'))
print(output.stderr.decode('utf-8'))
if os.path.isfile(transcoded_filepath):
pass
else:
transcoded_filepath = False
return transcoded_filepath
def main(local_filepath):
if os.path.isfile(sys.argv[1]:
local_filepath
transcoded_filepath = transcode(local_filepath)
return transcoded_filepath
if __name__ == "__main__":
main()