-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenc-twitter.py
45 lines (33 loc) · 1.18 KB
/
enc-twitter.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
# -*- coding: utf-8 -*-
import csv, os, shutil, argparse, errno,subprocess
import glob
def argparser_prepare():
class PrettyFormatter(argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter):
max_help_position = 35
parser = argparse.ArgumentParser(description='encode video for twitter',
formatter_class=PrettyFormatter)
parser.add_argument( 'path', type=str,
help='path to file or http url')
return parser
def is_url_exists(url):
return requests.head(url).status_code < 400
parser = argparser_prepare()
args = parser.parse_args()
path = args.path
print(path)
if os.path.isfile(path):
cmd='''
SRC=$1
DST=$(dirname $1)/$(basename $1| cut -d. -f1)-twitter.mp4
ffmpeg -i $SRC -y -vf scale=1920:1080 -c:v libx264 -crf 24 -vf format=yuv420p -c:a aac -movflags +faststart -preset fast $DST
'''
cmd = cmd.replace('$1',path)
os.system(cmd)
elif path != '':
cmd = '''wget -O- $url | ffmpeg -i - -y -c:v libx264 -crf 24 -preset fast -c:a libmp3lame v/twitter.mp4'''
cmd = cmd.replace('$url',path)
print(cmd)
os.system(cmd)
else:
quit('not found' + path)