-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVideoSplit.py
executable file
·64 lines (56 loc) · 1.46 KB
/
VideoSplit.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
61
62
63
64
#/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import datetime
import subprocess
#Youtube video length (Default: 15min)
yvl = 14
#==COMMAND NOTE==
#1:start time
#2:end time
#3:input file name
#4:output file name
#5:count id
COMMAND = 'mencoder \
-ss %s:00 \
-endpos 00:%02d:00 \
-oac copy -ovc copy \
-of mpeg \
-forceidx %s \
-o %s_%02d.mpg'
input_filename = sys.argv[1:]
def getVideoLength(fileName):
"""
input: file name
return: video length (int)
"""
getLengthCommand = "mplayer -vo null -ao null -frames 0 -identify %s 2>/dev/null \
| grep ID_LENGTH=\
| sed 's/^ID_LENGTH=//'" % (fileName)
#print getLengthCommand
stdout,stdin = subprocess.Popen(args=getLengthCommand,
shell=True,
stdout=subprocess.PIPE
).communicate()
#print stdout
return float(stdout[:-2])
def getSliceConut(fileName,videoLength):
"""
input: file name, video slice length
output: slice count
"""
length = getVideoLength(fileName)
return int(length/(videoLength*60))+1
def Runner():
for x in input_filename:
for i in range( getSliceConut(x,yvl)):
cmd = COMMAND % (i*yvl,
yvl,
x,
''.join(x.split('.')[:-1])
,i)
print 'Run:',cmd
os.system(cmd)
if __name__ == '__main__':
Runner()