mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 13:53:53 +02:00
Add media conversion utility function, fix fragment/cluster reading issues, expand color space logic, add qualitative bitrates, & many other fixes and improvements
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<!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()
|
||||
|
||||
console.time()
|
||||
const res = await Metamuxer.convert({
|
||||
input: new Metamuxer.Input({
|
||||
formats: Metamuxer.ALL_FORMATS,
|
||||
source
|
||||
}),
|
||||
output: new Metamuxer.Output({
|
||||
format: outputFormat,
|
||||
target
|
||||
}),
|
||||
/*
|
||||
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',
|
||||
},
|
||||
*/
|
||||
audio: {
|
||||
discard: true
|
||||
},
|
||||
trim: {
|
||||
start: 0,
|
||||
end: 60
|
||||
},
|
||||
onProgress: (event) => {
|
||||
progress.value = event.completion;
|
||||
}
|
||||
});
|
||||
console.timeEnd()
|
||||
console.log(res)
|
||||
|
||||
console.log("Done", target.buffer);
|
||||
download(new Blob([target.buffer]), 'converted' + outputFormat.getFileExtension());
|
||||
|
||||
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>
|
||||
+15
-23
@@ -6,32 +6,23 @@
|
||||
const fileInput = document.createElement('input');
|
||||
fileInput.type = 'file';
|
||||
document.body.append(fileInput);
|
||||
|
||||
/*
|
||||
const encoder = new AudioEncoder({
|
||||
output: console.log,
|
||||
error: console.error
|
||||
});
|
||||
encoder.configure({
|
||||
codec: 'vorbis',
|
||||
numberOfChannels: 2,
|
||||
sampleRate: 48000,
|
||||
bitrate: 128000
|
||||
});
|
||||
|
||||
let audioData = new AudioData({
|
||||
format: 'f32',
|
||||
numberOfChannels: 2,
|
||||
sampleRate: 48000,
|
||||
timestamp: 0,
|
||||
data: new Float32Array(2 * 48000),
|
||||
numberOfFrames: 48000
|
||||
});
|
||||
encoder.encode(audioData);
|
||||
*/
|
||||
|
||||
fileInput.addEventListener('change', async () => {
|
||||
const file = fileInput.files[0];
|
||||
const source = new Metamuxer.BlobSource(file);
|
||||
|
||||
const input = new Metamuxer.Input({
|
||||
formats: Metamuxer.ALL_FORMATS,
|
||||
source
|
||||
});
|
||||
|
||||
const videoTrack = await input.getPrimaryVideoTrack();
|
||||
const sink = new Metamuxer.EncodedVideoSampleSink(videoTrack);
|
||||
|
||||
console.log(await sink.getSample(16));
|
||||
console.log(await sink.getFirstSample());
|
||||
|
||||
/*
|
||||
const source = new Metamuxer.BufferSource(await file.arrayBuffer()) ?? new Metamuxer.BlobSource(file);
|
||||
|
||||
const start = performance.now();
|
||||
@@ -45,6 +36,7 @@
|
||||
target: new Metamuxer.BufferTarget()
|
||||
});
|
||||
output.start();
|
||||
*/
|
||||
|
||||
/*
|
||||
const audioTrack = await input.getPrimaryAudioTrack();
|
||||
|
||||
Reference in New Issue
Block a user