Skip to content

Instantly share code, notes, and snippets.

@victusfate
Created December 13, 2013 22:40
Show Gist options
  • Save victusfate/7952653 to your computer and use it in GitHub Desktop.
Save victusfate/7952653 to your computer and use it in GitHub Desktop.
quick mp4 segmenter
exec = require('child_process').exec;
args = process.argv.splice(2);
if args != 4
console.log 'usage: file totalTime dT outRoot'
file = args[0]
totalTime = parseFloat args[1]
dT = parseInt args[2], 10
outRoot = args[3]
nChunks = Math.ceil(totalTime/dT)
lastTime = totalTime - (nChunks - 1) * dT
cliArray = []
for i in [0...nChunks]
time = dT
time = lastTime if i == nChunks-1
cli = 'echo ffmpeg -v quiet -y -ss ' + i*dT + ' -t ' + time + ' -i ' + file + ' -c copy -sn ' + outRoot + i + '.mp4'
cliArray[i] = cli
console.log cliArray
runChain = (cliArray,i) ->
cli = cliArray[i]
exec cli, (err,sout,serr) ->
if err
console.log err
process.exit 1
else
console.log sout
console.log serr
i++
if i < cliArray.length
runChain cliArray, i
else
console.log 'done 1'
null
null
runChain cliArray, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment