concatDemuxer with example
This commit is contained in:
parent
68fd03d55d
commit
bfdb83b41b
57
examples/browser/concatDemuxer.html
Normal file
57
examples/browser/concatDemuxer.html
Normal file
@ -0,0 +1,57 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="/dist/ffmpeg.dev.js"></script>
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3>Select multiple video files to Concatenate</h3>
|
||||
<video id="output-video" controls></video><br />
|
||||
<input type="file" id="uploader" multiple />
|
||||
<p id="message"></p>
|
||||
<script>
|
||||
const { createWorker } = FFmpeg;
|
||||
const worker = createWorker({
|
||||
corePath: "../../node_modules/@ffmpeg/core/ffmpeg-core.js",
|
||||
logger: ({ message }) => console.log(message)
|
||||
});
|
||||
|
||||
const transcode = async ({ target: { files } }) => {
|
||||
const message = document.getElementById("message");
|
||||
message.innerHTML = "Loading ffmpeg-core.js";
|
||||
await worker.load();
|
||||
message.innerHTML = "Start Concating";
|
||||
const inputPaths = [];
|
||||
for (const file of files) {
|
||||
const { name } = file;
|
||||
await worker.write(name, file);
|
||||
inputPaths.push(name);
|
||||
}
|
||||
await worker.concatDemuxer(inputPaths, "output.mp4");
|
||||
message.innerHTML = "Complete Concating";
|
||||
const { data } = await worker.read("output.mp4");
|
||||
const video = document.getElementById("output-video");
|
||||
video.src = URL.createObjectURL(
|
||||
new Blob([data.buffer], {
|
||||
type: "video/mp4"
|
||||
})
|
||||
);
|
||||
};
|
||||
const elm = document.getElementById("uploader");
|
||||
elm.addEventListener("change", transcode);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user