Last active
July 1, 2020 15:05
-
-
Save weakish/3a07023cd37885a59ec0efeb6fabb48d to your computer and use it in GitHub Desktop.
cut video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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