Skip to content

Instantly share code, notes, and snippets.

@weakish
Last active July 1, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weakish/3a07023cd37885a59ec0efeb6fabb48d to your computer and use it in GitHub Desktop.
Save weakish/3a07023cd37885a59ec0efeb6fabb48d to your computer and use it in GitHub Desktop.
cut video
import ffmpy
from typing import List, Dict, Tuple
from typing_extensions import Final
def parse_time_span(s: str) -> Tuple[str, List[Dict[str, str]]]:
episode: Final[str]
time_span: Final[str]
episode, time_span = s.split(':', 1)
spans: List[str] = list(filter(lambda e: e is not '', time_span.split(',')))
result: List[Dict[str, str]] = []
for span in spans:
ss_to: List[str] = span.split('-')
d: Dict[str, str] = {'ss': ss_to[0].strip(), 'to': ss_to[1].strip()}
result.append(d)
return episode, result
def make_clips(s: str) -> None:
episode: Final[str]
time_spans: Final[List[Dict[str, str]]]
episode, time_spans = parse_time_span(s)
for index, time_span in enumerate(time_spans, start=1):
ffmpy.FFmpeg(
inputs={f'{episode}.mp4': None},
outputs={f'{episode}_{index}.mp4': f'-ss {time_span["ss"]}.0 -to {time_span["to"]}.0 -c copy'}
).run()
if __name__ == "__main__":
make_clips('14: 06:00-08:30, 19:50-22:00, 24:00-25:15')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment