Simplify export and filter manifests from dash generation.

This commit is contained in:
Kavin 2023-03-02 14:18:53 +00:00
parent bf0fb000e3
commit acff16a8d4
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 183 additions and 179 deletions

View file

@ -283,9 +283,10 @@ export default {
mime = "application/x-mpegURL"; mime = "application/x-mpegURL";
} else if (this.video.audioStreams.length > 0 && !lbry && MseSupport) { } else if (this.video.audioStreams.length > 0 && !lbry && MseSupport) {
if (!this.video.dash) { if (!this.video.dash) {
const dash = ( const dash = (await import("../utils/DashUtils.js")).generate_dash_file_from_formats(
await import("@/utils/DashUtils.js").then(mod => mod.default) streams,
).generate_dash_file_from_formats(streams, this.video.duration); this.video.duration,
);
uri = "data:application/dash+xml;charset=utf-8;base64," + btoa(dash); uri = "data:application/dash+xml;charset=utf-8;base64," + btoa(dash);
} else { } else {

View file

@ -4,12 +4,12 @@ import { Buffer } from "buffer";
window.Buffer = Buffer; window.Buffer = Buffer;
import { json2xml } from "xml-js"; import { json2xml } from "xml-js";
const DashUtils = { export function generate_dash_file_from_formats(VideoFormats, VideoLength) {
generate_dash_file_from_formats(VideoFormats, VideoLength) { const generatedJSON = generate_xmljs_json_from_data(VideoFormats, VideoLength);
const generatedJSON = this.generate_xmljs_json_from_data(VideoFormats, VideoLength);
return json2xml(generatedJSON); return json2xml(generatedJSON);
}, }
generate_xmljs_json_from_data(VideoFormatArray, VideoLength) {
function generate_xmljs_json_from_data(VideoFormatArray, VideoLength) {
const convertJSON = { const convertJSON = {
declaration: { declaration: {
attributes: { attributes: {
@ -32,22 +32,26 @@ const DashUtils = {
{ {
type: "element", type: "element",
name: "Period", name: "Period",
elements: this.generate_adaptation_set(VideoFormatArray), elements: generate_adaptation_set(VideoFormatArray),
}, },
], ],
}, },
], ],
}; };
return convertJSON; return convertJSON;
}, }
generate_adaptation_set(VideoFormatArray) {
function generate_adaptation_set(VideoFormatArray) {
const adaptationSets = []; const adaptationSets = [];
let mimeAudioObjs = []; let mimeAudioObjs = [];
VideoFormatArray.forEach(videoFormat => { VideoFormatArray.forEach(videoFormat => {
// the dual formats should not be used // the dual formats should not be used
if (videoFormat.mimeType.indexOf("video") != -1 && !videoFormat.videoOnly) { if (
(videoFormat.mimeType.includes("video") && !videoFormat.videoOnly) ||
videoFormat.mimeType.includes("application")
) {
return; return;
} }
@ -97,17 +101,18 @@ const DashUtils = {
for (var i = 0; i < mimeAudioObj.videoFormats.length; i++) { for (var i = 0; i < mimeAudioObj.videoFormats.length; i++) {
const videoFormat = mimeAudioObj.videoFormats[i]; const videoFormat = mimeAudioObj.videoFormats[i];
if (isVideoFormat) { if (isVideoFormat) {
adapSet.elements.push(this.generate_representation_video(videoFormat)); adapSet.elements.push(generate_representation_video(videoFormat));
} else { } else {
adapSet.elements.push(this.generate_representation_audio(videoFormat)); adapSet.elements.push(generate_representation_audio(videoFormat));
} }
} }
adaptationSets.push(adapSet); adaptationSets.push(adapSet);
}); });
return adaptationSets; return adaptationSets;
}, }
generate_representation_audio(Format) {
function generate_representation_audio(Format) {
const representation = { const representation = {
type: "element", type: "element",
name: "Representation", name: "Representation",
@ -154,8 +159,9 @@ const DashUtils = {
], ],
}; };
return representation; return representation;
}, }
generate_representation_video(Format) {
function generate_representation_video(Format) {
const representation = { const representation = {
type: "element", type: "element",
name: "Representation", name: "Representation",
@ -198,7 +204,4 @@ const DashUtils = {
], ],
}; };
return representation; return representation;
}, }
};
export default DashUtils;