forked from CommanderAsdasd/Weedeeoart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weedeeo.py
138 lines (118 loc) · 5.03 KB
/
Weedeeo.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# -*- coding: utf-8 -*-
from FilesScanner import *
from SequenceGenerator import *
from Writer import *
from Compose import *
from TimeEffects import *
from ImageEffects import *
from Mixing import *
from math import *
from moviepy.video.fx.all import *
import os
import sys
import moviepy
import logging
import random
import json
import moviepy.audio.fx.all as afx
import multiprocessing
from itertools import product
class Weedeeo(FilesScanner, Writer, Compose, TimeEffects, ImageEffects, Mixing):
'''Main class of video cutter combine Defines how and how much video will be cringed. Term 'Clips' is used for original files,
sequences is a internal cuts of these media clips'''
def __init__(self, path='./', logging='DEBUG', scantype = 'default', sources_count=5):
Compose.__init__(self)
Mixing.__init__(self)
ImageEffects.__init__(self)
self.sequences_video = []
self.sequences_audio = []
self.exec_numb = 5
self.path = path
self.Scanner = FilesScanner(self.path, sources_count)
self._logger()
if scantype =="recur":
self._scan_recur()
elif scantype == "default":
self._scan_default()
def _scan_recur(self):
self.Scanner.random_crawler()
def _scan_default(self):
# self.clips_video = self.Scanner.scan_video()
# self.clips_audio = self.Scanner.scan_audio()
pass
def _count_clips():
return len(self.clips_video)
def _count_sequences(self):
return len(self.sequences_video)
def _logger(self):
root = logging.getLogger()
root.setLevel(logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)
def shuffle_video(self, minLength=1, maxLength=1, times=1):
GeneratorVideo = SequenceGenerator(minLength, maxLength)
for i in self.Scanner.clips_video:
for j in range(0,times):
self.sequences_video.append(GeneratorVideo.rand_sequence(i))
random.shuffle(self.sequences_video)
# logging.debug("Video is: {}".format(self.sequences_video))
def shuffle_images(self, minLength=1, maxLength=1, times=1):
# logging.debug("images are: {}".format(self.clips_video))
self.clips_video.append(self.Scanner.scan_images(maxLength))
GeneratorImages = SequenceGenerator(minLength, maxLength)
for i in self.clips_video:
for j in range(0,times):
self.sequences_video.append(GeneratorImages.rand_sequence(i))
random.shuffle(self.sequences_video)
def shuffle_audio(self, minLength=1, maxLength=1, times=1):
# logging.debug(self.clips_audio)
GeneratorAudio = SequenceGenerator(minLength, maxLength)
for i in self.clips_audio:
self.clips_audio
for j in range(0,times):
self.sequences_audio.append(GeneratorAudio.rand_sequence(i))
random.shuffle(self.sequences_audio)
# logging.debug("Audio is: {}".format(self.sequences_audio))
def chop_sequences(self, timecodes):
if (len(self.sequences_video)>0):
with open(timecodes) as chopFile:
chopStr = chopFile.read()
chopData = json.loads(chopStr)
GeneratorVideo = SequenceGenerator()
for i in self.clips_video:
for start, end in chopData.items():
self.sequences_video.insert(0,GeneratorVideo.sequence(i, start, end))
# print(start, end)
def chop_clips(self, timecodes):
# if (hasattr(self, 'sequences_video')):
if (len(self.clips_video)>0):
clips_video_chop = []
with open(timecodes) as chopFile:
chopStr = chopFile.read()
chopData = json.loads(chopStr)
GeneratorVideo = SequenceGenerator()
for i, clip in enumerate(self.clips_video):
for start, end in chopData.items():
try:
clips_video_chop.append(GeneratorVideo.sequence(clip, start, end))
except Exception as e:
logging.info("An error in function {} occured: '{}'".format(sys._getframe().f_code.co_name, e))
self.clips_video = clips_video_chop
# print(start, end)
def audio_fx(self):
'''bring audio fx '''
# for i, pointerAudio in enumerate(self.sequences_audio):
# if random.randint(0,100) <= chance:
# self.sequences_audio[i] = pointerAudio.
def reshuffle(self):
if len(self.sequences_video) != 0:
random.shuffle(self.sequences_video)
if len(self.sequences_audio) != 0:
random.shuffle(self.sequences_video)
# if len(self.sequences_audio) != 0:
# self.sequences_altered + self.sequences_video)
def invert_green_blue(self):
pass