@@ -64,6 +64,7 @@ def __init__(self):
64
64
self .encoding_params = ''
65
65
self .video_filter = ''
66
66
self .output_file = ''
67
+ self .scenes = ''
67
68
self .audio = ''
68
69
# OS specific NULL pointer
69
70
@@ -96,6 +97,7 @@ def arg_parsing(self):
96
97
parser .add_argument ('--force_fps' , '-fps' , type = int , default = 0 , help = 'Force fps of output file' )
97
98
parser .add_argument ('--video_filter' , '-vf' , type = str , default = self .video_filter , help = 'FFmpeg video options' )
98
99
parser .add_argument ('--pix_format' , '-fmt' , type = str , default = self .pix_format , help = 'FFmpeg pixel format' )
100
+ parser .add_argument ('--scenes' , '-s' , type = str , default = self .scenes , help = 'File location for scenes' )
99
101
100
102
# Test
101
103
try :
@@ -107,6 +109,9 @@ def arg_parsing(self):
107
109
# Pass command line args that were passed
108
110
self .args = parser .parse_args ()
109
111
112
+ # Set scenes if provided
113
+ self .scenes = self .args .scenes
114
+
110
115
# Set encoder if provided
111
116
self .encoder = self .args .encoder .strip ()
112
117
if self .encoder not in ('svt_av1' , 'rav1e' , 'aom' ):
@@ -207,23 +212,50 @@ def extract_audio(self, input_vid):
207
212
print ('Audio stream file not found. Error in audio extraction' )
208
213
exit ()
209
214
210
- def split_video (self , input_vid ):
211
-
215
+ def scenedetect (self , video , output ):
212
216
# PySceneDetect used split video by scenes and pass it to encoder
213
217
# Optimal threshold settings 15-50
214
- print (f'\r Spliting video..' , end = '\r ' )
215
218
216
- cmd2 = f'scenedetect -i { input_vid } --output .temp/ detect-content ' \
219
+ cmd2 = f'scenedetect -i { video } --output { output } detect-content ' \
217
220
f'--threshold { self .threshold } list-scenes '
218
221
self .call_cmd (cmd2 )
219
- scenes = '.' .join (input_vid .split ('.' )[:- 1 ])
220
- with open (f'{ join (self .here , ".temp" , f"{ scenes } -Scenes.csv" )} ' ) as csv_file :
222
+
223
+ def split (self , video , timecodes ):
224
+ cmd = f'{ self .FFMPEG } -i { video } -map_metadata -1 -an -f segment -segment_times { timecodes } ' \
225
+ f'-c copy -avoid_negative_ts 1 .temp/split/%04d.mkv'
226
+ self .call_cmd (cmd )
227
+
228
+ def read_csv (self , file_path ):
229
+ with open (file_path ) as csv_file :
221
230
stamps = next (csv .reader (csv_file ))
222
231
stamps = stamps [1 :]
223
232
stamps = ',' .join (stamps )
224
- cmd = f'{ self .FFMPEG } -i { input_vid } -map_metadata -1 -an -f segment -segment_times { stamps } ' \
225
- f'-c copy -avoid_negative_ts 1 .temp/split/%04d.mkv'
226
- self .call_cmd (cmd )
233
+ return stamps
234
+
235
+ def split_video (self , input_vid ):
236
+
237
+ if self .scenes :
238
+
239
+ file_path = join (self .here , self .scenes )
240
+ if os .path .exists (file_path ):
241
+ stamps = self .read_csv (file_path )
242
+ self .split (input_vid , stamps )
243
+ else :
244
+ self .scenedetect (input_vid , '.' )
245
+ video = '.' .join (input_vid .split ('.' )[:- 1 ])
246
+ file_path = f'{ join (self .here , f"{ video } -Scenes.csv" )} '
247
+
248
+ stamps = self .read_csv (file_path )
249
+ self .split (input_vid , stamps )
250
+ else :
251
+ print (f'\r Spliting video..' , end = '\r ' )
252
+
253
+ self .scenedetect (input_vid , '.temp' )
254
+ video = '.' .join (input_vid .split ('.' )[:- 1 ])
255
+ file_path = f'{ join (self .here , ".temp" , f"{ video } -Scenes.csv" )} '
256
+
257
+ stamps = self .read_csv (file_path )
258
+ self .split (input_vid , stamps )
227
259
228
260
def get_video_queue (self , source_path ):
229
261
0 commit comments