now you can easily crop few seconds more both ways

This commit is contained in:
kolaczyn
2020-06-25 04:04:27 +02:00
parent a04b35f014
commit f3ab649341

View File

@ -3,16 +3,20 @@ import re
import os
from datetime import timedelta
search = '(pesky|bird)' # the searched phrase
search = '(pesky bird)' # the searched phrase
sides = 6 # how much do we to both sides of a fragment
# TODO:
# side =6 -> side = timedelta(seconds=6)
#now sides cant be bigger than 29, because of the way i hardcoded it somewhere
#TODO give an option to use longer version
# the fast version should be for testing only anyway
# to make sure that 00:00:02 doesn't become 23:59:42
def clamps(t):
if (t<timedelta(seconds=sides)):
if (t<=timedelta(seconds=sides)):
return timedelta()
else:
return t
return t-timedelta(seconds=sides)
# if
# def merge_overlap(data): # if two chunks overlap, they get merged
@ -36,7 +40,11 @@ for i, f in enumerate(file_names):
file = open(path + f)
for i, line in enumerate(file):
if i%4 == 2 and re.search(search, line): # we only need to check lines which contain text, hence the first condition
data.append({'fname':f, 'beg':prev[0:8], 'end':prev[17:25], 'desc':line}) # get file name, time stamps and desciption
data.append({
'fname':f,
'beg':clamps(timedelta(minutes = int(prev[3 :5]), seconds=int(prev[6: 8]))),
'end':clamps(timedelta(minutes = int(prev[20:22]), seconds=int(prev[23:25]))),
'desc':line}) # get file name, time stamps and desciption
if i%4 == 1:
prev = line # a timestamp line
@ -48,10 +56,9 @@ for (i, d) in enumerate(data):
outname ="../out/{}-{:0>2}.mp4".format(name, i)
# refactor time thingy and get rid of hardcoding
time_beg = '0' + str(clamps((timedelta(minutes=int(d['beg'][3:5]), seconds=int(d['beg'][6:8]))-timedelta(seconds=sides))))
time_end = '0' + str(clamps((timedelta(minutes=int(d['end'][3:5]), seconds=int(d['end'][6:8]))+timedelta(seconds=sides))))
file_list.write("file '{}'\n".format(outname))
file_rip .write('ffmpeg -ss {} -i ../original/{}.mp4 -to 00:00:{} -c copy {}\n'.format(time_beg, name, sides*2,outname))
print(d['end']-d['beg'])
file_rip .write('ffmpeg -ss {} -i ../original/{}.mp4 -to 0{} -c copy {}\n'.format(d['beg'], name, d['end']-d['beg']+timedelta(seconds=6),outname))
# file_rip .write('ffmpeg -ss {} -i ../original/{}.mp4 -to 00:00:12 -c copy {}\n'.format(d['beg'], name, outname))