Skip to content

Commit 757174c

Browse files
committed
concat demux bug
1 parent 8956937 commit 757174c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

examples/browser/concatDemux.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<html>
2+
<head>
3+
<script src="/dist/ffmpeg.dev.js"></script>
4+
<style>
5+
html,
6+
body {
7+
margin: 0;
8+
width: 100%;
9+
height: 100%;
10+
}
11+
12+
body {
13+
display: flex;
14+
flex-direction: column;
15+
align-items: center;
16+
}
17+
</style>
18+
</head>
19+
20+
<body>
21+
<h3>Upload a Video File</h3>
22+
<video id="output-video" controls></video><br />
23+
<input type="file" id="uploader" />
24+
<p id="message"></p>
25+
<script>
26+
const { createWorker } = FFmpeg;
27+
const worker = createWorker({
28+
corePath: "../../node_modules/@ffmpeg/core/ffmpeg-core.js",
29+
logger: ({ message }) => console.log(message)
30+
});
31+
32+
const transcode = async ({ target: { files } }) => {
33+
const message = document.getElementById("message");
34+
const { name } = files[0];
35+
message.innerHTML = "Loading ffmpeg-core.js";
36+
await worker.load();
37+
message.innerHTML = "Start Concating";
38+
await worker.write(name, files[0]);
39+
const textFileName = "list.txt";
40+
await worker.writeText(textFileName, `file ${name}\nfile ${name}`);
41+
await worker.concatDemux(textFileName, "output.mp4");
42+
message.innerHTML = "Complete Concating";
43+
const { data } = await worker.read("output.mp4");
44+
const video = document.getElementById("output-video");
45+
video.src = URL.createObjectURL(
46+
new Blob([data.buffer], { type: "video/mp4" })
47+
);
48+
};
49+
const elm = document.getElementById("uploader");
50+
elm.addEventListener("change", transcode);
51+
</script>
52+
</body>
53+
</html>

src/createWorker.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ module.exports = (_options = {}) => {
122122
)
123123
);
124124

125+
const concatDemux = (texFilePath, outputPath, opts = '', del = false, jobId) => {
126+
run(`${opts} -f concat -safe 0 -i /data/${texFilePath} -c copy ${outputPath}`,
127+
{ del },
128+
jobId);
129+
};
130+
125131
const ls = (path, jobId) => (
126132
startJob(createJob({
127133
id: jobId, action: 'ls', payload: { path },
@@ -175,6 +181,7 @@ module.exports = (_options = {}) => {
175181
run,
176182
transcode,
177183
trim,
184+
concatDemux,
178185
ls,
179186
terminate,
180187
};

0 commit comments

Comments
 (0)