Created
October 18, 2022 04:45
-
-
Save tayiorbeii/1a49b0d9b87e6024390f846972d5f14c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "@johnlindquist/kit" | |
| const leadingzero = await npm("leadingzero") | |
| const replaceAll = await npm("just-replace-all") | |
| // Name: split-video-on-scene | |
| let longVideoFile = await getSelectedFile() | |
| cd(path.dirname(longVideoFile)) | |
| // requires the scenedetect Python library | |
| // pip install --upgrade opencv | |
| // pip install --upgrade scenedetect[opencv] | |
| let {stdout} = await exec(`scenedetect --input "${longVideoFile}" --frame-skip 2 --min-scene-len 00:03:00 --merge-last-scene detect-content -t 40 list-scenes`) | |
| // parse detected scenes, adding 0s for the start | |
| let timecodelist = ['00:00:00', ...stdout.split('\n')[stdout.split('\n').length-1].trim().split(',')] | |
| let originalFilename = longVideoFile.split('/')[longVideoFile.split('/').length - 1] | |
| let cutsToMake = timecodelist.map((time, index) => { | |
| if (time[index + 1] == undefined) { | |
| return { | |
| from: time, | |
| desc: `${originalFilename}-part${leadingzero(index+1, 2)}`, | |
| } | |
| } | |
| return { | |
| from: time, | |
| to: timecodelist[index+1], | |
| desc: `${originalFilename}-part${leadingzero(index+1, 2)}` | |
| } | |
| }) | |
| for (let cut of cutsToMake) { | |
| let clipFileName = `${replaceAll(cut.desc, ' ', '_')}.mp4` | |
| await exec(`ffmpeg -i "${longVideoFile}" -c copy -ss ${cut.from} ${cut.to ? `-to ${cut.to}`: ''} ${clipFileName}`) | |
| // also split the SRT file | |
| await exec(`ffmpeg -i "${longVideoFile}.srt" -c copy -ss ${cut.from} ${cut.to ? `-to ${cut.to}`: ''} ${clipFileName}.srt`) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment