ffprobe command was added. Missing definitions were added. Code reformat.
This commit is contained in:
@@ -62,6 +62,7 @@ export class FFmpeg {
|
||||
case FFMessageType.MOUNT:
|
||||
case FFMessageType.UNMOUNT:
|
||||
case FFMessageType.EXEC:
|
||||
case FFMessageType.FFPROBE:
|
||||
case FFMessageType.WRITE_FILE:
|
||||
case FFMessageType.READ_FILE:
|
||||
case FFMessageType.DELETE_FILE:
|
||||
@@ -249,6 +250,42 @@ export class FFmpeg {
|
||||
signal
|
||||
) as Promise<number>;
|
||||
|
||||
/**
|
||||
* Execute ffprobe command.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const ffmpeg = new FFmpeg();
|
||||
* await ffmpeg.load();
|
||||
* await ffmpeg.writeFile("video.avi", ...);
|
||||
* // Getting duration of a video in seconds: ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.avi -o output.txt
|
||||
* await ffmpeg.ffprobe(["-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", "video.avi", "-o", "output.txt"]);
|
||||
* const data = ffmpeg.readFile("output.txt");
|
||||
* ```
|
||||
*
|
||||
* @returns `0` if no error, `!= 0` if timeout (1) or error.
|
||||
* @category FFmpeg
|
||||
*/
|
||||
public ffprobe = (
|
||||
/** ffprobe command line args */
|
||||
args: string[],
|
||||
/**
|
||||
* milliseconds to wait before stopping the command execution.
|
||||
*
|
||||
* @defaultValue -1
|
||||
*/
|
||||
timeout = -1,
|
||||
{ signal }: FFMessageOptions = {}
|
||||
): Promise<number> =>
|
||||
this.#send(
|
||||
{
|
||||
type: FFMessageType.FFPROBE,
|
||||
data: { args, timeout },
|
||||
},
|
||||
undefined,
|
||||
signal
|
||||
) as Promise<number>;
|
||||
|
||||
/**
|
||||
* Terminate all ongoing API calls and terminate web worker.
|
||||
* `FFmpeg.load()` must be called again before calling any other APIs.
|
||||
|
||||
@@ -7,6 +7,7 @@ export const CORE_URL = `https://unpkg.com/@ffmpeg/core@${CORE_VERSION}/dist/umd
|
||||
export enum FFMessageType {
|
||||
LOAD = "LOAD",
|
||||
EXEC = "EXEC",
|
||||
FFPROBE = "FFPROBE",
|
||||
WRITE_FILE = "WRITE_FILE",
|
||||
READ_FILE = "READ_FILE",
|
||||
DELETE_FILE = "DELETE_FILE",
|
||||
|
||||
@@ -100,6 +100,14 @@ const exec = ({ args, timeout = -1 }: FFMessageExecData): ExitCode => {
|
||||
return ret;
|
||||
};
|
||||
|
||||
const ffprobe = ({ args, timeout = -1 }: FFMessageExecData): ExitCode => {
|
||||
ffmpeg.setTimeout(timeout);
|
||||
ffmpeg.ffprobe(...args);
|
||||
const ret = ffmpeg.ret;
|
||||
ffmpeg.reset();
|
||||
return ret;
|
||||
};
|
||||
|
||||
const writeFile = ({ path, data }: FFMessageWriteFileData): OK => {
|
||||
ffmpeg.FS.writeFile(path, data);
|
||||
return true;
|
||||
@@ -170,6 +178,9 @@ self.onmessage = async ({
|
||||
case FFMessageType.EXEC:
|
||||
data = exec(_data as FFMessageExecData);
|
||||
break;
|
||||
case FFMessageType.FFPROBE:
|
||||
data = ffprobe(_data as FFMessageExecData);
|
||||
break;
|
||||
case FFMessageType.WRITE_FILE:
|
||||
data = writeFile(_data as FFMessageWriteFileData);
|
||||
break;
|
||||
|
||||
31
packages/types/types/index.d.ts
vendored
31
packages/types/types/index.d.ts
vendored
@@ -39,22 +39,28 @@ export interface Stat {
|
||||
blocks: number;
|
||||
}
|
||||
|
||||
export interface FSFilesystemWORKERFS {
|
||||
|
||||
}
|
||||
export interface FSFilesystemWORKERFS {}
|
||||
|
||||
export interface FSFilesystemMEMFS {
|
||||
|
||||
}
|
||||
export interface FSFilesystemMEMFS {}
|
||||
|
||||
export interface FSFilesystems {
|
||||
WORKERFS: FSFilesystemWORKERFS;
|
||||
MEMFS: FSFilesystemMEMFS;
|
||||
}
|
||||
|
||||
export type FSFilesystem =
|
||||
| FSFilesystemWORKERFS
|
||||
| FSFilesystemMEMFS;
|
||||
export type FSFilesystem = FSFilesystemWORKERFS | FSFilesystemMEMFS;
|
||||
|
||||
export interface OptionReadFile {
|
||||
encoding: string;
|
||||
}
|
||||
|
||||
export interface WorkerFSMountConfig {
|
||||
blobs?: {
|
||||
name: string;
|
||||
data: Blob;
|
||||
}[];
|
||||
files?: File[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Functions to interact with Emscripten FS library.
|
||||
@@ -75,7 +81,11 @@ export interface FS {
|
||||
isFile: (mode: number) => boolean;
|
||||
/** mode is a numeric notation of permission, @see [Numeric Notation](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) */
|
||||
isDir: (mode: number) => boolean;
|
||||
mount: (fileSystemType: FSFilesystem, data: WorkerFSMountConfig, path: string) => void;
|
||||
mount: (
|
||||
fileSystemType: FSFilesystem,
|
||||
data: WorkerFSMountConfig,
|
||||
path: string
|
||||
) => void;
|
||||
unmount: (path: string) => void;
|
||||
filesystems: FSFilesystems;
|
||||
}
|
||||
@@ -115,6 +125,7 @@ export interface FFmpegCoreModule {
|
||||
mainScriptUrlOrBlob: string;
|
||||
|
||||
exec: (...args: string[]) => number;
|
||||
ffprobe: (...args: string[]) => number;
|
||||
reset: () => void;
|
||||
setLogger: (logger: (log: Log) => void) => void;
|
||||
setTimeout: (timeout: number) => void;
|
||||
|
||||
Reference in New Issue
Block a user