multiple trims

This commit is contained in:
q
2024-12-13 14:44:57 +02:00
parent c5947d0d60
commit 8902e0ad16
2 changed files with 13 additions and 19 deletions

View File

@@ -2,7 +2,7 @@ import argparse
from tsmark.video_annotator import Marker from tsmark.video_annotator import Marker
VERSION = "0.5" VERSION = "0.5.1"
def get_options(): def get_options():

View File

@@ -372,24 +372,18 @@ class Marker:
if len(self.stamps) == 0: if len(self.stamps) == 0:
self.stamps.append(0) self.stamps.append(0)
self.stamps.append(self.frames) self.stamps.append(self.frames)
if len(self.stamps) > 0: padlen = len(str(self.frames))
print( src_name = self.opts.video.replace('"', '\\"')
'ffmpeg -i "{}" {}-c:v mpeg2video -q:v 3 -g 1 -a copy -ss {} -to {} "{}.trimmed.mp4"'.format( tgt_name = os.path.splitext(self.opts.video)[0].replace('"', '\\"')
self.opts.video.replace('"', '\\"'), for i in range(1,len(self.stamps),2):
cropstr, from_ts = self.stamps[i-1]
self.format_time(self.stamps[0]), to_ts = self.stamps[i]
self.format_time(self.stamps[-1]), from_ft = self.format_time(from_ts)
os.path.splitext(self.opts.video)[0].replace('"', '\\"'), to_ft = self.format_time(to_ts)
) from_str=str(from_ts).zfill(padlen)
) to_str=str(to_ts).zfill(padlen)
elif self.crop[0][0] is not None: print(f'ffmpeg -i "{src_name}" {cropstr}-c:v mpeg2video -q:v 3 -g 1 -c:a copy -ss {from_ft} -to {to_ft} "{tgt_name}.trim.{from_str}-{to_str}.mpeg"')
print(
'ffmpeg -i "{}" {}-c:v mpeg2video -q:v 3 -g 1 "{}.trimmed.mp4"'.format(
self.opts.video.replace('"', '\\"'),
cropstr,
os.path.splitext(self.opts.video)[0].replace('"', '\\"'),
)
)
def save_timestamps(self): def save_timestamps(self):