-
Notifications
You must be signed in to change notification settings - Fork 1
/
image_extract.py
31 lines (17 loc) · 910 Bytes
/
image_extract.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
import os
def flame_extract(video_name,flame_interval,output_dir):
cmd = "ffmpeg -i " + video_name + " 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//"
length = os.popen(cmd).read()
length_0 = length.split(":")
video_length = float(length_0[1])*60 + float(length_0[2])
print "video length is: " + str(video_length) + "s"
r = str(float(1.0/flame_interval))
#os.system("mkdir test")
print "ffmpeg -i " + video_name + " -f image2 -ss 0 -r " + r + " "+ output_dir +"test-%03d.jpg "
os.system("ffmpeg -i " + video_name + " -f image2 -ss 0 -r " + r + " "+ output_dir +"test-%03d.jpg ")
return video_length,length
if __name__ == "__main__":
video_name = "test.mp4"
flame_interval = 1.0
output_dir = "/home/xiatian/music_generation/test_image/"
video_length = flame_extract(video_name,flame_interval,output_dir)