Last active
March 15, 2023 22:00
-
-
Save sfan5/e461d6f8b9c2620abd32952165c8d6ec to your computer and use it in GitHub Desktop.
VapourSynth script for "simple" frame exact cutting of video & audio
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 vapoursynth as vs | |
import csv | |
core = vs.get_core() | |
if "input" not in dir(): | |
print("ERROR: Provide input file via --arg input=./spec.txt") | |
assert False | |
vsrc = None | |
asrc = None | |
aout = "output.wav" | |
ranges = [] | |
with open(input, 'r') as f: | |
reader = csv.reader(f, | |
delimiter=' ', escapechar='\\', | |
quotechar='"', quoting=csv.QUOTE_MINIMAL, | |
strict=True, skipinitialspace=False | |
) | |
for fields in reader: | |
if len(fields) < 1: continue | |
t = fields[0].lower() | |
if t == "video": | |
assert len(fields) == 2, "argument error" | |
assert vsrc is None, "only one video source allowed" | |
vsrc = fields[1] | |
elif t == "audio": | |
assert len(fields) == 2, "argument error" | |
assert asrc is None, "only one video source allowed" | |
asrc = fields[1] | |
elif t == "aout": | |
assert len(fields) == 2, "argument error" | |
assert fields[1].split(".")[-1] in ("wav", "flac"), "invalid audio format" | |
aout = fields[1] | |
elif t == "frames": | |
assert len(fields) == 3, "argument error" | |
a, b = int(fields[1]), int(fields[2]) | |
assert b >= a, "end frame must be >= start frame" | |
ranges.append((a, b)) | |
else: | |
assert False, "unrecognized thingy" | |
assert vsrc is not None, "video source missing" | |
assert vsrc is not None, "audio source missing" | |
assert len(ranges) > 0, "no frame ranges given" | |
src = core.ffms2.Source(vsrc) | |
src = core.damb.Read(src, asrc) | |
out = None | |
for r in ranges: | |
add = core.std.Trim(src, first=r[0], last=r[1]) | |
out = (add) if out is None else (out + add) | |
out = core.damb.Write(out, aout) | |
out.set_output() |
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
video "furry porn.mp4" | |
audio extracted_audio.wav | |
aout final_audio.flac # <- can be omitted (defaults to .wav format) | |
frames 582 1757 | |
frames 3460 4617 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment