mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
109 lines
2.3 KiB
HTML
109 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<script src="../dist/metamuxer.js"></script>
|
|
|
|
<script type="module">
|
|
const fileInput = document.createElement('input');
|
|
fileInput.type = 'file';
|
|
document.body.append(fileInput);
|
|
|
|
const progress = document.createElement('progress');
|
|
progress.max = 1;
|
|
document.body.append(progress);
|
|
|
|
fileInput.addEventListener('change', async () => {
|
|
const file = fileInput.files[0];
|
|
|
|
const source = new Metamuxer.BlobSource(file);
|
|
const target = new Metamuxer.BufferTarget();
|
|
const outputFormat = new Metamuxer.Mp4OutputFormat({
|
|
fastStart: 'fragmented'
|
|
})
|
|
|
|
const button = document.createElement('button');
|
|
button.textContent = 'Cancel';
|
|
button.onclick = () => conversion.cancel();
|
|
document.body.append(button);
|
|
|
|
const conversion = await Metamuxer.Conversion.init({
|
|
input: new Metamuxer.Input({
|
|
formats: Metamuxer.ALL_FORMATS,
|
|
source
|
|
}),
|
|
output: new Metamuxer.Output({
|
|
format: outputFormat,
|
|
target
|
|
}),
|
|
audio: {
|
|
//discard: true
|
|
},
|
|
/*
|
|
video: {
|
|
discard: true,
|
|
bitrate: Metamuxer.QUALITY_VERY_HIGH,
|
|
//bitrate: Metamuxer.QUALITY_VERY_HIGH
|
|
codec: 'av1',
|
|
//width: 800,
|
|
//fit: 'fill',
|
|
//rotate: 90,
|
|
},
|
|
audio: {
|
|
bitrate: Metamuxer.QUALITY_HIGH,
|
|
codec: 'aac',
|
|
},
|
|
*/
|
|
/*
|
|
video: {
|
|
codec: 'avc',
|
|
},
|
|
audio: {
|
|
codec: 'mp3',
|
|
bitrate: 320000
|
|
},
|
|
*/
|
|
video: {
|
|
//forceReencode: true,
|
|
//rotate: 90
|
|
//width: 720 ?? 2160,
|
|
//height: 1280 ?? 3840,
|
|
fit: 'contain',
|
|
rotate: 90,
|
|
width: 512,
|
|
height: 512,
|
|
//width: 200,
|
|
//height: 100,
|
|
},
|
|
trim: {
|
|
start: 0,
|
|
end: 10
|
|
},
|
|
computeProgress: true
|
|
});
|
|
console.log(conversion);
|
|
|
|
conversion.onProgress = () => progress.value = conversion.progress;
|
|
|
|
console.time();
|
|
await conversion.execute();
|
|
console.timeEnd()
|
|
|
|
console.log("Done", target.buffer);
|
|
|
|
const video = document.createElement('video');
|
|
video.src = URL.createObjectURL(new Blob([target.buffer]));
|
|
video.controls = true;
|
|
document.body.append(video);
|
|
video.play();
|
|
|
|
//download(new Blob([target.buffer]), 'converted' + outputFormat.fileExtension);
|
|
|
|
function download(blob, filename) {
|
|
const url = URL.createObjectURL(blob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = filename;
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
});
|
|
</script> |