-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support reconstructing the length and cues in a webm #2
Comments
Please use the EBMLReader class and tools.putRefinedMetaData function. I wrote this to solve the problem. Here is the example code to insert example: https://github.com/legokichi/ts-ebml/blob/88beee06d5dad0e36c9b082d7da2d7eb227ca3b1/src/seekable_example.ts |
https://www.matroska.org/technical/order/index.html
Is it not necessary to write the position of Cue in SeekHead at the top of the file? |
Matroska might allow Cues and SeekHead at the end, but WebM doesn't, I believe: https://www.webmproject.org/docs/container/#muxer-guidelines. |
The most interesting Cr bug is https://crbug.com/642012, but IMHO we should not try to complicate the c++ code and instead should try to do this as a polyfill, as I argued in w3c/mediacapture-record#119. That aside, |
I published in @ 1.4.0. usage import EBMLReader from 'ts-ebml/lib/EBMLReader';
import {Decoder, Encoder, tools} from "ts-ebml";
import * as EBML from "ts-ebml";
main("foo.webm");
async function main(file: string){
const res = await fetch(file);
const webm_buf = await res.arrayBuffer();
const elms = new Decoder().decode(webm_buf);
let metadataElms: EBML.EBMLElementDetail[] = [];
let metadataSize = 0;
let last_duration = 0;
const cluster_ptrs: number[] = [];
const reader = new EBMLReader();
reader.logging = true;
reader.addListener("metadata", ({data, metadataSize: size})=>{
metadataElms = data;
metadataSize = size;
});
reader.addListener("cluster_ptr", (ptr)=>{
cluster_ptrs.push(ptr);
});
reader.addListener("duration", ({timecodeScale, duration})=>{
last_duration = duration;
});
elms.forEach((elm)=>{ reader.read(elm); });
reader.stop();
const refinedMetadataElms = tools.putRefinedMetaData(metadataElms, cluster_ptrs, last_duration);
const refinedMetadataBuf = new Encoder().encode(refinedMetadataElms);
const body = webm_buf.slice(metadataSize);
const raw_webM = new Blob([webm_buf], {type: "video/webm"});
const refinedWebM = new Blob([refinedMetadataBuf, body], {type: "video/webm"});
const raw_video = await fetchVideo(URL.createObjectURL(raw_webM));
const refined_video = await fetchVideo(URL.createObjectURL(refinedWebM));
document.body.appendChild(raw_video);
document.body.appendChild(refined_video);
}
function fetchVideo(src: string): Promise<HTMLVideoElement>{
return new Promise((resolve, reject)=>{
const video = document.createElement("video");
video.src = src;
video.controls = true;
video.onloadeddata = ()=>{
video.onloadeddata = <any>null;
resolve(video);
};
video.onerror = (err)=>{
video.onerror = <any>null;
reject(err);
};
});
} But this method of inserting SeekHead does not work well with Firefox. |
https://bugzilla.mozilla.org/show_bug.cgi?id=1356833 After all it was my mistake, the file was broken. here is the new demo: https://jsfiddle.net/1nrx33gd/1/ |
This is awesome! Thanks! |
@miguelao keep in mind that the WebM spec says that it does not recommend Additionally, if you run a non-seekable WebM file through and |
update: I stopped adding
see also |
Hi! After w3c/mediacapture-record#119 (comment) I have been playing with emscripten-compiling libwebm, but I found this repo that might be able to produce the same result using more succinct code. The problem is essentially that MediaRecorder produces files that are not seekable, one because they have no
Duration
and second, perhaps, because they have noCues
. Is it something you could help with?The text was updated successfully, but these errors were encountered: