Update API

This commit is contained in:
Jerome Wu 2022-09-23 17:33:01 +08:00
parent 7ced0478da
commit edb05a6572
8 changed files with 16 additions and 16 deletions

View File

@ -21,7 +21,7 @@
const { name } = files[0];
ffmpeg.FS.writeFile(name, await fetchFile(files[0]));
message.innerHTML = 'Start transcoding';
await ffmpeg.exec(['-i', name, 'output.mp4']);
await ffmpeg.exec('-i', name, 'output.mp4');
message.innerHTML = 'Complete transcoding';
const data = ffmpeg.FS.readFile('output.mp4');

View File

@ -3,5 +3,5 @@ import createFFmpeg from "@ffmpeg/ffmpeg";
void (async () => {
const ffmpeg = await createFFmpeg();
ffmpeg.setLogger(({ message }) => console.log(message));
console.log("return code: ", ffmpeg.exec(["-h"]));
console.log("return code: ", ffmpeg.exec("-h"));
})();

View File

@ -13,5 +13,5 @@ void (async () => {
);
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"));
})();

View File

@ -13,5 +13,5 @@ void (async () => {
);
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"));
})();

View File

@ -54,11 +54,11 @@ describe("exec()", () => {
});
it("should output help", () => {
expect(ffmpeg.exec(["-h"])).to.equal(0);
expect(ffmpeg.exec("-h")).to.equal(0);
});
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");
expect(out.length).to.not.equal(0);
ffmpeg.FS.unlink("video.avi");
@ -74,7 +74,7 @@ describe("setTimeout()", () => {
it("should timeout", () => {
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", () => {
const logs = [];
ffmpeg.setLogger(({ message }) => logs.push(message));
ffmpeg.exec(["-h"]);
ffmpeg.exec("-h");
expect(logs.length).to.not.equal(0);
});
});
@ -103,7 +103,7 @@ describe("setProgress()", () => {
it("should handle progress", () => {
let progress = 0;
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);
ffmpeg.FS.unlink("video.avi");
});

View File

@ -53,11 +53,11 @@ describe("exec()", () => {
});
it("should output help", () => {
expect(ffmpeg.exec(["-h"])).to.equal(0);
expect(ffmpeg.exec("-h")).to.equal(0);
});
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");
expect(out.length).to.not.equal(0);
ffmpeg.FS.unlink("video.avi");
@ -73,7 +73,7 @@ describe("setTimeout()", () => {
it("should timeout", () => {
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", () => {
const logs = [];
ffmpeg.setLogger(({ message }) => logs.push(message));
ffmpeg.exec(["-h"]);
ffmpeg.exec("-h");
expect(logs.length).to.not.equal(0);
});
});
@ -102,7 +102,7 @@ describe("setProgress()", () => {
it("should handle progress", () => {
let progress = 0;
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);
ffmpeg.FS.unlink("video.avi");
});

View File

@ -50,7 +50,7 @@ function printErr(message) {
Module["logger"]({ type: "stderr", message });
}
function exec(_args) {
function exec(..._args) {
const args = [...Module["DEFAULT_ARGS"], ..._args];
try {
Module["_ffmpeg"](args.length, stringsToPtr(args));

View File

@ -24,7 +24,7 @@ export interface FFmpegModule {
ret: number;
timeout: number;
exec: (args: string[]) => number;
exec: (...args: string[]) => number;
reset: () => void;
setLogger: (logger: (log: Log) => void) => void;
setTimeout: (timeout: number) => void;