Update API
This commit is contained in:
parent
7ced0478da
commit
edb05a6572
@ -21,7 +21,7 @@
|
|||||||
const { name } = files[0];
|
const { name } = files[0];
|
||||||
ffmpeg.FS.writeFile(name, await fetchFile(files[0]));
|
ffmpeg.FS.writeFile(name, await fetchFile(files[0]));
|
||||||
message.innerHTML = 'Start transcoding';
|
message.innerHTML = 'Start transcoding';
|
||||||
await ffmpeg.exec(['-i', name, 'output.mp4']);
|
await ffmpeg.exec('-i', name, 'output.mp4');
|
||||||
message.innerHTML = 'Complete transcoding';
|
message.innerHTML = 'Complete transcoding';
|
||||||
const data = ffmpeg.FS.readFile('output.mp4');
|
const data = ffmpeg.FS.readFile('output.mp4');
|
||||||
|
|
||||||
|
@ -3,5 +3,5 @@ import createFFmpeg from "@ffmpeg/ffmpeg";
|
|||||||
void (async () => {
|
void (async () => {
|
||||||
const ffmpeg = await createFFmpeg();
|
const ffmpeg = await createFFmpeg();
|
||||||
ffmpeg.setLogger(({ message }) => console.log(message));
|
ffmpeg.setLogger(({ message }) => console.log(message));
|
||||||
console.log("return code: ", ffmpeg.exec(["-h"]));
|
console.log("return code: ", ffmpeg.exec("-h"));
|
||||||
})();
|
})();
|
||||||
|
@ -13,5 +13,5 @@ void (async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ffmpeg.FS.writeFile("audio.wav", wav);
|
ffmpeg.FS.writeFile("audio.wav", wav);
|
||||||
console.log("return code: ", ffmpeg.exec(["-i", "audio.wav", "audio.mp4"]));
|
console.log("return code: ", ffmpeg.exec("-i", "audio.wav", "audio.mp4"));
|
||||||
})();
|
})();
|
||||||
|
@ -13,5 +13,5 @@ void (async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
ffmpeg.FS.writeFile("video.avi", avi);
|
ffmpeg.FS.writeFile("video.avi", avi);
|
||||||
console.log("return code: ", ffmpeg.exec(["-i", "video.avi", "video.mp4"]));
|
console.log("return code: ", ffmpeg.exec("-i", "video.avi", "video.mp4"));
|
||||||
})();
|
})();
|
||||||
|
@ -54,11 +54,11 @@ describe("exec()", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should output help", () => {
|
it("should output help", () => {
|
||||||
expect(ffmpeg.exec(["-h"])).to.equal(0);
|
expect(ffmpeg.exec("-h")).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should transcode", () => {
|
it("should transcode", () => {
|
||||||
expect(ffmpeg.exec(["-i", "video.mp4", "video.avi"])).to.equal(0);
|
expect(ffmpeg.exec("-i", "video.mp4", "video.avi")).to.equal(0);
|
||||||
const out = ffmpeg.FS.readFile("video.avi");
|
const out = ffmpeg.FS.readFile("video.avi");
|
||||||
expect(out.length).to.not.equal(0);
|
expect(out.length).to.not.equal(0);
|
||||||
ffmpeg.FS.unlink("video.avi");
|
ffmpeg.FS.unlink("video.avi");
|
||||||
@ -74,7 +74,7 @@ describe("setTimeout()", () => {
|
|||||||
|
|
||||||
it("should timeout", () => {
|
it("should timeout", () => {
|
||||||
ffmpeg.setTimeout(1); // timeout after 1ms
|
ffmpeg.setTimeout(1); // timeout after 1ms
|
||||||
expect(ffmpeg.exec(["-i", "video.mp4", "video.avi"])).to.equal(1);
|
expect(ffmpeg.exec("-i", "video.mp4", "video.avi")).to.equal(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ describe("setLogger()", () => {
|
|||||||
it("should handle logs", () => {
|
it("should handle logs", () => {
|
||||||
const logs = [];
|
const logs = [];
|
||||||
ffmpeg.setLogger(({ message }) => logs.push(message));
|
ffmpeg.setLogger(({ message }) => logs.push(message));
|
||||||
ffmpeg.exec(["-h"]);
|
ffmpeg.exec("-h");
|
||||||
expect(logs.length).to.not.equal(0);
|
expect(logs.length).to.not.equal(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -103,7 +103,7 @@ describe("setProgress()", () => {
|
|||||||
it("should handle progress", () => {
|
it("should handle progress", () => {
|
||||||
let progress = 0;
|
let progress = 0;
|
||||||
ffmpeg.setProgress((_progress) => (progress = _progress));
|
ffmpeg.setProgress((_progress) => (progress = _progress));
|
||||||
expect(ffmpeg.exec(["-i", "video.mp4", "video.avi"])).to.equal(0);
|
expect(ffmpeg.exec("-i", "video.mp4", "video.avi")).to.equal(0);
|
||||||
expect(progress).to.equal(1);
|
expect(progress).to.equal(1);
|
||||||
ffmpeg.FS.unlink("video.avi");
|
ffmpeg.FS.unlink("video.avi");
|
||||||
});
|
});
|
||||||
|
@ -53,11 +53,11 @@ describe("exec()", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should output help", () => {
|
it("should output help", () => {
|
||||||
expect(ffmpeg.exec(["-h"])).to.equal(0);
|
expect(ffmpeg.exec("-h")).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should transcode", () => {
|
it("should transcode", () => {
|
||||||
expect(ffmpeg.exec(["-i", "video.mp4", "video.avi"])).to.equal(0);
|
expect(ffmpeg.exec("-i", "video.mp4", "video.avi")).to.equal(0);
|
||||||
const out = ffmpeg.FS.readFile("video.avi");
|
const out = ffmpeg.FS.readFile("video.avi");
|
||||||
expect(out.length).to.not.equal(0);
|
expect(out.length).to.not.equal(0);
|
||||||
ffmpeg.FS.unlink("video.avi");
|
ffmpeg.FS.unlink("video.avi");
|
||||||
@ -73,7 +73,7 @@ describe("setTimeout()", () => {
|
|||||||
|
|
||||||
it("should timeout", () => {
|
it("should timeout", () => {
|
||||||
ffmpeg.setTimeout(1); // timeout after 1ms
|
ffmpeg.setTimeout(1); // timeout after 1ms
|
||||||
expect(ffmpeg.exec(["-i", "video.mp4", "video.avi"])).to.equal(1);
|
expect(ffmpeg.exec("-i", "video.mp4", "video.avi")).to.equal(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ describe("setLogger()", () => {
|
|||||||
it("should handle logs", () => {
|
it("should handle logs", () => {
|
||||||
const logs = [];
|
const logs = [];
|
||||||
ffmpeg.setLogger(({ message }) => logs.push(message));
|
ffmpeg.setLogger(({ message }) => logs.push(message));
|
||||||
ffmpeg.exec(["-h"]);
|
ffmpeg.exec("-h");
|
||||||
expect(logs.length).to.not.equal(0);
|
expect(logs.length).to.not.equal(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -102,7 +102,7 @@ describe("setProgress()", () => {
|
|||||||
it("should handle progress", () => {
|
it("should handle progress", () => {
|
||||||
let progress = 0;
|
let progress = 0;
|
||||||
ffmpeg.setProgress((_progress) => (progress = _progress));
|
ffmpeg.setProgress((_progress) => (progress = _progress));
|
||||||
expect(ffmpeg.exec(["-i", "video.mp4", "video.avi"])).to.equal(0);
|
expect(ffmpeg.exec("-i", "video.mp4", "video.avi")).to.equal(0);
|
||||||
expect(progress).to.equal(1);
|
expect(progress).to.equal(1);
|
||||||
ffmpeg.FS.unlink("video.avi");
|
ffmpeg.FS.unlink("video.avi");
|
||||||
});
|
});
|
||||||
|
@ -50,7 +50,7 @@ function printErr(message) {
|
|||||||
Module["logger"]({ type: "stderr", message });
|
Module["logger"]({ type: "stderr", message });
|
||||||
}
|
}
|
||||||
|
|
||||||
function exec(_args) {
|
function exec(..._args) {
|
||||||
const args = [...Module["DEFAULT_ARGS"], ..._args];
|
const args = [...Module["DEFAULT_ARGS"], ..._args];
|
||||||
try {
|
try {
|
||||||
Module["_ffmpeg"](args.length, stringsToPtr(args));
|
Module["_ffmpeg"](args.length, stringsToPtr(args));
|
||||||
|
2
src/types/ffmpeg/ffmpeg.d.ts
vendored
2
src/types/ffmpeg/ffmpeg.d.ts
vendored
@ -24,7 +24,7 @@ export interface FFmpegModule {
|
|||||||
ret: number;
|
ret: number;
|
||||||
timeout: number;
|
timeout: number;
|
||||||
|
|
||||||
exec: (args: string[]) => number;
|
exec: (...args: string[]) => number;
|
||||||
reset: () => void;
|
reset: () => void;
|
||||||
setLogger: (logger: (log: Log) => void) => void;
|
setLogger: (logger: (log: Log) => void) => void;
|
||||||
setTimeout: (timeout: number) => void;
|
setTimeout: (timeout: number) => void;
|
||||||
|
Loading…
Reference in New Issue
Block a user