问题
I am writing a software that manipulates camera stream video in firefox.
I am generating a Blob with video type recorded with MediaRecorder API.
What i am doing to save the blob as video in local storage is using FileSaver library :
FileSaver.saveAs(BlobVideo,"video.mp4");
It seems the video doesnt have any max duration, so i cannot navigate in timeline in my newly generated video in VLC, for example.
Is there a way to set duration metadatas on a blob video?
回答1:
This question is an almost duplicate of this other one. (But since there is a bounty on it, we can't vote to close)
This is a known chrome bug.
You can have this duration from the browser itself by loading the video, setting its currentTime
to some extra-value, then reading the duration, but you won't have it attached to the file itself, at least not until the bug has been fixed.
回答2:
Until the chrome bug that Kaiido mentioned gets fixed, this worked for me:
while(video.duration === Infinity) {
await new Promise(r => setTimeout(r, 1000));
video.currentTime = 10000000*Math.random();
}
let duration = video.duration;
It would probably be a better idea to listen for the "durationchange" event though, rather than having the arbitrary 1 second pauses.
来源:https://stackoverflow.com/questions/38062864/blob-video-duration-metadata