Watch Folder
data-variant=info
data-slots=text
Since: 27.0
The Media Encoder Watch Folder API is the used for all operations involving managing Watch Folders in Media Encoder. A watch folder monitors a source directory and automatically encodes new files using a specified preset.
The Watch Folder object can be acceessed from the main app object:
const app = require("mediaencoder");
const WatchFolder = app.WatchFolder;
Constants
These Watch Folder Constants are used as parameters in various WatchFolder API methods for Media Encoder.
All Constants can be accessed via the WatchFolder object:
const app = require("mediaencoder");
const WatchFolder = app.WatchFolder;
const WATCH_FOLDER_ENCODER_STATUS_CHANGED =
WatchFolder.WATCH_FOLDER_ENCODER_STATUS_CHANGED; // "WatchFolderStatusEvent"
PROGRESS_CATEGORY_ID
Retrieves the unique identifier for the progress category for global progress of the AME renderer. This ID allows access to the global progress of the AME Renderer. To obtain the category, use getOrCreateProgressCategory() on the ProgressCategoryContainer object. The ProgressItem object should be used to manage individual progress items. Each job item is registered using its unique reference ID.
Type: string
Since: 27.0
WATCH_FOLDER_ENCODER_STATUS_CHANGED
Event ID for when a watch folder encoder status changes.
The listener receives a WatchFolderStatusEvent object with the following property:
Type: string
Since: 27.0
Properties
These read-only properties are available on a watch folder object, such as the one returned by createWatchFolder.
const app = require("mediaencoder");
const watchFolder = await app.WatchFolder.createWatchFolder(
"path/to/source",
"path/to/destination",
"path/to/preset.epr",
);
watchFolder.id; // "e8105b34-f5f8-4254-84d9-6345120568f4"
id
The unique identifier (GUID) for the watch folder.
Type: string (readonly)
Since: 27.0
filePath
The source path being monitored by the watch folder.
Type: string (readonly)
Since: 27.0
presetPath
The preset file path used for encoding.
Type: string (readonly)
Since: 27.0
destinationPath
The destination path where encoded files are saved.
Type: string (readonly)
Since: 27.0
Methods
getInstance
Gets an instance of the WatchFolder object.
Since: 27.0
Parameters
none
Returns
WatchFolder objectconst app = require("mediaencoder");
const watchFolder = app.WatchFolder.getInstance();
createWatchFolder
Creates a watch folder that monitors the source directory and automatically encodes new files using the specified preset. The watch folder will process any new files added to the source directory and save the encoded output to the destination directory.
Since: 27.0
Parameters
*.epr) to use for encodingReturns
A watch folder item object with the following read-only properties:
const app = require("mediaencoder");
const watchFolder = await app.WatchFolder.createWatchFolder(
"path/to/source",
"path/to/destination",
"path/to/preset.epr",
);
watchFolder; // { id, filePath, presetPath, destinationPath }
The Promise is rejected with an error message if the source path, destination path, or preset path does not exist or is invalid, or if the preset uses an unsupported HEVC encoding format (when called from a non-first-party context).
getAllWatchFolders
Returns an array of all active watch folder objects.
Since: 27.0
Parameters
none
Returns
const app = require("mediaencoder");
const watchFolders = await app.WatchFolder.getAllWatchFolders();
removeAllWatchFolders
Removes all active watch folders from the system.
Since: 27.0
Parameters
none
Returns
true if removal was successfulconst app = require("mediaencoder");
const success = await app.WatchFolder.removeAllWatchFolders();
success; // true
addOutput
Adds another output to this watch folder. Each output has its own preset and destination folder, so a single watch folder can encode every new file into several formats. Ingest presets are not supported.
Call this method on a watch folder object, such as one returned by createWatchFolder or getAllWatchFolders.
Since: 27.0
Parameters
*.epr) to use for the new outputReturns
A Promise that resolves with a WatchFolderOutput describing the new output.
The Promise is rejected with an error message if the destination folder doesn't exist, if the preset file is missing, can't be read, is an ingest preset, or uses an unsupported HEVC encoding format (when called from a non-first-party context), if the watch folder no longer exists, or if the output can't be added.
const app = require("mediaencoder");
const watchFolder = await app.WatchFolder.createWatchFolder(
"path/to/source",
"path/to/destination",
"path/to/preset.epr",
);
const output = await watchFolder.addOutput("path/to/other-preset.epr", "path/to/other-destination");
output; // { id, presetPath, destinationPath }
getOutputs
Returns the outputs of this watch folder. Call this method on a watch folder object.
Since: 27.0
Parameters
none
Returns
The Promise resolves with an empty array if the watch folder no longer exists.
const app = require("mediaencoder");
const [watchFolder] = await app.WatchFolder.getAllWatchFolders();
const outputs = await watchFolder.getOutputs();
outputs.forEach((output) => console.log(output.id, output.destinationPath));
removeOutput
Removes an output from this watch folder. Call this method on a watch folder object.
Since: 27.0
Parameters
Returns
true if the output was removedThe Promise is rejected with an error message if outputId is empty, the watch folder no longer exists, or the output can't be removed.
const app = require("mediaencoder");
const [watchFolder] = await app.WatchFolder.getAllWatchFolders();
const [output] = await watchFolder.getOutputs();
await watchFolder.removeOutput(output.id); // true
subscribeToEvent
Registers a subscription to a watch folder event. After subscribing, call addEventListener to react to the event.
Since: 27.0
Parameters
Returns
true if subscription was successful, false if eventKey is not a watch folder eventconst app = require("mediaencoder");
const watchFolder = app.WatchFolder.getInstance();
const event = app.WatchFolder.WATCH_FOLDER_ENCODER_STATUS_CHANGED;
watchFolder.subscribeToEvent(event); // true
watchFolder.addEventListener(event, (statusEvent) => {
console.log("Watch folder encoder status:", statusEvent.status);
});
addEventListener
Registers an event handler for the specified event on this WatchFolder. The event handling follows the W3C DOM Level 2 Events Specification.
Since: 27.0
Parameters
true to call the handler during the capture phase. Also accepts an options object with a capture property. Defaults to falseReturns
none
const app = require("mediaencoder");
const watchFolder = app.WatchFolder.getInstance();
const event = app.WatchFolder.WATCH_FOLDER_ENCODER_STATUS_CHANGED;
watchFolder.subscribeToEvent(event);
const callback = (statusEvent) => {
console.log("Watch Folder Encoder Status Changed", statusEvent.status);
};
watchFolder.addEventListener(event, callback);
removeEventListener
Unregisters a previously registered event handler for the specified event on this WatchFolder.
Since: 27.0
Parameters
Returns
none
const app = require("mediaencoder");
const watchFolder = app.WatchFolder.getInstance();
const event = app.WatchFolder.WATCH_FOLDER_ENCODER_STATUS_CHANGED;
watchFolder.subscribeToEvent(event);
const callback = (statusEvent) => {
console.log("Watch Folder Encoder Status Changed", statusEvent.status);
};
watchFolder.addEventListener(event, callback);
watchFolder.removeEventListener(event, callback);