Created
July 7, 2022 20:40
-
-
Save jpsamaroo/6fc18e4aefa979cec0b0ef7dd3fcf605 to your computer and use it in GitHub Desktop.
FFMPEG Cutting Script - in Julia
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
#!/usr/bin/env julia | |
function ts_to_s(ts::AbstractString) | |
secs = tryparse(Float64, ts) | |
if secs !== nothing | |
return secs | |
end | |
hours, mins, secs = parse.(Float64, split(ts, ':')) | |
return (hours * 60 * 60) + (mins * 60) + secs | |
end | |
file = popfirst!(ARGS) | |
file_out = "$(file)_edited.mkv" | |
cp(file, file_out; force=true) | |
cuts = [] | |
while !isempty(ARGS) | |
splits = popfirst!(ARGS) | |
start, stop = split(splits, '|') | |
start_s = ts_to_s(start) | |
stop_s = ts_to_s(stop) | |
println("Cutting $file from $start to $stop ($start_s to $stop_s)") | |
push!(cuts, (start_s, stop_s)) | |
end | |
expr = join(map(cut->"between(t,$(cut[1]),$(cut[2]))", cuts), '+') | |
run(`ffmpeg -i $file_out -vf "select='eq($expr,0)',setpts=N/FRAME_RATE/TB" -af "aselect='eq($expr,0)',asetpts=N/SR/TB" "$(file_out).tmp.mkv"`) | |
mv("$(file_out).tmp.mkv", file_out; force=true) | |
println("Done editing. Output file is at $file_out") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment