Skip to main content
MattKushner
Participant
July 5, 2023

AME Scripting Help, Please!

  • July 5, 2023
  • 7 replies
  • 368 views

@eckiAMETeam not sure if you're the ones to ask, but I have a couple very specific scripting questions that I really need answers to! I posted on here two months ago and have gotten no response. 

 

I've gotten familiar with the scripting docs (https://readthedocs.org/projects/ame-scripting-guide/downloads/pdf/latest/) and have gotten some things to work, namely launching AME command line with a JSX file and getting it to clear the queue, populate it and start rendering the specified file and it's corresponding preset.

 

But I'm having a few very specific issues:

 

  •  I'm using the below function to create an item from an image sequence:

 

​encoderWrapper = app.getFrontend().addFileSequenceToBatch();

 but I can't get the attributes of frameRate, outputFrameSize or frameRange to work (I also don't see a way to set whether to include alpha).

var frameRate = "24";
encoderWrapper.setFrameRate(frameRate);​
var width = 1920;
var height = 1080;
encoderWrapper.setOutputFrameSize(width, height);
//workAreaType: 0-Entire, 1-InToOut, 2-WorkArea, 3-Custom, 4-UseDefault
var workAreaType = 0;
var startTime = 0.0;
var endTime = 1.0;
encoderWrapper.setWorkArea(workAreaType, startTime, endTime);

Frame range is by far the most important, it's something I really need to be able to control. I am already able to manage resolution, frame rate and alpha by dynamically creating presets. It works, but it's an unnecessarily heavy lift and creates tons of presets that need to be cleaned up, so I'd love to be able to simplify that as well. 

 

  • I can't figure out whether the

 

writeIn​

print statements go anywhere...they don't echo in a shell/console I can find and I'd rather log them to a txt file but I can't figure out how to do that either...

 

  • I'd really like AME to quit upon queue completion, most importantly because I have post process cleanup of the JSX I'm dynamically creating as well as all the presets, but also to be able to manage license use. I can't find any sort of flag to pass to the command line function:

 

​<AME Executable> --console es.processFile <JSX File>

or for it to return some info from the subprocess so I can trigger a kill of AME myself. 

 

7 replies

Community Manager
July 18, 2023

Hi Matt, 

I encountered a few obstacles that required my attention. I'm delighted to hear that you were able to benefit from some of the suggestions provided. Have you had the opportunity to try using the setWorkAreaInTicks() method with a widely used file format such as *.mp4? This would help ensure the proper usage of the method.
Would you mind sending me your email as dm so I can share the link ? 

 

Best regards,

Sueky

MattKushner
Participant
July 18, 2023

Hi  @eckiAMETeam ,

 

