@file-viewer/renderer-media 2.2.9 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +3 -0
- package/README.md +3 -0
- package/dist/mp4.d.ts +35 -0
- package/dist/mp4.js +447 -0
- package/dist/mp4v.worker.d.ts +1 -0
- package/dist/mp4v.worker.js +228 -0
- package/dist/mp4vPlayer.d.ts +6 -0
- package/dist/mp4vPlayer.js +226 -0
- package/dist/vendor/mp4v/AOSP-NOTICE.txt +189 -0
- package/dist/vendor/mp4v/EMSCRIPTEN-LICENSE.txt +101 -0
- package/dist/vendor/mp4v/mp4v-decoder.d.mts +20 -0
- package/dist/vendor/mp4v/mp4v-decoder.mjs +2 -0
- package/dist/vendor/mp4v/mp4v-decoder.wasm +0 -0
- package/dist/video.js +128 -6
- package/package.json +8 -4
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Emscripten is available under 2 licenses, the MIT license and the
|
|
2
|
+
University of Illinois/NCSA Open Source License.
|
|
3
|
+
|
|
4
|
+
Both are permissive open source licenses, with little if any
|
|
5
|
+
practical difference between them.
|
|
6
|
+
|
|
7
|
+
The reason for offering both is that (1) the MIT license is
|
|
8
|
+
well-known, while (2) the University of Illinois/NCSA Open Source
|
|
9
|
+
License allows Emscripten's code to be integrated upstream into
|
|
10
|
+
LLVM, which uses that license, should the opportunity arise.
|
|
11
|
+
|
|
12
|
+
The full text of both licenses follows.
|
|
13
|
+
|
|
14
|
+
==============================================================================
|
|
15
|
+
|
|
16
|
+
Copyright (c) 2010-2014 Emscripten authors, see AUTHORS file.
|
|
17
|
+
|
|
18
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
in the Software without restriction, including without limitation the rights
|
|
21
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
furnished to do so, subject to the following conditions:
|
|
24
|
+
|
|
25
|
+
The above copyright notice and this permission notice shall be included in
|
|
26
|
+
all copies or substantial portions of the Software.
|
|
27
|
+
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
34
|
+
THE SOFTWARE.
|
|
35
|
+
|
|
36
|
+
==============================================================================
|
|
37
|
+
|
|
38
|
+
Copyright (c) 2010-2014 Emscripten authors, see AUTHORS file.
|
|
39
|
+
All rights reserved.
|
|
40
|
+
|
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
42
|
+
copy of this software and associated documentation files (the
|
|
43
|
+
"Software"), to deal with the Software without restriction, including
|
|
44
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
45
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
46
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
47
|
+
the following conditions:
|
|
48
|
+
|
|
49
|
+
Redistributions of source code must retain the above copyright
|
|
50
|
+
notice, this list of conditions and the following disclaimers.
|
|
51
|
+
|
|
52
|
+
Redistributions in binary form must reproduce the above
|
|
53
|
+
copyright notice, this list of conditions and the following disclaimers
|
|
54
|
+
in the documentation and/or other materials provided with the
|
|
55
|
+
distribution.
|
|
56
|
+
|
|
57
|
+
Neither the names of Mozilla,
|
|
58
|
+
nor the names of its contributors may be used to endorse
|
|
59
|
+
or promote products derived from this Software without specific prior
|
|
60
|
+
written permission.
|
|
61
|
+
|
|
62
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
63
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
64
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
65
|
+
IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
|
66
|
+
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
67
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
68
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
|
|
69
|
+
|
|
70
|
+
==============================================================================
|
|
71
|
+
|
|
72
|
+
This program uses portions of Node.js source code located in src/library_path.js,
|
|
73
|
+
in accordance with the terms of the MIT license. Node's license follows:
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
77
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
78
|
+
of this software and associated documentation files (the "Software"), to
|
|
79
|
+
deal in the Software without restriction, including without limitation the
|
|
80
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
81
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
|
82
|
+
furnished to do so, subject to the following conditions:
|
|
83
|
+
|
|
84
|
+
The above copyright notice and this permission notice shall be included in
|
|
85
|
+
all copies or substantial portions of the Software.
|
|
86
|
+
|
|
87
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
88
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
89
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
90
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
91
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
93
|
+
IN THE SOFTWARE.
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
The musl libc project is bundled in this repo, and it has the MIT license, see
|
|
97
|
+
system/lib/libc/musl/COPYRIGHT
|
|
98
|
+
|
|
99
|
+
The third_party/ subdirectory contains code with other licenses. None of it is
|
|
100
|
+
used by default, but certain options use it (e.g., the optional closure compiler
|
|
101
|
+
flag will run closure compiler from third_party/).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface Mp4vDecoderModule {
|
|
2
|
+
HEAPU8: Uint8Array
|
|
3
|
+
_malloc(size: number): number
|
|
4
|
+
_free(pointer: number): void
|
|
5
|
+
_mp4v_create(config: number, configSize: number, width: number, height: number): number
|
|
6
|
+
_mp4v_decode(decoder: number, data: number, size: number, timestamp: number): number
|
|
7
|
+
_mp4v_reset(decoder: number): number
|
|
8
|
+
_mp4v_output(decoder: number): number
|
|
9
|
+
_mp4v_width(decoder: number): number
|
|
10
|
+
_mp4v_height(decoder: number): number
|
|
11
|
+
_mp4v_buffer_width(decoder: number): number
|
|
12
|
+
_mp4v_buffer_height(decoder: number): number
|
|
13
|
+
_mp4v_destroy(decoder: number): void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare const createDecoderModule: (options?: {
|
|
17
|
+
locateFile?: (path: string, directory: string) => string
|
|
18
|
+
}) => Promise<Mp4vDecoderModule>
|
|
19
|
+
|
|
20
|
+
export default createDecoderModule
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
async function Module(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";var programArgs=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var EXITSTATUS;class EmscriptenEH{}class EmscriptenSjLj extends EmscriptenEH{}var runtimeInitialized=false;function getMemoryBuffer(){return wasmMemory.buffer}function updateMemoryViews(){if(HEAP8?.buffer?.resizable)return;var b=getMemoryBuffer();HEAP8=new Int8Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b)}function preRun(){var preRun=Module["preRun"];if(preRun){if(typeof preRun=="function")preRun=[preRun];onPreRuns.push(...preRun)}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["g"]()}function postRun(){var postRun=Module["postRun"];if(postRun){if(typeof postRun=="function")postRun=[postRun];onPostRuns.push(...postRun)}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("mp4v-decoder.wasm")}return new URL("mp4v-decoder.wasm",import.meta.url).href}function getBinarySync(file){if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();var instantiateWasm=Module["instantiateWasm"];if(instantiateWasm){return new Promise(resolve=>{instantiateWasm(info,inst=>resolve(receiveInstance(inst)))})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var onPreRuns=[];var noExitRuntime=true;var __abort_js=()=>abort("");var runtimeKeepaliveCounter=0;var __emscripten_runtime_keepalive_clear=()=>{noExitRuntime=false;runtimeKeepaliveCounter=0};var timers={};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind"){return EXITSTATUS}quit_(1,e)};var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;_proc_exit(status)};var _exit=exitJS;var maybeExit=()=>{if(!keepRuntimeAlive()){try{_exit(EXITSTATUS)}catch(e){handleException(e)}}};var callUserCallback=func=>{if(ABORT){return}try{return func()}catch(e){handleException(e)}finally{maybeExit()}};var _emscripten_get_now=()=>performance.now();var __setitimer_js=(which,timeout_ms)=>{if(timers[which]){clearTimeout(timers[which].id);delete timers[which]}if(!timeout_ms)return 0;var id=setTimeout(()=>{delete timers[which];callUserCallback(()=>__emscripten_timeout(which,_emscripten_get_now()))},timeout_ms);timers[which]={id,timeout_ms};return 0};var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var HEAPU8;var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["arguments"])programArgs=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var preInit=Module["preInit"];if(preInit){if(typeof preInit=="function")Module["preInit"]=preInit=[preInit];while(preInit.length>0){preInit.shift()()}}}var _mp4v_create,_free,_malloc,_mp4v_decode,_mp4v_reset,_mp4v_output,_mp4v_width,_mp4v_height,_mp4v_buffer_width,_mp4v_buffer_height,_mp4v_destroy,__emscripten_timeout,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_mp4v_create=Module["_mp4v_create"]=wasmExports["h"];_free=Module["_free"]=wasmExports["i"];_malloc=Module["_malloc"]=wasmExports["j"];_mp4v_decode=Module["_mp4v_decode"]=wasmExports["k"];_mp4v_reset=Module["_mp4v_reset"]=wasmExports["l"];_mp4v_output=Module["_mp4v_output"]=wasmExports["m"];_mp4v_width=Module["_mp4v_width"]=wasmExports["n"];_mp4v_height=Module["_mp4v_height"]=wasmExports["o"];_mp4v_buffer_width=Module["_mp4v_buffer_width"]=wasmExports["p"];_mp4v_buffer_height=Module["_mp4v_buffer_height"]=wasmExports["q"];_mp4v_destroy=Module["_mp4v_destroy"]=wasmExports["r"];__emscripten_timeout=wasmExports["s"];memory=wasmMemory=wasmExports["f"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={d:__abort_js,c:__emscripten_runtime_keepalive_clear,a:__setitimer_js,e:_emscripten_resize_heap,b:_proc_exit};async function run(){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}var wasmExports;wasmExports=await createWasm();await run();
|
|
2
|
+
;return Module}export default Module;
|
|
Binary file
|
package/dist/video.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createFileViewerTranslator } from '@file-viewer/core';
|
|
2
|
+
import { extractMp4vSoftwareTrack, inspectMp4VideoTrack } from './mp4.js';
|
|
3
|
+
import { mountMp4vSoftwarePlayer } from './mp4vPlayer.js';
|
|
2
4
|
const videoStyle = `
|
|
3
5
|
.fv-video-viewer{width:100%;min-height:100%;display:flex;align-items:center;justify-content:center;padding:28px;background:#eef1f4;box-sizing:border-box}
|
|
4
6
|
.fv-video-shell{width:min(100%,960px);border-radius:8px;border:1px solid rgba(15,23,42,.1);background:#fff;box-shadow:0 18px 48px rgba(15,23,42,.14);overflow:hidden}
|
|
@@ -7,12 +9,35 @@ const videoStyle = `
|
|
|
7
9
|
.fv-video-heading strong{color:#132235;font-size:16px}
|
|
8
10
|
.fv-video-player{display:block;width:100%;aspect-ratio:16/9;background:#05070a}
|
|
9
11
|
.fv-video-hint{margin:0;padding:12px 18px 16px;color:#64748b;font-size:13px;line-height:1.7}
|
|
12
|
+
.fv-video-software-player{position:relative;width:100%;max-height:min(72vh,720px);overflow:hidden;background:#05070a;color:#fff;outline:none}
|
|
13
|
+
.fv-video-software-canvas{display:block;width:100%;height:100%;object-fit:contain;background:#05070a;cursor:pointer}
|
|
14
|
+
.fv-video-audio-clock{position:absolute;width:1px;height:1px;opacity:0;pointer-events:none}
|
|
15
|
+
.fv-video-software-loading{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(2,6,12,.74);color:#f8fafc;font-size:14px;text-align:center;box-sizing:border-box;z-index:2}
|
|
16
|
+
.fv-video-software-loading[hidden]{display:none}
|
|
17
|
+
.fv-video-software-badge{position:absolute;top:12px;right:12px;padding:4px 8px;border:1px solid rgba(255,255,255,.24);border-radius:999px;background:rgba(2,6,12,.68);color:#e2e8f0;font-size:11px;font-weight:700;z-index:1}
|
|
18
|
+
.fv-video-software-controls{position:absolute;left:0;right:0;bottom:0;display:grid;grid-template-columns:40px auto minmax(80px,1fr) auto 40px 40px;gap:8px;align-items:center;padding:28px 12px 10px;background:linear-gradient(transparent,rgba(2,6,12,.9));box-sizing:border-box;z-index:1}
|
|
19
|
+
.fv-video-software-button{width:36px;height:32px;padding:0;border:0;border-radius:6px;background:rgba(255,255,255,.08);color:#fff;font:700 15px/1 system-ui;cursor:pointer}
|
|
20
|
+
.fv-video-software-button:hover,.fv-video-software-button:focus-visible{background:rgba(255,255,255,.2);outline:2px solid rgba(45,212,191,.8);outline-offset:1px}
|
|
21
|
+
.fv-video-software-time{min-width:42px;color:#f8fafc;font-size:12px;font-variant-numeric:tabular-nums;text-align:center}
|
|
22
|
+
.fv-video-software-seek{width:100%;accent-color:#14b8a6;cursor:pointer}
|
|
23
|
+
.fv-video-compatibility{min-height:320px;display:flex;align-items:center;justify-content:center;padding:32px;background:linear-gradient(135deg,rgba(245,158,11,.12),transparent 46%),#f8fafc;box-sizing:border-box}
|
|
24
|
+
.fv-video-compatibility-card{width:min(100%,620px);padding:24px;border:1px solid rgba(217,119,6,.24);border-radius:8px;background:#fff7ed;color:#7c2d12;box-sizing:border-box}
|
|
25
|
+
.fv-video-compatibility-card span{display:inline-flex;align-items:center;padding:4px 8px;border-radius:999px;background:#ffedd5;color:#9a3412;font-size:12px;font-weight:800}
|
|
26
|
+
.fv-video-compatibility-card strong{display:block;margin-top:12px;color:#7c2d12;font-size:20px;line-height:1.3}
|
|
27
|
+
.fv-video-compatibility-card p{margin:9px 0 0;color:#9a3412;font-size:14px;line-height:1.7}
|
|
28
|
+
.fv-video-compatibility-card code{display:inline-block;margin-top:14px;padding:5px 8px;border-radius:6px;background:rgba(124,45,18,.08);color:#7c2d12;font:600 12px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
10
29
|
[data-viewer-theme='dark'] .fv-video-viewer{background:#101820;color:#e5eef8}
|
|
11
30
|
[data-viewer-theme='dark'] .fv-video-shell{border-color:rgba(148,163,184,.18);background:#111827;box-shadow:0 22px 56px rgba(0,0,0,.32)}
|
|
12
31
|
[data-viewer-theme='dark'] .fv-video-heading{border-color:rgba(148,163,184,.18)}
|
|
13
32
|
[data-viewer-theme='dark'] .fv-video-heading strong{color:#f8fafc}
|
|
14
33
|
[data-viewer-theme='dark'] .fv-video-hint{color:#94a3b8}
|
|
15
|
-
|
|
34
|
+
[data-viewer-theme='dark'] .fv-video-compatibility{background:linear-gradient(135deg,rgba(251,146,60,.13),transparent 46%),#0f172a}
|
|
35
|
+
[data-viewer-theme='dark'] .fv-video-compatibility-card{border-color:rgba(251,146,60,.3);background:#28170f;color:#fed7aa}
|
|
36
|
+
[data-viewer-theme='dark'] .fv-video-compatibility-card span{background:#431d0b;color:#fdba74}
|
|
37
|
+
[data-viewer-theme='dark'] .fv-video-compatibility-card strong,[data-viewer-theme='dark'] .fv-video-compatibility-card p,[data-viewer-theme='dark'] .fv-video-compatibility-card code{color:#fed7aa}
|
|
38
|
+
[data-viewer-theme='dark'] .fv-video-compatibility-card code{background:rgba(251,146,60,.12)}
|
|
39
|
+
@media (prefers-color-scheme:dark){[data-viewer-theme='system'] .fv-video-viewer{background:#101820;color:#e5eef8}[data-viewer-theme='system'] .fv-video-shell{border-color:rgba(148,163,184,.18);background:#111827;box-shadow:0 22px 56px rgba(0,0,0,.32)}[data-viewer-theme='system'] .fv-video-heading{border-color:rgba(148,163,184,.18)}[data-viewer-theme='system'] .fv-video-heading strong{color:#f8fafc}[data-viewer-theme='system'] .fv-video-hint{color:#94a3b8}[data-viewer-theme='system'] .fv-video-compatibility{background:linear-gradient(135deg,rgba(251,146,60,.13),transparent 46%),#0f172a}[data-viewer-theme='system'] .fv-video-compatibility-card{border-color:rgba(251,146,60,.3);background:#28170f;color:#fed7aa}[data-viewer-theme='system'] .fv-video-compatibility-card span{background:#431d0b;color:#fdba74}[data-viewer-theme='system'] .fv-video-compatibility-card strong,[data-viewer-theme='system'] .fv-video-compatibility-card p,[data-viewer-theme='system'] .fv-video-compatibility-card code{color:#fed7aa}[data-viewer-theme='system'] .fv-video-compatibility-card code{background:rgba(251,146,60,.12)}}
|
|
40
|
+
@media (max-width:640px){.fv-video-viewer{padding:10px}.fv-video-software-controls{grid-template-columns:36px minmax(72px,1fr) 36px 36px}.fv-video-software-time{display:none}.fv-video-software-badge{top:8px;right:8px}}
|
|
16
41
|
`;
|
|
17
42
|
const VIDEO_MIME_MAP = {
|
|
18
43
|
m3u8: 'application/vnd.apple.mpegurl',
|
|
@@ -47,6 +72,22 @@ const getMimeType = (type) => {
|
|
|
47
72
|
const createLocalUrl = (buffer, type) => {
|
|
48
73
|
return URL.createObjectURL(new Blob([buffer], { type: getMimeType(type) }));
|
|
49
74
|
};
|
|
75
|
+
class UnsupportedVideoCodecError extends Error {
|
|
76
|
+
constructor(track) {
|
|
77
|
+
super(`The browser could not decode the ${track.label} video track.`);
|
|
78
|
+
this.name = 'UnsupportedVideoCodecError';
|
|
79
|
+
this.track = track;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const createCompatibilityNotice = (track, t) => {
|
|
83
|
+
const notice = createElement('div', 'fv-video-compatibility');
|
|
84
|
+
notice.setAttribute('role', 'alert');
|
|
85
|
+
notice.dataset.codec = track.codec;
|
|
86
|
+
const card = createElement('div', 'fv-video-compatibility-card');
|
|
87
|
+
card.append(createElement('span', '', t('media.video.codecUnsupportedBadge')), createElement('strong', '', t('media.video.codecUnsupportedTitle')), createElement('p', '', t('media.video.codecUnsupportedDescription', { codec: track.label })), createElement('code', '', track.contentType), createElement('p', '', t('media.video.codecUnsupportedAction')));
|
|
88
|
+
notice.append(card);
|
|
89
|
+
return notice;
|
|
90
|
+
};
|
|
50
91
|
/**
|
|
51
92
|
* Pure TypeScript video renderer.
|
|
52
93
|
*
|
|
@@ -56,9 +97,16 @@ const createLocalUrl = (buffer, type) => {
|
|
|
56
97
|
export default async function renderVideo(buffer, target, type, context) {
|
|
57
98
|
const t = createFileViewerTranslator(context === null || context === void 0 ? void 0 : context.options);
|
|
58
99
|
const normalizedType = (type || 'mp4').toLowerCase();
|
|
100
|
+
const mp4VideoTrack = normalizedType === 'mp4'
|
|
101
|
+
? inspectMp4VideoTrack(buffer)
|
|
102
|
+
: undefined;
|
|
103
|
+
const mp4vSoftwareTrack = (mp4VideoTrack === null || mp4VideoTrack === void 0 ? void 0 : mp4VideoTrack.codec) === 'mp4v'
|
|
104
|
+
? extractMp4vSoftwareTrack(buffer)
|
|
105
|
+
: undefined;
|
|
59
106
|
let disposed = false;
|
|
60
107
|
let objectUrl = '';
|
|
61
108
|
let hls = null;
|
|
109
|
+
let softwarePlayer = null;
|
|
62
110
|
const root = createElement('div', 'fv-video-viewer');
|
|
63
111
|
const shell = createElement('section', 'fv-video-shell');
|
|
64
112
|
const heading = createElement('div', 'fv-video-heading');
|
|
@@ -141,9 +189,11 @@ export default async function renderVideo(buffer, target, type, context) {
|
|
|
141
189
|
video.src = source;
|
|
142
190
|
video.load();
|
|
143
191
|
await waitForVideoMetadata(video, context === null || context === void 0 ? void 0 : context.signal);
|
|
192
|
+
if (mp4VideoTrack) {
|
|
193
|
+
await ensureVideoTrackDecoded(video, mp4VideoTrack, context === null || context === void 0 ? void 0 : context.signal);
|
|
194
|
+
}
|
|
144
195
|
};
|
|
145
|
-
const
|
|
146
|
-
disposed = true;
|
|
196
|
+
const releasePlaybackResources = () => {
|
|
147
197
|
hls === null || hls === void 0 ? void 0 : hls.destroy();
|
|
148
198
|
hls = null;
|
|
149
199
|
video.pause();
|
|
@@ -154,18 +204,90 @@ export default async function renderVideo(buffer, target, type, context) {
|
|
|
154
204
|
objectUrl = '';
|
|
155
205
|
}
|
|
156
206
|
};
|
|
207
|
+
const cleanup = () => {
|
|
208
|
+
disposed = true;
|
|
209
|
+
softwarePlayer === null || softwarePlayer === void 0 ? void 0 : softwarePlayer.cleanup();
|
|
210
|
+
softwarePlayer = null;
|
|
211
|
+
releasePlaybackResources();
|
|
212
|
+
};
|
|
157
213
|
try {
|
|
158
214
|
await mountVideo();
|
|
215
|
+
root.dataset.videoState = 'ready';
|
|
159
216
|
}
|
|
160
217
|
catch (error) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
218
|
+
if (error instanceof UnsupportedVideoCodecError) {
|
|
219
|
+
if (error.track.codec === 'mp4v' && mp4vSoftwareTrack) {
|
|
220
|
+
try {
|
|
221
|
+
softwarePlayer = await mountMp4vSoftwarePlayer(buffer, video, mp4vSoftwareTrack, context);
|
|
222
|
+
root.dataset.videoState = 'software-decoder';
|
|
223
|
+
}
|
|
224
|
+
catch (softwareError) {
|
|
225
|
+
releasePlaybackResources();
|
|
226
|
+
root.dataset.videoState = 'unsupported-codec';
|
|
227
|
+
root.dataset.videoError = softwareError instanceof Error
|
|
228
|
+
? softwareError.message
|
|
229
|
+
: String(softwareError);
|
|
230
|
+
const failedPlayer = shell.querySelector('.fv-video-software-player');
|
|
231
|
+
const failedElement = failedPlayer || video;
|
|
232
|
+
failedElement.replaceWith(createCompatibilityNotice(error.track, t));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
releasePlaybackResources();
|
|
237
|
+
root.dataset.videoState = 'unsupported-codec';
|
|
238
|
+
video.replaceWith(createCompatibilityNotice(error.track, t));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
cleanup();
|
|
243
|
+
target.replaceChildren();
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
164
246
|
}
|
|
165
247
|
return createRenderedInstance(target, () => {
|
|
166
248
|
cleanup();
|
|
167
249
|
});
|
|
168
250
|
}
|
|
251
|
+
const ensureVideoTrackDecoded = async (video, track, signal) => {
|
|
252
|
+
if (video.videoWidth > 0 && video.videoHeight > 0)
|
|
253
|
+
return;
|
|
254
|
+
if (!video.canPlayType(track.contentType)) {
|
|
255
|
+
throw new UnsupportedVideoCodecError(track);
|
|
256
|
+
}
|
|
257
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted)
|
|
258
|
+
throw new DOMException('The video request was aborted.', 'AbortError');
|
|
259
|
+
await new Promise((resolve, reject) => {
|
|
260
|
+
const timeoutId = window.setTimeout(() => {
|
|
261
|
+
cleanup();
|
|
262
|
+
reject(new UnsupportedVideoCodecError(track));
|
|
263
|
+
}, 1500);
|
|
264
|
+
const cleanup = () => {
|
|
265
|
+
window.clearTimeout(timeoutId);
|
|
266
|
+
video.removeEventListener('resize', onReady);
|
|
267
|
+
video.removeEventListener('loadeddata', onReady);
|
|
268
|
+
video.removeEventListener('error', onError);
|
|
269
|
+
signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
|
|
270
|
+
};
|
|
271
|
+
const onReady = () => {
|
|
272
|
+
if (video.videoWidth <= 0 || video.videoHeight <= 0)
|
|
273
|
+
return;
|
|
274
|
+
cleanup();
|
|
275
|
+
resolve();
|
|
276
|
+
};
|
|
277
|
+
const onError = () => {
|
|
278
|
+
cleanup();
|
|
279
|
+
reject(video.error || new UnsupportedVideoCodecError(track));
|
|
280
|
+
};
|
|
281
|
+
const onAbort = () => {
|
|
282
|
+
cleanup();
|
|
283
|
+
reject(new DOMException('The video request was aborted.', 'AbortError'));
|
|
284
|
+
};
|
|
285
|
+
video.addEventListener('resize', onReady);
|
|
286
|
+
video.addEventListener('loadeddata', onReady);
|
|
287
|
+
video.addEventListener('error', onError, { once: true });
|
|
288
|
+
signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort, { once: true });
|
|
289
|
+
});
|
|
290
|
+
};
|
|
169
291
|
const waitForVideoMetadata = async (video, signal) => {
|
|
170
292
|
if (video.readyState >= HTMLMediaElement.HAVE_METADATA)
|
|
171
293
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-media",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone audio and video renderer plugin for File Viewer with native media playback, HLS fallback, MIDI parsing, and offline-friendly lazy loading.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"LICENSE"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@file-viewer/core": "2.
|
|
58
|
+
"@file-viewer/core": "2.3.0",
|
|
59
59
|
"@tonejs/midi": "^2.0.28",
|
|
60
60
|
"hls.js": "^1.6.16"
|
|
61
61
|
},
|
|
@@ -64,7 +64,11 @@
|
|
|
64
64
|
},
|
|
65
65
|
"license": "Apache-2.0",
|
|
66
66
|
"scripts": {
|
|
67
|
-
"build": "tsc -b tsconfig.json",
|
|
68
|
-
"type-check": "tsc -b tsconfig.json"
|
|
67
|
+
"build": "tsc -b tsconfig.json && node scripts/copy-mp4v-assets.mjs",
|
|
68
|
+
"type-check": "tsc -b tsconfig.json",
|
|
69
|
+
"build:mp4v-decoder": "node scripts/build-mp4v-decoder.mjs",
|
|
70
|
+
"verify:mp4v-boundary": "node scripts/verify-mp4v-boundary.mjs",
|
|
71
|
+
"verify:mp4v-demo-dist": "npm exec --yes --package playwright -- node scripts/verify-mp4v-demo-dist.mjs",
|
|
72
|
+
"verify:mp4v-black-screen": "pnpm build && pnpm verify:mp4v-boundary && npm exec --yes --package playwright -- node scripts/verify-mp4v-black-screen.mjs"
|
|
69
73
|
}
|
|
70
74
|
}
|