Skip to content

Commit

Permalink
subtitle overlay support
Browse files Browse the repository at this point in the history
  • Loading branch information
agrathwohl committed Dec 28, 2017
1 parent a87e076 commit 4727864
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 7 additions & 3 deletions encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ const grabScreenshot = (video, data, outPath) => new Promise((resolve, reject) =
f.run()
})

const encodeVideo = (video, data, outPath, codecs, platform) => new Promise((resolve, reject) => {
const encodeVideo = (video, data, outPath, codecs, args) => new Promise((resolve, reject) => {
const bar = new ProgressBar({
schema: ` Encoding ${path.basename(video)} @ :fps fps [:bar] :percent `,
width : 80,
total : 100
})
const platform = args.platform
const f = ffmpeg(video)
f.on('start', () => term.bold('Encoding video...\n'))
f.on('progress', prog => bar.update((prog.percent / 100), { fps: prog.currentFps }))
Expand Down Expand Up @@ -118,6 +119,9 @@ const encodeVideo = (video, data, outPath, codecs, platform) => new Promise((res
} else if (data.width < 2560) {
f.size(`${data.width}x?`)
}
if (args.subtitles) {
f.videoFilters(`subtitles=${path.resolve(args.subtitles)}`)
}
f.run()
})

Expand Down Expand Up @@ -155,10 +159,10 @@ const getCodecSupport = () => new Promise((resolve, reject) => {
} catch (err) { reject(err.stack || err) }
})

const main = (video, data, outPath, platform) => new Promise((resolve, reject) => {
const main = (video, data, outPath, args) => new Promise((resolve, reject) => {
getCodecSupport().then(codecs => {
return Promise.all([
encodeVideo(video, data, outPath, codecs, platform),
encodeVideo(video, data, outPath, codecs, args),
grabScreenshot(video, data, outPath)
])
}).then((outputs) => {
Expand Down
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const argv = require('yargs')
.describe('t', 'Input video type')
.choices('t', ['sbs', 'ou', 'mono', '2d'])
.default('t', 'mono')
.alias('s', 'subtitles')
.nargs('s', 1)
.describe('s', 'Path to subtitle track to overlay on top of video')
.alias('o', 'outputDirectory')
.nargs('o', 1)
.describe('o', 'Output directory (default: same as input path)')
Expand All @@ -37,8 +40,8 @@ const argv = require('yargs')
'encode 180 degree over-under stereoscopic video')
.example('node $0 -i myvideo.mp4 -d 360 -t sbs -o /work/encodes',
'encode 360 degree side-by-side stereoscopic video, output to /work/encodes directory')
.example('node $0 -i myvideo.mp4 -d 0 -t 2d -p windowsmr',
'encode a 2D flat video for viewing in theater mode for Windows MR')
.example('node $0 -i myvideo.mp4 -d 0 -t 2d -p windowsmr -s mysubtitles.srt',
'encode a 2D flat video with overlayed subtitles for viewing in theater mode for Windows MR')
.epilog('Email [email protected] for assistance/accolades.\n\nCopyright 2018 Little Star Media, Inc.')
.demandOption(['input', 'degrees'])
.showHelpOnFail(false, 'Specify --help for options')
Expand Down Expand Up @@ -78,6 +81,10 @@ let outputFilePath = `${argv.outputDirectory || videoDir}/${videoBase.toLowerCas
switch (argv.degrees) {
case 360:
case 180:
if (argv.subtitles) {
term.bold(`Subtitles not supported for 360 or 180 video.\n`)
process.exit(1)
}
outputFilePath = `${outputFilePath}_${argv.degrees}_${argv.type}.mp4`
break
case 0:
Expand All @@ -99,7 +106,7 @@ term.underline.red(`Outputting PSVR sideload video to ${outputFilePath}\n`)
* Then perform the transcode and output an interleaved MP4 */

analyze(videoFile).then((videoData) => {
return encode(videoFile, videoData, outputFilePath, argv.platform)
return encode(videoFile, videoData, outputFilePath, argv)
}).then((encodedVideoFile) => {
term.bold(`Encoding complete. Output path: ${encodedVideoFile}`)
}).catch(err => {
Expand Down

0 comments on commit 4727864

Please sign in to comment.