mp4box.js
mp4box.js copied to clipboard
Video track not played
Hello i try to add audio track to file with only video track but after file saved, video track does not play i have tried load and save files and it is bad after save(just few KB) here is my code
<html>
<script src="mp4box.all.js" ></script>
<body>
<script>
function makeRequest(method, url) {
return new Promise(function (resolve, reject) {
let xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open(method, url);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send();
});
}
function loadFromBuffer(file, buffer) {
return new Promise(function (resolve, reject) {
file.onError = function(e) {
reject(e);
};
file.onReady = function(info) {
resolve(info);
};
let tempBuffer = buffer;
tempBuffer.fileStart = 0;
if (!tempBuffer.fileStart) {
// IE does not support adding properties to an ArrayBuffer generated by XHR
tempBuffer = buffer.slice(0);
tempBuffer.fileStart = 0;
}
file.appendBuffer(tempBuffer, true);
file.flush();
});
}
var videoUrl = "./video.mp4";
async function start() {
let videoBuffer = await makeRequest("GET", videoUrl);
let videofile = MP4Box.createFile();
let videoInfo = await loadFromBuffer(videofile, videoBuffer);
videofile.save("test.mp4");
}
start();
</script>
</body>
</html>
``
sample vido but i also try other videos same problem
https://user-images.githubusercontent.com/5040118/156850576-c539ede5-865c-404e-8ed6-447483190162.mp4
`
Unfortunately, at this stage, you cannot use save
on a file to which you appended data. I need to think about how to add this feature. So far save
is used only when the file was not parsed.