forked from Storyboard-fm/little-media-box
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
128 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,60 @@ | ||
const Asset = require('./asset') | ||
const Source = require('./source') | ||
const Target = require('./target') | ||
const { AudioTrack, SubtitleTrack, VideoTrack, Track } = require('./track') | ||
|
||
const nanoprocess = require('nanoprocess') | ||
const path = require('path') | ||
const uuidv4 = require('uuid/v4') | ||
|
||
class Delivery { | ||
constructor(sources, opts = {}) { | ||
if (sources instanceof Source) { | ||
this.sources = [sources] | ||
} else if (Array.isArray(sources) && sources.every(s => s instanceof Source)) { | ||
this.sources = sources | ||
} else { | ||
throw new Error('Invalid sources provided') | ||
} | ||
this.opts = opts | ||
} | ||
} | ||
|
||
class Package { | ||
constructor(tracks, opts = {}) { | ||
const opt = opts //copy | ||
this.targets = [] | ||
this.uuid = uuidv4() | ||
if (tracks instanceof Track) { | ||
this.tracks = [tracks] | ||
} else if (Array.isArray(tracks) && tracks.every(t => t instanceof Track)) { | ||
this.tracks = tracks.sort((track1, track2) => { | ||
return track1.properties.index - track2.properties.index | ||
}) | ||
} else { | ||
throw new Error('Invalid tracks provided') | ||
} | ||
|
||
if (opt.targets) { | ||
if (opt.targets instanceof Target) { | ||
this.targets = [opt.targets] | ||
} else if (Array.isArray(opt.targets) && | ||
opt.targets.every(t => t instanceof Target) | ||
) { | ||
this.targets.push(opt.targets) | ||
} | ||
} | ||
|
||
this.opts = opt | ||
|
||
this.muxes = [] | ||
this.demuxes = [] | ||
} | ||
mux(options = {}) { | ||
return new Promise((resolve, reject) => { | ||
const opts = options //copy | ||
const outputUrl = opts.outputUrl || 'mux_output.mkv' | ||
|
||
const tracks = this.tracks //copy | ||
const cmdOpts = ['-o', outputUrl, tracks.shift().source.uri] | ||
cmdOpts.push( | ||
...tracks.filter(t => t.source.uri !== cmdOpts[2]).map(m => `+${m.source.uri}`) | ||
) | ||
const muxCmd = nanoprocess('mkvmerge', cmdOpts) | ||
|
||
muxCmd.open((err) => { | ||
if (err) { reject(err) } | ||
muxCmd.process.on('close', (exitCode) => { | ||
console.log('closed mux command with code', exitCode) | ||
if (exitCode == 0) { | ||
this.muxes.push(outputUrl) | ||
resolve(outputUrl) | ||
} else { | ||
reject('mkvmerge failed with exit code', exitCode) | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
assignTargets(targets) { | ||
this.targets.push(targets) | ||
} | ||
const { ffmpeg, FFPROBE_BIN_PATH, FFMPEG_BIN_PATH } = require('./ffmpeg') | ||
const { createDemuxStream, demux } = require('./demux') | ||
const { MKVMERGE_BIN_PATH } = require('./mkvmerge') | ||
const { X264_BIN_PATH } = require('./x264') | ||
const { configure } = require('./configure') | ||
const { Delivery } = require('./delivery') | ||
const extensions = require('./extensions') | ||
const { Source } = require('./source') | ||
const { Target } = require('./target') | ||
const { Asset } = require('./asset') | ||
const constants = require('./constants') | ||
const settings = require('./settings') | ||
const { mux } = require('./mux') | ||
const targets = require('./targets') | ||
const iso639 = require('./iso-639') | ||
|
||
const { | ||
AudioTrack, | ||
SubtitleTrack, | ||
Track, | ||
TrackError, | ||
TrackPropertiesError, | ||
TrackPropertiesMissingFormatError, | ||
TrackPropertiesMissingStreamError, | ||
TrackValidationError, | ||
VideoTrack | ||
} = require('./track') | ||
|
||
/** | ||
* Module exports. | ||
*/ | ||
module.exports = { | ||
Asset, | ||
AudioTrack, | ||
configure, | ||
constants, | ||
createDemuxStream, | ||
Delivery, | ||
demux, | ||
extensions, | ||
ffmpeg, | ||
FFPROBE_BIN_PATH, | ||
FFMPEG_BIN_PATH, | ||
iso639, | ||
MKVMERGE_BIN_PATH, | ||
mux, | ||
settings, | ||
Source, | ||
SubtitleTrack, | ||
Target, | ||
targets, | ||
Track, | ||
TrackError, | ||
TrackPropertiesError, | ||
TrackPropertiesMissingFormatError, | ||
TrackPropertiesMissingStreamError, | ||
TrackValidationError, | ||
VideoTrack, | ||
X264_BIN_PATH, | ||
} | ||
|
||
module.exports = { Asset, AudioTrack, Delivery, Package, Source, SubtitleTrack, Target, Track, VideoTrack } |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const mobile = require('./mobile.json') | ||
const ps4 = require('./ps4.json') | ||
const web = require('./web.json') | ||
const vr = require('./vr.json') | ||
|
||
/** | ||
* Module exports. | ||
*/ | ||
module.exports = { | ||
mobile, | ||
ps4, | ||
vr, | ||
web | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"limits": { | ||
"codec": { | ||
"audio": { | ||
}, | ||
"video": { | ||
} | ||
} | ||
}, | ||
"name": "mobile", | ||
"enabled": [ ], | ||
"options": { | ||
"defaults": { | ||
"audio": { | ||
"channels": 2, | ||
"codec": [ | ||
"aac" | ||
], | ||
"sampleRate": 48000 | ||
}, | ||
"container": { | ||
"trackCount": { | ||
"video": 1, | ||
"audio": 1 | ||
} | ||
}, | ||
"video": { | ||
"codec": [ "h264_nvenc", "libx264" ] | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"limits": { | ||
"codec": { | ||
"audio": { | ||
}, | ||
"video": { | ||
} | ||
} | ||
}, | ||
"name": "vr", | ||
"enabled": [ ], | ||
"options": { | ||
"defaults": { | ||
"audio": { | ||
"channels": 2, | ||
"codec": [ | ||
"aac" | ||
], | ||
"sampleRate": 48000 | ||
}, | ||
"container": { | ||
"trackCount": { | ||
"video": 1, | ||
"audio": 1 | ||
} | ||
}, | ||
"video": { | ||
"codec": [ "h264_nvenc", "libx264" ] | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"limits": { | ||
"codec": { | ||
"audio": { | ||
}, | ||
"video": { | ||
} | ||
} | ||
}, | ||
"name": "web", | ||
"enabled": [ ], | ||
"options": { | ||
"defaults": { | ||
"audio": { | ||
"channels": 2, | ||
"codec": [ | ||
"aac" | ||
], | ||
"sampleRate": 48000 | ||
}, | ||
"container": { | ||
"trackCount": { | ||
"video": 1, | ||
"audio": 1 | ||
} | ||
}, | ||
"video": { | ||
"codec": [ "h264_nvenc", "libx264" ] | ||
} | ||
} | ||
} | ||
} |