Last active
July 20, 2016 18:40
-
-
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.
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 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