Skip to content

Commit

Permalink
handle filenames with single quote
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongdove committed Oct 23, 2021
1 parent 9ab51c6 commit 0596495
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mkchap.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def process(inputfile, outputfile):


def get_chapters(inputfile, duration):
output = get_output(['ffprobe', '-f', 'lavfi', '-i', 'movie=\'{}\',blackdetect=d={}:pic_th={}:pix_th={}[out0]'.format(inputfile, min_black_seconds, ratio_black_pixels, pixel_threshold),
escaped_inputfile = escape(inputfile)
output = get_output(['ffprobe', '-f', 'lavfi', '-i', 'movie={},blackdetect=d={}:pic_th={}:pix_th={}[out0]'.format(escaped_inputfile, min_black_seconds, ratio_black_pixels, pixel_threshold),
'-show_entries', 'frame_tags=lavfi.black_start,lavfi.black_end', '-of', 'default=nw=1', '-v', 'panic'])
raw_pairs = filter(lambda c: len(c) == 2, chunks(output.splitlines(), 2))
numeric_pairs = list(map(
Expand Down Expand Up @@ -108,6 +109,8 @@ def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]

def escape(text):
return text.replace('\'', '\\\\\\\'')

if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 0596495

Please sign in to comment.