diff --git a/tsmark/__init__.py b/tsmark/__init__.py index c92e105..a918602 100644 --- a/tsmark/__init__.py +++ b/tsmark/__init__.py @@ -1,7 +1,7 @@ from tsmark.video_annotator import Marker import argparse -VERSION = "0.4.5" +VERSION = "0.4.6" def get_options(): @@ -13,7 +13,7 @@ def get_options(): dest="timestamps", default=None, required=False, - help="Comma separated list of predefined timestamps, in seconds, or HH:MM:SS.ss. You can use the -o output file as input via --ts $( cut -d, -f1 ts.csv | xargs printf '%%s,' )", + help="Comma separated list of predefined timestamps, in seconds, or HH:MM:SS.ss, or input CSV file. You can use the -o output file as input via --ts $( cut -d, -f1 ts.csv | xargs printf '%%s,' )", ) parser.add_argument( "-o", diff --git a/tsmark/video_annotator.py b/tsmark/video_annotator.py index 01f4449..70262d0 100755 --- a/tsmark/video_annotator.py +++ b/tsmark/video_annotator.py @@ -247,10 +247,17 @@ class Marker: def parse_timestamps(self): if self.opts.timestamps: + if os.path.exists(self.opts.timestamps): + with open(self.opts.timestamps,'rt') as fp: + + self.opts.timestamps = [x.split(",")[0] for x in fp.readlines()] + else: + self.opts.timestamps = self.opts.timestamps.split(",") + self.stamps = sorted( [ self.parse_time(ts.strip()) - for ts in self.opts.timestamps.split(",") + for ts in self.opts.timestamps if ts.strip() != "" ] ) @@ -270,11 +277,11 @@ class Marker: print("# {}: {} / {}".format(i + 1, self.format_time(ts), ts + 1)) if len(self.stamps) > 0: print( - 'ffmpeg -i "{}" -ss {} -to {} -c copy "{}.trimmed.mp4"'.format( - self.opts.video.replace('"', '\\"'), + 'ffmpeg -ss {} -to {} -i "{}" -c copy "{}.trimmed.mp4"'.format( self.format_time(self.stamps[0]), self.format_time(self.stamps[-1]), self.opts.video.replace('"', '\\"'), + self.opts.video.replace('"', '\\"'), ) )