A better ffmpeg.wasm front end, allowing for it to be included in a single line of js, and is independent of the ffmpeg-core version.
See the demo page here
This documentation describes the available asynchronous functions for interacting with an in-memory FFmpeg filesystem.
All functions are asynchronous and should be called using await
.
let dirs = await ffmpeg.listDir(".");
Lists the contents of a directory.
-
Parameters:
path
(string): The directory path to list.
-
Returns:
string[]
- An array of filenames in the directory. -
Example:
let dirs = await ffmpeg.listDir("."); console.log(dirs);
Creates a new directory.
-
Parameters:
path
(string): The directory path to create.
-
Returns:
string
- The created directory path. -
Example:
await ffmpeg.mkdir("/new-folder");
Reads a file and returns a blob URL.
-
Parameters:
path
(string): The file path to read.
-
Returns:
string
- A blob URL representing the file contents. -
Example:
let fileUrl = await ffmpeg.readFileToUrl("video.mp4"); console.log(fileUrl);
Renames a file or directory.
-
Parameters:
oldname
(string): The current file/directory name.newname
(string): The new name.
-
Returns:
string
- The new name. -
Example:
await ffmpeg.rename("old.mp4", "new.mp4");
Writes a file from a given URL to the FFmpeg filesystem.
-
Parameters:
path
(string): The target file path.url
(string): The source URL of the file.
-
Returns:
string
- The written file path. -
Example:
await ffmpeg.writeFileFromUrl("video.mp4", "https://example.com/video.mp4");
Executes an FFmpeg command.
-
Parameters:
args
(string[]): An array of command-line arguments for FFmpeg.
-
Returns: The execution result.
-
Example:
let result = await ffmpeg.exec(["-i", "input.mp4", "-vf", "scale=1280:720", "output.mp4"]); console.log(result);
Writes data to a file in the FFmpeg filesystem.
- Parameters:
path
(string): The target file path.data
(Uint8Array | string): The data to write.
- Returns:
string
- The written file path. - Example:
let data = new Uint8Array([0x00, 0x01, 0x02]); await ffmpeg.writeFile("file.bin", data);
Reads a file from the FFmpeg filesystem.
- Parameters:
path
(string): The file path to read.isString
(boolean): Whether to decode the file as a string.
- Returns:
Uint8Array | string
- The file contents. - Example:
let binaryData = await ffmpeg.readFile("file.bin"); let textData = await ffmpeg.readFile("file.txt", true);
Sets the logging function.
- Parameters:
func
(function): A function that receives log messages.
- Example:
ffmpeg.setLogger(console.log);
Sets the progress tracking function.
- Parameters:
func
(function): A function that receives progress updates.
- Example:
ffmpeg.setProgress(progress => console.log("Progress:", progress));