Last active
March 25, 2021 17:24
-
-
Save djeikyb/c6255775d70cee9bf5ff8bc94391b0f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
interface Stream { | |
file: string; | |
kind: "video" | "audio"; | |
label?: string; | |
} | |
interface Job { | |
streams: Stream[]; | |
dest: string; | |
} | |
const job: Job = { | |
dest: "out", | |
streams: [ | |
{ | |
file: "hd720.mp4", | |
kind: "video", | |
}, | |
{ | |
file: "hd1080.mp4", | |
kind: "video", | |
}, | |
{ | |
file: "2k.mp4", | |
kind: "video", | |
}, | |
{ | |
file: "4k.mp4", | |
kind: "video", | |
}, | |
], | |
}; | |
function stripFileExtension(name: string) { | |
const idx = name.lastIndexOf("."); | |
return name.slice(0, idx); | |
} | |
const args: string[] = []; | |
// packager docs use this term, "stream descriptor" | |
// each line that specifies a file input is a stream descriptor | |
// the format is <field>=<value>[,<field>=<value>]... | |
for (const stream of job.streams) { | |
const segmentFolder: string = stripFileExtension(stream.file); | |
const fields: string[] = []; | |
fields.push(`in=${stream.file}`); | |
fields.push(`stream=${stream.kind}`); | |
fields.push(`playlist_name=${segmentFolder}/stream.m3u8`); | |
fields.push(`init_segment=${job.dest}/${segmentFolder}/init.mp4`); | |
fields.push(`segment_template=${job.dest}/${segmentFolder}/$Number$.m4s`); | |
const stream_descriptor = fields.join(","); | |
args.push(`'${stream_descriptor}'`); | |
} | |
args.push("--hls_playlist_type VOD"); | |
args.push(`--hls_master_playlist_output=${job.dest}/main.m3u8`); | |
// If segment_template is specified in stream descriptors, shaka-packager | |
// generates dynamic mpd by default; if this flag is enabled, | |
// shaka-packager generates static mpd instead | |
args.push("--generate_static_live_mpd"); | |
args.push(`--mpd_output=${job.dest}/main.mpd`); | |
const cmd = `rm -r out ; packager \\\n ${args.join(" \\\n ")}`; | |
console.log(cmd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download this file to, I dunno, hullo.ts and run it:
Run the generated shaka packager command (cd to /media first):
In the same directory as the script, generate the test content like: