forked from Deevoluation/ALPR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
videosplit_sklearn.py
56 lines (41 loc) · 1.27 KB
/
videosplit_sklearn.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
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import skvideo.io
import numpy as np
import os
import time
import shutil
import scipy.misc
def Launch(video):
start = time.time()
videodata = skvideo.io.vreader(video)
metadata = skvideo.io.ffprobe(video)
metadata = metadata['video']
size = (metadata['@width'],metadata['@height'])
fps = metadata['@avg_frame_rate']
totalFrames = int(metadata['@nb_frames'])
videolength = metadata['@duration']
#print( "total frames = : ",totalFrames )
try:
if os.path.exists('data'):
shutil.rmtree('data', ignore_errors=True)
os.makedirs('data')
except OSError:
print('Error: Creating data')
framesWeNeed = 5
interval = round(totalFrames/framesWeNeed)
count = 0
frame_no = 0
for frame in videodata:
if(count % interval == 0):
frame_no += 1
name = './data/frame' + str(frame_no) + '.jpg'
scipy.misc.imsave(name,frame)
count += 1
print( "total frames generated = : ",frame_no)
print('\ntime taken = ' + str(time.time() - start))
return ("{0:.2f}".format(float(videolength)),str(totalFrames))
#Launch('car18.mp4')