-
Notifications
You must be signed in to change notification settings - Fork 1
/
video_frequence_detect.py
85 lines (65 loc) · 2.43 KB
/
video_frequence_detect.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import subprocess
import os
"""
Computer the time segmentation of a video.
Based on the HSI change frequence (a threshold is set) and the content change frequence
Return a list of all the time sec of the a video
"""
def get_time_sec(file_name, save_image=False):
cmd = "scenedetect --input "+ file_name +" --detector content --threshold 10 -fs 2 -df 2"
if save_image == True:
cmd += " -si"
output = subprocess.check_output(cmd, shell=True)
time_sec = output.split("[PySceneDetect]")[-1].split(",")
time_sec[0] = time_sec[0].split("\n")[-1]
time_sec[-1] = time_sec[-1].split("\n")[0]
output_time_sec = []
for time in time_sec:
temp = time.split(":")
time = float(temp[-1]) + float(temp[-2])*60
#time = int(time+0.5)
output_time_sec.append(time)
output_time_sec = list(set(output_time_sec))
output_time_sec.sort()
return output_time_sec
"""
Compute the number of time sec between every key frame,
which is the frequence feature of the video.
Return the frame-changed frequence of an interval.
"""
def compute_interval_frequence(start_time,end_time,output_time_sec):
if end_time < start_time:
print "end time is less than start time"
frame_num = 0
for time_sec in output_time_sec:
if time_sec <= float(end_time) and time_sec > float(start_time):
frame_num += 1
return float(frame_num) / (end_time - start_time)
"""
Compute the video frequence emotion feature.
"""
def compute_frequence_feature(mood_duration, file_name):
print "*****************************************************"
print "extract video frequence feature"
output_time_sec = get_time_sec(file_name)
start_time = 0
end_time = 0
#define the frequence emotion bound
happy_bound = 0.5
sad_bound = 0.1
video_frequence_feature = []
for duration in mood_duration:
start_time = end_time
end_time = start_time + duration
interval_frequence = compute_interval_frequence(start_time,end_time,output_time_sec)
video_frequence_feature.append(interval_frequence)
return video_frequence_feature
if __name__ == "__main__":
file_name = "test3.mp4"
mood_duration = []
for i in range(35):
mood_duration.append(10)
video_frequence_feature = compute_frequence_feature(mood_duration,file_name)
print "************************************"
for x in video_frequence_feature:
print x