Watch Folder

data-variant=info
data-slots=text
UXP for Adobe Media Encoder is in public beta. This reference is being written, and the supported API surface may change before general availability.

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:

Name
Type
Description
status
int
The new status of the watch folder encoder. Uses the same values as the RENDER_QUEUE_* constants

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

Name
Type
Description
watchFolder
object
A WatchFolder object
const 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

Name
Type
Description
sourcePath
string
The path to the folder which should be monitored as a watch folder
destinationPath
string
The path where encoded files will be saved
presetPath
string
The full path to the preset file (*.epr) to use for encoding

Returns

A watch folder item object with the following read-only properties:

Name
Type
Description
id
string
The unique identifier (GUID) for the watch folder
filePath
string
The source path being monitored by the watch folder
presetPath
string
The preset file path used for encoding
destinationPath
string
The destination path where encoded files are saved
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

Name
Type
Description
watchFolders
object[]
Array of all active watch folder objects
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

Name
Type
Description
result
boolean
Returns true if removal was successful
const 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

Name
Type
Description
presetPath
string
The full path to the preset file (*.epr) to use for the new output
destinationPath
string
The path where the output's encoded files are saved

Returns

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

Name
Type
Description
outputs
object[]
Array of WatchFolderOutput objects

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

Name
Type
Description
outputId
string
The id of the WatchFolderOutput to remove

Returns

Name
Type
Description
result
boolean
Returns true if the output was removed

The 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

Name
Type
Description
eventKey
string
The event ID to subscribe to: WATCH_FOLDER_ENCODER_STATUS_CHANGED

Returns

Name
Type
Description
success
boolean
Returns true if subscription was successful, false if eventKey is not a watch folder event
const 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

Name
Type
Description
eventType
string
The event to listen for, such as WATCH_FOLDER_ENCODER_STATUS_CHANGED
handler
function
A function to be triggered when the specified event occurs
capture
boolean (optional)
true to call the handler during the capture phase. Also accepts an options object with a capture property. Defaults to false

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);

removeEventListener

Unregisters a previously registered event handler for the specified event on this WatchFolder.

Since: 27.0

Parameters

Name
Type
Description
eventType
string
The event to stop listening for
handler
function
The previously registered callback to remove
capture
boolean (optional)
Must match the capture value used in addEventListener. Defaults to false

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);