Skip to content

Instantly share code, notes, and snippets.

@lostfictions
Last active July 20, 2016 18:40
Show Gist options
  • Save lostfictions/612651cd21e7c9177b766b58e383d17e to your computer and use it in GitHub Desktop.
Save lostfictions/612651cd21e7c9177b766b58e383d17e to your computer and use it in GitHub Desktop.
Node script to convert any type of file VLC can read into a Unity import-friendly .ogv format.
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const efs = require('child_process').execFileSync
const vlcPath = path.resolve('C\:/Program\ Files/VideoLAN/VLC/vlc.exe')
const getVlcArgs = (inputFile, outputFile) =>
`"${inputFile}" :sout='#transcode{vcodec=theo,vb=800,scale=1,acodec=vorb,ab=128,channels=2,samplerate=44100}:file{dst="${outputFile}"}' vlc://quit --intf dummy`
const [dir1, dir2] = process.argv.slice(2, 4)
if(dir1 == undefined) {
console.log(`Usage: converter [inputDirectory] outputDirectory`)
return
}
if(!fs.existsSync(vlcPath)) {
throw new Error(`Cannot find VLC at ${vlcPath}!`)
}
const outputDir = path.resolve(dir2 != undefined ? dir2 : dir1)
const inputDir = path.resolve(dir2 != undefined ? dir1 : process.cwd())
if(!fs.existsSync(inputDir)) {
throw new Error(`Input directory ${inputDir} not found!`)
}
if(!fs.existsSync(outputDir)) {
throw new Error(`Output directory ${outputDir} not found!`)
}
const inFilesToOutFiles = fs.readdirSync(inputDir)
.filter(f => f.endsWith('.mov'))
.map(f => [path.join(inputDir, f), path.join(outputDir, f.slice(0, -4) + '.ogv')])
inFilesToOutFiles.forEach(f => {
console.log(`Transcoding ${f[0]} to ${f[1]}`)
efs(vlcPath, [f[0], `:sout=#transcode{vcodec=theo,vb=800,scale=1,acodec=vorb,ab=128,channels=2,samplerate=44100}:file{dst="${f[1]}"}`, 'vlc://quit', '--intf', 'dummy'])
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment