phrase and mode are no longer hardcoded in gen-script.py

This commit is contained in:
kolaczyn
2020-07-11 11:48:46 +02:00
parent baa67c408f
commit f75aa85d6c
3 changed files with 21 additions and 24 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
rm list.txt rip.sh output.mp4 debug.txt rm list.txt rip.sh output.mp4
rm -r ../out rm -r ../out
mkdir ../out mkdir ../out

View File

@ -8,13 +8,14 @@
# make program organize file # make program organize file
# add alternative versions # add alternative versions
# passing arguments into program; get rid of hardcoded values # passing arguments into program; get rid of hardcoded values
# fix def write_debug_file(data), so it generates correct values # add debug file, I removed the old one because it wasnt working correctly
# check if you tell ffmpeg after the video is over - how does it handle it? # check if you tell ffmpeg after the video is over - how does it handle it?
# if yes, add r_clamp(.). I would have to get the length of the videos # if yes, add r_clamp(.). I would have to get the length of the videos
import re import re
import os import os
import sys
from datetime import timedelta from datetime import timedelta
# left clamps. used to make sure that eg. 00:00:02 doesn't become 23:59:52 # left clamps. used to make sure that eg. 00:00:02 doesn't become 23:59:52
@ -66,25 +67,26 @@ def write_list_rip(data):
file_list.write("file '{}'\n".format(outname)) file_list.write("file '{}'\n".format(outname))
delta = d['end']-d['beg'] delta = d['end']-d['beg']
# painfully slow if sys.argv[2] == 'slow':
# file_rip.write('ffmpeg -i ../original/{}.mp4 -ss 0{} -t 0{} -async 1 {}\n'.format(name, d['beg'], delta ,outname)) # slow but more accurate file_rip.write('ffmpeg -i ../original/{}.mp4 -ss 0{} -t 0{} -async 1 {}\n'.format(name, d['beg'], delta ,outname)) # slow but more accurate
# very fast, but there are still 'bugs' elif sys.argv[2] =='fast':
true_beg = l_clamps(d['beg'], back) true_beg = l_clamps(d['beg'], back)
d1 = d['beg'] - true_beg # we have to do it his was just in case the clip is at the beginning d1 = d['beg'] - true_beg # we have to do it his was just in case the clip is at the beginning
file_rip.write('ffmpeg -ss 0{} -i ../original/{}.mp4 -ss 0{} -t 0{} -c copy {}\n'.format(true_beg, name, d1, delta, outname)) # fast but not accurate file_rip.write('ffmpeg -ss 0{} -i ../original/{}.mp4 -ss 0{} -t 0{} -c copy {}\n'.format(true_beg, name, d1, delta, outname)) # fast but not accurate
# generates a debug file - I can see how the clips are laid out def validate_arguments():
# at the moment it doesnt work correcty. fix that if not len(sys.argv) == 3:
def write_debug_file(data): print('Error: incorrect number of arguments.')
file_debug = open('debug.txt', 'w') sys.exit()
for d in data: if not sys.argv[2] in ['slow', 'fast']:
if d: print('Error: second argument can be only one of the following: slow, fast')
file_debug.write('{}\t{}\t{}\t{}\n'.format(d['fname'][:2], d['beg'], d['end'], d['desc'])) sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
search = '(pesky bird)' # the searched phrase validate_arguments()
search = sys.argv[1] # the searched phrase
sides = timedelta(seconds=10) # time we cut on both sides sides = timedelta(seconds=10) # time we cut on both sides
back = timedelta(seconds=60) # how much do we want to go to get better keyframes. dunno how to explain this in two sentences back = timedelta(seconds=60) # how much do we want to go to get better keyframes. dunno how to explain this in two sentences
path = os.getcwd() + '/../subs/' # subtitles location path = os.getcwd() + '/../subs/' # subtitles location
@ -93,4 +95,3 @@ if __name__ == "__main__":
data = generate_splice_data(file_names) data = generate_splice_data(file_names)
merge_overlap(data) merge_overlap(data)
write_list_rip(data) write_list_rip(data)
write_debug_file(data)

10
run.sh
View File

@ -1,9 +1,5 @@
#!/bin/bash #!/bin/bash
# TODO make it so the only data you need to feed the application sh clean.sh
# is an URL of a youtube playlist/ video you want to edit python gen-script.py
sh rip.sh
./clean.sh
./gen-script.py
bash rip.sh
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4 # splice all the clips