Last active
February 17, 2021 16:00
-
-
Save zmarffy/d1f7599411204be8ced016195e3655b5 to your computer and use it in GitHub Desktop.
Split an audio file by start times using `ffmpeg`
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 argparse | |
import subprocess | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file", help="file to split") | |
parser.add_argument("name_and_time", type=lambda x: x.rsplit( | |
"_", 1), nargs="+", help="[name]_[time to split on]") | |
args = parser.parse_args() | |
file_extension = args.file.split(".")[-1] | |
for index, (file_name, start_time) in enumerate(args.name_and_time): | |
f = f"{file_name}.{file_extension}" | |
if index == len(args.name_and_time) - 1: | |
subprocess.check_call( | |
["ffmpeg", "-i", args.file, "-acodec", "copy", "-ss", start_time, f]) | |
else: | |
subprocess.check_call(["ffmpeg", "-i", args.file, "-acodec", "copy", | |
"-ss", start_time, "-to", args.name_and_time[index + 1][1], f]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment