-
Notifications
You must be signed in to change notification settings - Fork 0
/
video-slicer.py
64 lines (46 loc) · 1.8 KB
/
video-slicer.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
# written by Muluh MG Godson
# godsonmuluh@gmail.com
from moviepy.editor import *
import os
import csv
#Defaults
gif_duration = 5
videopath = "videos"
header = ['VIDEO', 'GIF', 'AUDIO', 'TSTART', 'TEND']
#Get all the videos
vid_tot = os.listdir(videopath)
print("Total Videos: " + str(len(vid_tot)))
#add data to csv file
with open('output/metadata.csv', 'a', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
# write the header
writer.writerow(header)
for index, v in enumerate(vid_tot, start=1):
#Load the video file
clip = (VideoFileClip(videopath+"/"+v))
#Get the Duration of the video file
duration = clip.duration
gif_total = int(duration/gif_duration)
print("Clip Duration: " + str(duration))
print("Total GIFs: " + str(gif_total))
t_start = 0
t_end = gif_duration
for x in range(gif_total):
print("Video: " + str(index) + " of " + str(len(vid_tot)))
print("Video Name: " + str(v))
print("GIF: " + str(x) + " of " + str(gif_total))
print("GIF Beginning TimeStamp: " + str(t_start))
print("GIF Ending TimeStamp: " + str(t_end))
#Get 5 seconds of gif
gif = clip.subclip(t_start,t_end)
audioclip = gif.audio
#export the gif video and audio
g_name = str(v)+str(x)+".gif"
a_name = str(v)+str(x)+".wav"
gif.write_gif("output/gif/"+g_name)
audioclip.write_audiofile("output/audio/"+a_name, 44100, 2, 2000,"pcm_s32le")
#Add data to csv file
data = [str(v),g_name,a_name,t_start,t_end]
writer.writerow(data)
t_start = t_start + gif_duration
t_end = t_end + gif_duration