Skip to main content
SWAX
Inspiring
November 4, 2017
Answered

Mark in/out + add to Media Encoder?

  • November 4, 2017
  • 2 replies
  • 4386 views

After working on scripts for AE, I'm trying to get things going in Premiere.

However, the documentation here lacks severely, and finding the right functions isn't a walk in the park either. So I wanted to check if these two things are possible before I try to delve deeper:

  • Is it possible to set mark in and out (like when using shortcuts i + o) via extendscript?
  • Can that mark in/out selection be added to the Media Encoder queue? This would be the equivalent of pressing ctrl + m, and choosing "queue")

Bruce Bullis -- could you please shed a light on my questions?

Thanks in advance!

This topic has been closed for replies.
Correct answer SWAX

After testing my script, there is a strange anomaly.

I have a sequence with split (extended) markers that show a range inside the sequence.

When I run this script:

var activeSequence = app.project.activeSequence;

if (activeSequence) {

var markers = activeSequence.markers;

if (markers) {

var numMarkers = markers.numMarkers;

if (numMarkers > 0) {

var marker_index = 1;

for(var current_marker = markers.getFirstMarker();

current_marker !== undefined;

current_marker = markers.getNextMarker(current_marker)){

                                var selectIn = current_marker.start.seconds;

                                app.project.activeSequence.setInPoint(selectIn);   

                                var getIn = app.project.activeSequence.getInPoint();

                                $.writeln("In: "+marker_index+" -> "+getIn);

                                var selectOut = current_marker.end.seconds;

                                app.project.activeSequence.setOutPoint(selectOut);   

                                var getOut = app.project.activeSequence.getOutPoint();

                                $.writeln("Out: "+marker_index+" -> "+getOut);

                                app.encoder.encodeSequence(app.project.activeSequence,"test-"+marker_index+".mp4",

                                "preset.epr", app.encoder.ENCODE_IN_TO_OUT, 1);

                                alert();

}

}

}

}

All is fine - the encoder fires up, adds the sequence to it, shows me an alert - and after I click it it goes through all the sequences - and exports the correct ranges perfectly.

When I comment the alert(); -- I runs through all the markers, and adds them to the queue all using the same in/out point.

It seems like when the alert fires, the window is brought to the front and the selection is done correctly - but when it's done in the background there is something going wrong.

Bruce Bullis​ -- is this a bug? Or is there another way to do this more efficiently?

2 replies

pctechtv
Inspiring
September 10, 2018

I understand what you mean. I have seen other things happen too fast when alert() is not part of the script. This is my first attempt at getting Premiere to work with Media Encoder with a script. When I run your script with alerts firing I don't see anything happen to Media Encoder. The Exstend Script TooIkit give me back the long string saying the encoder commands were successful. I have tried having Media Encoder open and closed. Is there some of  steps that have to be done to Media Encoder to get this to work? Thanks

SWAX
SWAXAuthor
Inspiring
November 4, 2017

Ok, to answer my own question - and creating a new question:

Yes, it's possible - by iterating through the markers and setting the inPoint and outPoint.

However, I cannot seem to get the encoding of the "workarea" (set by the in/out range) working:

app.project.activeSequence.setInPoint(1);   

$.writeln("In:"+app.project.activeSequence.getInPoint());

app.project.activeSequence.setOutPoint(5);   

$.writeln("Out:"+app.project.activeSequence.getOutPoint());

app.encoder.encodeSequence(app.project.activeSequence,"output.mp4", "preset.epr", app.encoder.ENCODE_WORKAREA, 1);

The sequence is 11 seconds long, I select from 1 - 5 seconds, put it the renderqueue and render with ENCODE_WORKAREA -- it always renders 11 seconds for me.

Bruce Bullis​ -- is there a problem with this approach?

SWAX
SWAXAuthor
Inspiring
November 4, 2017

And the last piece of the puzzle is now ready:

There are three different parameters when encoding:

  • app.encoder.ENCODE_WORKAREA
  • app.encoder.ENCODE_ENTIRE
  • app.encoder.ENCODE_IN_TO_OUT

So this works fine, when iterating through the markers, setting the in/out points, and rendering out with the correct parameter:

app.project.activeSequence.setInPoint(1);  

$.writeln("In:"+app.project.activeSequence.getInPoint());

app.project.activeSequence.setOutPoint(5);  

$.writeln("Out:"+app.project.activeSequence.getOutPoint());

app.encoder.encodeSequence(app.project.activeSequence,"output.mp4", "preset.epr", app.encoder.ENCODE_IN_TO_OUT, 1);

SWAX
SWAXAuthorCorrect answer
Inspiring
November 4, 2017

After testing my script, there is a strange anomaly.

I have a sequence with split (extended) markers that show a range inside the sequence.

When I run this script:

var activeSequence = app.project.activeSequence;

if (activeSequence) {

var markers = activeSequence.markers;

if (markers) {

var numMarkers = markers.numMarkers;

if (numMarkers > 0) {

var marker_index = 1;

for(var current_marker = markers.getFirstMarker();

current_marker !== undefined;

current_marker = markers.getNextMarker(current_marker)){

                                var selectIn = current_marker.start.seconds;

                                app.project.activeSequence.setInPoint(selectIn);   

                                var getIn = app.project.activeSequence.getInPoint();

                                $.writeln("In: "+marker_index+" -> "+getIn);

                                var selectOut = current_marker.end.seconds;

                                app.project.activeSequence.setOutPoint(selectOut);   

                                var getOut = app.project.activeSequence.getOutPoint();

                                $.writeln("Out: "+marker_index+" -> "+getOut);

                                app.encoder.encodeSequence(app.project.activeSequence,"test-"+marker_index+".mp4",

                                "preset.epr", app.encoder.ENCODE_IN_TO_OUT, 1);

                                alert();

}

}

}

}

All is fine - the encoder fires up, adds the sequence to it, shows me an alert - and after I click it it goes through all the sequences - and exports the correct ranges perfectly.

When I comment the alert(); -- I runs through all the markers, and adds them to the queue all using the same in/out point.

It seems like when the alert fires, the window is brought to the front and the selection is done correctly - but when it's done in the background there is something going wrong.

Bruce Bullis​ -- is this a bug? Or is there another way to do this more efficiently?