I reorganized my jsx file based on your suggestions (which was a bit tricky as it's generated dynamically through python), and I believe it is constructed correctly as it doesn't error, but it also doesn't seem to respect the setting of the frame range to 1 second, the same way your script does--it still outputs the default 5 second notchlc file from a still that it did before. 

 

I have collected my .jsx script, the epr presets (I have a full res and proxy I make), the source png still and the output notch files and would be happy to send them over for you to look at and test with if you provide an upload link. 

 

Thanks!

Matt Kushner

MattKushner
Participant
July 12, 2023

Hi there,

 

Thank you for your response! To explain in simple terms, our team needs to encode batches of image sequences into NotchLC Quicktime files. The output QTs need to match the input sequence resolution, alpha settings, and have an easy way to input the FPS, as well as make the file naming and output directory consistent. We developed our own PyQT UI to  be able to load all the data from the sequences we want to encode, and then a subprocess generates the JSX dynamically through python, which launches AME via command line with the JSX passed, and the renders are queued and start processing.

 

From earlier in this thread, because addFileSequenceToBatch() only returns a boolean, there is no way for me to set any of the attributes on the batch object itself. So I built a workaround--using an existing epr preset as a template, I'm dynamically copying it, replacing the UID, the name of the preset, width, height, FPS & alpha. This works, but is an unnecessarily heavy lift if I was able to just set those attributes directly in the jsx. I also can't control frame range this way, which is very important for our use cases.

 

Related to frame range, from experience, a still frame defaults to a 5 second encode, which, for a 30 FPS QT is 150 times larger than necessary. It is a very slow process to dive into each encode's settings and drag the in and out points to adjust this, but the notchlc codec is very large so we can't afford the disc space for these to be 5 seconds long.  I realized that because these are still frames, I can theoretically use addFileToBatch() instead of addFileSequenceToBatch() in these cases, though I'm not sure if that's really true if the frame range setting is designed for encoding a QT instead of a still image. 

 

I could give you a preset, but that's really not the issue. Setting the frame range is what I'm trying to accomplish, and if there was a way to expose these attributes for addFileSequenceToBatch() so I can just use a default notchlc preset, that would be way easier to manage.

Community Manager
July 10, 2023

Assuming you only want to render one item in your queue, I would use EncoderHostObject to listen to whether the batchItem has been encoded, as you can see in the snippet.

 

      encoderHost.addEventListener("onItemEncodeComplete", function (eventObj) {
        $.writeln("width :", batch_item0.outputWidth);
        $.writeln("height:", batch_item0.outputHeight);
        $.writeln("outputFiles:", batch_item0.outputFiles);
      });
      encoderHost.runBatch();

 

 

Community Manager
July 10, 2023

Hi Matt, 


I would like to inquire if it would be possible for you to share your preset file with me. I have installed the Notch plugin from the official website (https://notchlc.notch.one/#download), but unfortunately, I do not have access to the specific settings used in your preset.

 

If you have an interest in expanding your knowledge of scripting, I would be more than willing to assist you. 

Additionally, it is worth noting that the methods such as 'addFileToBatch' or 'addSequenceToBatch' may have been developed at different points in time, which could explain why they are implemented differently.

I am currently working on recreating your scenario in order to better understand your perspective and objectives. In order to proceed with accuracy, I kindly request additional information from you.

Could you kindly clarify what you were aiming to achieve with your snippet?

 


This is how I would rewrite the snippet. 
Notice: Hence I do not have access to the preset I just used the default one that will be choosen if the format QuickTime is set. 

var preset0 = ""; // If you have a format set then the first default preset will be used
var source_path0 = "C:\\dev\\test\\media\\Toni.jpg";
var dest0 = "C:\\dev\\test\\media\\Output";
var format = "QuickTime";

var exporter = app.getExporter();
if (exporter) {
  exporter.removeAllBatchItems();

  var frontend = app.getFrontend();
  // listen for batch item added event
  if (frontend) {
    frontend.addEventListener("onItemAddedToBatch", function (eventObj) {
      $.writeln("onAddItemToBatch success");
    });

    var batch_item0 = frontend.addFileToBatch(
      source_path0,
      format,
      preset0,
      dest0
    );

    var ticksPerSecond = 254016000000;
    var startTimeInTicks = 0 * ticksPerSecond; // starting at 0 second
    var timeToAddInTicks = 1 * ticksPerSecond; // ending at 1 second
    var startTime0 = String(startTimeInTicks);
    var endTime0 = String(timeToAddInTicks);
    batch_item0.setWorkAreaInTicks(2, startTime0, endTime0);

    var encoderHost = app.getEncoderHost();
    if (encoderHost) {
      encoderHost.addEventListener("onItemEncodeComplete", function (eventObj) {
        $.writeln("width :", batch_item0.outputWidth);
        $.writeln("height:", batch_item0.outputHeight);
        $.writeln("outputFiles:", batch_item0.outputFiles);
      });
      encoderHost.runBatch();
    }
  }
}

Hint, register the eventlistener always before calling the methods. 
Best regards, 

Sükriye 

MattKushner
Participant
July 7, 2023

Hi Sueky,

 

Thanks so much for getting back to me so quickly! I called Adobe about this and was informed that no one who works for Adobe can help me with my issues. I guess I was talking to the wrong people!

 

It doesn't make sense to me that addFileSequenceToBatch() and addFileToBatch() don't both return an encoderWrapper object--aren't they both batch objects? How can I modify the settings for an image sequence if it doesn't return an encoderWrapper object? Is that something that can be updated?

 

I do have a case where I'm trying to encode a QT for a still image (which by default encodes a 5 second QT instead of a single frame) and can use the addFileToBatch() function but can't seem to get the setWorkAreaInTicks() to function. If I want to make a single frame QT of that, how do I do that using that function? I would imagine the start value would be 0 and the end value would be 254016000000/FPS. But I've tried all kinds of permutations of that and it doesn't work. Does the setWorkAreaInTicks() function only work for source media that is a video file?

 

The below works fine without the setWorkAreaInTicks() added:

var exporter = app.getExporter();
var encoderHost = app.getEncoderHost();
var watchFolderObj = app.getWatchFolder();
//clean up queue before populating
exporter.removeAllBatchItems();
var frontend = app.getFrontend();
// listen for batch item added event
if (frontend) {
frontend.addEventListener("onItemAddedToBatch", function (eventObj) {
$.writeln("onAddItemToBatch success");
});
var ticksPerSecond = 254016000000;
var startTimeInTicks = 0 * ticksPerSecond;
var timeToAddInTicks = 1 * ticksPerSecond;
var startTime0 = String(startTimeInTicks);
var endTime0 = String(timeToAddInTicks);
source_path0 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01.01001.png"
preset0 = "C:\\Users\\mkushner\\Documents\\Adobe\\Adobe Media Encoder\\22.0\\Presets\\LV_taylorSwift_rm02_W2A1Hi0_v01.epr"
dest0 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01.mov"
var batch_item0 = frontend.addFileToBatch(source_path0,
                                              "NotchLC (DirectX)",
                                              preset0,
                                              dest0);
$.writeln("width :", batch_item0.outputWidth);
$.writeln("height:", batch_item0.outputHeight);
$.writeln("outputFiles:", batch_item0.outputFiles);
if (batch_item0) {
$.writeln("Batch item 0 added successfully");}
var ticksPerSecond = 254016000000;
var startTimeInTicks = 0 * ticksPerSecond;
var timeToAddInTicks = 1 * ticksPerSecond;
var startTime1 = String(startTimeInTicks);
var endTime1 = String(timeToAddInTicks);
source_path1 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01.01001.png"
preset1 = "C:\\Users\\mkushner\\Documents\\Adobe\\Adobe Media Encoder\\22.0\\Presets\\LV_taylorSwift_rm02_W2A1Hi0_v01_proxy10.epr"
dest1 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01_proxy10.mov"
var batch_item1 = frontend.addFileToBatch(source_path1,
                                              "NotchLC (DirectX)",
                                              preset1,
                                              dest1);
$.writeln("width :", batch_item1.outputWidth);
$.writeln("height:", batch_item1.outputHeight);
$.writeln("outputFiles:", batch_item1.outputFiles);
if (batch_item1) {
$.writeln("Batch item 1 added successfully");}
}

but when it is added the code fails:

var exporter = app.getExporter();
var encoderHost = app.getEncoderHost();
var watchFolderObj = app.getWatchFolder();
//clean up queue before populating
exporter.removeAllBatchItems();
var frontend = app.getFrontend();
// listen for batch item added event
if (frontend) {
frontend.addEventListener("onItemAddedToBatch", function (eventObj) {
$.writeln("onAddItemToBatch success");
});
var ticksPerSecond = 254016000000;
var startTimeInTicks = 0 * ticksPerSecond;
var timeToAddInTicks = 1 * ticksPerSecond;
var startTime0 = String(startTimeInTicks);
var endTime0 = String(timeToAddInTicks);
source_path0 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01.01001.png"
preset0 = "C:\\Users\\mkushner\\Documents\\Adobe\\Adobe Media Encoder\\22.0\\Presets\\LV_taylorSwift_rm02_W2A1Hi0_v01.epr"
dest0 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01.mov"
var batch_item0 = frontend.addFileToBatch(source_path0,
                                              "NotchLC (DirectX)",
                                              preset0,
                                              dest0);
batch_item0.setWorkAreaInTicks(2, startTime0, endTime0);
$.writeln("width :", batch_item0.outputWidth);
$.writeln("height:", batch_item0.outputHeight);
$.writeln("outputFiles:", batch_item0.outputFiles);
if (batch_item0) {
$.writeln("Batch item 0 added successfully");}
var ticksPerSecond = 254016000000;
var startTimeInTicks = 0 * ticksPerSecond;
var timeToAddInTicks = 1 * ticksPerSecond;
var startTime1 = String(startTimeInTicks);
var endTime1 = String(timeToAddInTicks);
source_path1 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01.01001.png"
preset1 = "C:\\Users\\mkushner\\Documents\\Adobe\\Adobe Media Encoder\\22.0\\Presets\\LV_taylorSwift_rm02_W2A1Hi0_v01_proxy10.epr"
dest1 = "\\\\mnt\\jobs\\Events\\02_POST\\DISGUISE\\RENDERS\\LV\\taylorSwift\\rm02\\LV_taylorSwift_rm02_v01\\LV_taylorSwift_rm02_W2A1Hi0_v01_proxy10.mov"
var batch_item1 = frontend.addFileToBatch(source_path1,
                                              "NotchLC (DirectX)",
                                              preset1,
                                              dest1);
batch_item1.setWorkAreaInTicks(2, startTime1, endTime1);
$.writeln("width :", batch_item1.outputWidth);
$.writeln("height:", batch_item1.outputHeight);
$.writeln("outputFiles:", batch_item1.outputFiles);
if (batch_item1) {
$.writeln("Batch item 1 added successfully");}
}

 

I also tried app.quit() in the JSX I'm creating, but when I try to wrap it in an event listener, AME doesn't like it. Is my syntax wrong?

batch_item1.addEventListener("onEncodeFinished", function (eventObj) {
$.writeln("Encoding result for batch item: " + eventObj.result);
app.quit();
}
Community Manager
July 7, 2023

Hi Matt, first thanks a lot for reaching out to us. 

Excuse me, I believe there may have been a misunderstanding. It seems that there might be a small error in the way you used the method. Let me clarify the correct way to use it so that you can achieve the desired outcome more effectively.

 

 [bool] : addFileSequenceToBatch(...); 
This method will return a boolean and not a encoderWrapper object. I am aftraid that there is no way to get an encoderWrapper object which is a render or a batch item (I don't know which one of these words sounds familiar to you).

I have been looking at the code and only couple of other methods would get you an encoderWrapper Object and let you modify it. Those are 
addFileToBatch()
addDLToBatch()

But if you use one of these methods and want to modify the added item; let say the setWorkArea(...) I highly recommend you to use the 
setWorkAreaInTicks(...)

 https://ame-scripting.docsforadobe.dev/reference/index.html#encoderwrapper

ar sequence2997 = "C:\\path\\to\\weLove.mp4";
var format = "H.264";
var preset = "C:\\path\\to\\HD 720p.epr";
var outputPath = "C:\\path\\to\\Output";

// The value of ticksPerSecond is predefined in premiere pro and ame.
// For more information please have a look into https://ppro-scripting.docsforadobe.dev/other/time.html
var ticksPerSecond = 254016000000;
var startTimeInTicks = 20 * ticksPerSecond;
var timeToAddInTicks = 30 * ticksPerSecond;

var startTimeinTicksStr = String(startTimeInTicks);
var endTimeInTicksStr = String(timeToAddInTicks);

var frontend = app.getFrontend();
if (frontend) {
  var encoderWrapper = frontend.addFileToBatch(
    sequence2997,
    format,
    preset,
    outputPath
  );
  if (encoderWrapper) {
    $.writeln("workarea start time: ", startTimeinTicksStr);
    $.writeln("workarea end time: ", endTimeInTicksStr);
    encoderWrapper.setWorkAreaInTicks(
      2,
      startTimeinTicksStr,
      endTimeInTicksStr
    );
  } else {
    $.writeln("encoderWrapper is not valid");
  }
  var encoderHost = app.getEncoderHost();
  if (encoderHost) {
    encoderHost.runBatch();
  } else {
    $.writeln("encoderHost is not valid");
  }
} else {
  $.writeln("frontend is not valid");
}

 

How to trigger quitAME()?

I see that you are using the console command to run a jsx file. Therefore, we cannot retrieve any events that occurred while processing the jsx file.
Assuming that you are using the latest beta version, you can allow AME by adding the following to the debugdatabase.txt

 

AME.WriteLogNextToOutput	true	false

This file is in \Documents\Adobe\Adobe Media Encoder (Beta)\23.0.
This flag allows AME to write the file ...._logOutPut.txt next to the encoded file, and if you can recognize this file, it means that the encoding has been completed. So you know that you can terminate AME by writing

app.quit();

Note that there are couple of other ways to manipulate the debugdatabase.txt file. You can also open Media Encoder. 

Press Ctrl+F12 to open the console Windows. Right clicking on the panels header will open the context menu and you can select DebugDatabase and look forWriteLogNextToOutput flag and set it to true. 

 

But be aware that changing any flags here can have impact on your outcome. 

 

And I am looking into the echoing to the shell command question and will come back to you. 

 

I hope this helps you. LMK if you have any other question. 

Best regards,

-Sueky