Closed louwjlabuschagne closed 3 years ago
Try the following:
var videoTrackNr = 0;
var seq = app.project.activeSequence;
var videoTrack = seq.videoTracks[videoTrackNr];
var clips = videoTrack.clips;
var clip = clips[0];
var clipStartTime = clip.start;
clipStartTime.seconds = clipStartTime.seconds + 5;
videoTrack.insertClip(clip.projectItem, clipStartTime.ticks);
Thanks for your response! I'm not sure if this will do. Let me explain my problem in detail: I have one video file, split in 3 Parts (Part A, B and C). After every part I need to check whether the clip-end Timecode is below or above 30 seconds (minutes and hours don't matter). If it is below 30 seconds, the automation has to put a 'special' black frame (2 minute long .mxf video file) into the timeline right after part A, which ends at exactly at the following full minute (f.e.: Part A ends at 00:20:25:00 [HH:MM:SS:FF] so the black frame has to end at 00:21:00:00.). If the clip-end is above 30 seconds it has to end exactly at the second next full minute (Part A ends at 00:21:35:00 -> black frame ends at 00:23:00:00). I've already done the maths behind that, I just need to get the correct parameter to use the following command "activeSequence.videoTracks[0].insertClip(BlackFrame, [the time in seconds or ticks I calculated])"
So the variable 'd' should be my end time, but every time I execute the script I receive "Illegal Parameter type" in this line: "activeSequence.videoTracks[0].insertClip(BlackFrame, d)"
clipStartTime.seconds = clipStartTime.seconds + 5;
Or is it possible to use my calculated variable d, instead of 5 in this case?
I'm new to this, excuse all these questions :D Greetings
A bit for the context. Sorry for the missing snippit on the right side. I took this photo last week in office for a colleague. I don't think there is anything essential missing, to understand what I was doing
@titusFTV try the following:
var seq = app.project.activeSequence;
var blackClipProjItem = seq.videoTracks[1].clips[0].projectItem;
var videoTrackNr = 0;
var videoTrack = seq.videoTracks[videoTrackNr];
var clips = videoTrack.clips;
var clip = clips[0];
var clipEndTime = clip.end;
// We use the modules (%) operator to give us the seconds after we remove all the minutes
// if the seconds where 183, then 183 % 60 = 3,
// if the secods where 179, then 179 % 60 = 59
var secondsModulus60 = clipEndTime.seconds % 60;
// we can then use the `secondsModulus60` variable to determine
// if we are before or after the 30s mark
var isBefore30s = secondsModulus60 < 30;
// This might be the ingrediant you were needing,
// you can initialise a new Time object and set the seconds
// and the ticks will update automatically, this way you
// don't have to worry about converting between the 2.
// Plus, if you do normal math on the seconds, which are Integers,
// the the ticks, which are Strings, reflect this
var durationTime = new Time();
// Below we calculate how long our black clip needs to be
// If before 30s, then we only fill up to the next minute
// If after 30s, then we fill all the way to the next minute
if (isBefore30s) {
durationTime.seconds = 60 - secondsModulus60;
} else {
durationTime.seconds = 60 + (60 - secondsModulus60);
}
// Since there is no way to set the duration of our clip,
// we need to alter the endPoint, this can be done using
// the setOutPoint method on our black clip's project item
// the ProjectItem.setOutPoint method takes 2 arguments:
// time: in ticks as a String
// mediaType: as an integer that represents a lookup of Video: 1, Audio: 2, Both: 4,
blackClipProjItem.setOutPoint(durationTime.ticks, 4);
videoTrack.overwriteClip(blackClipProjItem, clipEndTime.ticks);
Vid of it filling to the next second if the clip ends after 30s:
Vid of it filling to the second if the clip ends before 30s:
Hi there! So I have an update for you. There is good and bad news. The good one: the code snippit is working perfectly. The bad one: inserting clips right after the "trimmed" blackClipProjItem doesn´t work like I did before. I´ve tried for hours but always received "illegal parameter type" in line 107. I tried stuff like using the clipLength as ticks or seconds, I´ve tried using the "overwriteClip" command and set the playhead to the ending of the BlackFrame, took the PlayerPosition.seconds/.ticks and so on..nothing worked. Even the console told me, that var "duration" is a string (like needed for the commands I used [Source: https://readthedocs.org/projects/premiere-scripting-guide/downloads/pdf/latest/ 20.2.3 & 20.2.1]. I couldn´t solve the problem.
I´m using PrPr2020 ver. 14.3/14.0..
What do I do? Greetings
@titusFTV can you confirm that the importPartB_SM
is of type ProjectItem
.
If you can maybe paste the line of code where you declare importBlack
and importPartB_SM
?
Also, if you can maybe paste the code as text, not as an image, then I can pop in on my side and see if it works... Check out the Syntax highlighting
section on https://guides.github.com/features/mastering-markdown/
Basically you can wrap your code in 3 back ticks, i.e. `
On a more conceptional level, what are you trying to achieve? Loop through all the clips on track 1 and fill it with the black clip depending on the below30s criteria?
app.project.importFiles("L:\\2_Ingest\\AZ\\ExtendScript\\Legalizer.mxf"); //0
app.project.importFiles("L:\\2_Ingest\\AZ\\ExtendScript\\Legalizer_30sek.mxf"); //1
app.project.importFiles(importFolder+ "\\" + WDH); //2
app.project.importFiles(importFolder+ "\\" + PartA_SM); //3
app.project.importFiles(importFolder+ "\\" + PartB_SM); //4
app.project.importFiles(importFolder+ "\\" + PartC_SM); //5
_//~ app.project.importFiles(importFolder+ "\\" + PartA_CF); //6
//~ app.project.importFiles(importFolder+ "\\" + PartB_CF); //7
//~ app.project.importFiles(importFolder+ "\\" + PartC_CF); //8_
var importBlack30 = app.project.rootItem.children[1];
var importWDH = app.project.rootItem.children[2];
var importPartA_SM = app.project.rootItem.children[3];
var importBlack = app.project.rootItem.children[0];
var importPartB_SM = app.project.rootItem[4]; _//**so this is where Problems began, there´s just 2 children missing :)**_
var importPartC_SM = app.project.rootItem[5];```
These are the lines where everything needed is getting Imported and declared.
The main goal is to insert 3 Clips (PartA, PartB and PartC) into one timeline and add the blackframe right after every single Part, filling the gaps between Parts A,B & C depending on the below30s criteria. No trimming, no cutting on Part A, B and C, just put it in as it is. The Part right after the blackFrame has to begin right at a full minute. (Currently the next Part begins with one frame offset; too early..but it depends on the clips. It is kind of random, sometimes the next Part starts at full minute, sometimes at one frame offset).
While writing this I´ve already found my mistake in the lines above. Import now works just fine, there is just the fine-tuning of the timing left. (Btw, you might be asking if it is necessary that the Parts B and C begin at exactly the full minute: yes, it really is :D).
### **The full code:**
```javascript
var project = app.project;
var projectItem = project.rootItem;
_// Deklaration Staffel und Sendung_
var Staffel = "04";
var Sendung = "13";
_// Deklaration Sourcepath_
var importFolder = "L:\\2_Ingest\\AZ\\AZ" + Sendung;
_//Deklaration importclips_
var PartA_SM = "LNB_S" + Staffel + "_F" + Sendung + "_Part_A.mxf";
var PartB_SM ="LNB_S" + Staffel + "_F" + Sendung + "_Part_B.mxf";
var PartC_SM = "LNB_S" + Staffel + "_F" + Sendung + "_Part_C.mxf";
var PartA_CF = "LNB_S" + Staffel + "_F" + Sendung + "_Part_A_CF.mxf";
var PartB_CF = "LNB_S" + Staffel + "_F" + Sendung + "_Part_B_CF.mxf";
var PartC_CF = "LNB_S" + Staffel + "_F" + Sendung + "_Part_C_CF.mxf";
var WDH = "LNB_S" + Staffel + "_F" + Sendung + "_WDH.mxf";
var Black = "Legalizer.mxf";
var Black30 = "Legalizer_30sek";
_//Deklaration Sequenzen_
var Seq_SM = "LNB_S" + Staffel + "_F" + Sendung + "_SM";
var Seq_CF = "LNB_S" + Staffel + "_F" + Sendung + "_CF";
var Seq_WDH = "LNB_S" + Staffel + "_F" + Sendung + "_WDH";
_//Import aller Files_
app.project.importFiles("L:\\2_Ingest\\AZ\\ExtendScript\\Legalizer.mxf"); //0
app.project.importFiles("L:\\2_Ingest\\AZ\\ExtendScript\\Legalizer_30sek.mxf"); //1
app.project.importFiles(importFolder+ "\\" + WDH); //2
app.project.importFiles(importFolder+ "\\" + PartA_SM); //3
app.project.importFiles(importFolder+ "\\" + PartB_SM); //4
app.project.importFiles(importFolder+ "\\" + PartC_SM); //5
_//~ app.project.importFiles(importFolder+ "\\" + PartA_CF); //6
//~ app.project.importFiles(importFolder+ "\\" + PartB_CF); //7
//~ app.project.importFiles(importFolder+ "\\" + PartC_CF); //8_
var importBlack30 = app.project.rootItem.children[1];
var importWDH = app.project.rootItem.children[2];
var importPartA_SM = app.project.rootItem.children[3];
var importBlack = app.project.rootItem.children[0];
var importPartB_SM = app.project.rootItem.children[4];
var importPartC_SM = app.project.rootItem.children[5];
_//Erstelle Sequenz WDH_
app.project.newSequence(Seq_WDH, "C:\\Users\\Edit2\\Documents\\Adobe\\Premiere Pro\\14.0\\Profile-Edit2\\Settings\\Benutzerdefiniert\\Playout_CF.sqpreset");
var activeSequence = app.project.activeSequence;
_//WDH to SEQ + Legalizer30_
activeSequence.videoTracks[0].insertClip(importWDH, 0)
var clipLengthWDH = app.project.activeSequence.videoTracks[0].clips[0].duration;
activeSequence.videoTracks[0].insertClip(importBlack30, clipLengthWDH)
_//Erstelle Sequenz SM_
app.project.newSequence(Seq_SM, "C:\\Users\\Edit2\\Documents\\Adobe\\Premiere Pro\\14.0\\Profile-Edit2\\Settings\\Benutzerdefiniert\\Playout_CF.sqpreset");
var activeSequence = app.project.activeSequence;
_//SM to SEQ + Legalizer_
activeSequence.videoTracks[0].insertClip(importPartA_SM, 0)
_//~ var clipLengthSM_A = app.project.activeSequence.videoTracks[0].clips[0].duration;_
_//Timing_
var seq = app.project.activeSequence;
var videoTrackNr = 0;
var videoTrack = seq.videoTracks[0];
var clips = videoTrack.clips;
var clip = clips[0];
var clipEndTime = clip.end;
_//Quick Maths_
var secondsModulus60 = clipEndTime.seconds % 60;
var isBefore30s = secondsModulus60 < 30;
var durationTime = new Time();
if (isBefore30s) {
durationTime.seconds = 60 - secondsModulus60;
} else {
durationTime.seconds = 60 + (60 - secondsModulus60);
}
_//~ alert(durationTime.seconds);_
importBlack.setOutPoint(durationTime.ticks, 4);
videoTrack.overwriteClip(importBlack, clipEndTime.ticks);
_//Reset Outpoint für 2. Legalizer nach Part B_
app.project.rootItem.children[0].clearOutPoint()
var videoTracks = activeSequence.videoTracks;
var trackOne = videoTracks[0];
var clip = trackOne.clips[1];
var duration = clip.end.ticks;
_//Bewege Playhead zum Ende vom Schwarzbild_
app.project.activeSequence.setPlayerPosition(duration);
var playheadTime = activeSequence.getPlayerPosition()
var playheadSeconds= playheadTime.ticks;
_//Setze neue StartTime von Part B_
app.project.rootItem.children[4].setStartTime(playheadSeconds)
activeSequence.videoTracks[0].insertClip(importPartB_SM,playheadSeconds);
_//Timing_
var seq = app.project.activeSequence;
var videoTrackNr = 0;
var videoTrack = seq.videoTracks[0];
var clips = videoTrack.clips;
var clip = clips[2];
var clipEndTime = clip.end;
_//Quick Maths_
var secondsModulus60 = clipEndTime.seconds % 60;
var isBefore30s = secondsModulus60 < 30;
var durationTime = new Time();
if (isBefore30s) {
durationTime.seconds = 60 - secondsModulus60;
} else {
durationTime.seconds = 60 + (60 - secondsModulus60);
}
_//~ alert(durationTime.seconds);_
importBlack.setOutPoint(durationTime.ticks, 4);
videoTrack.overwriteClip(importBlack, clipEndTime.ticks);
_//Reset Outpoint für 2. Legalizer nach Part B_
app.project.rootItem.children[0].clearOutPoint()
var videoTracks = activeSequence.videoTracks;
var trackOne = videoTracks[0];
var clip = trackOne.clips[3];
var duration = clip.end.ticks;
_//Bewege Playhead zum Ende vom Schwarzbild_
app.project.activeSequence.setPlayerPosition(duration);
var playheadTime = activeSequence.getPlayerPosition()
var playheadSeconds= playheadTime.ticks;
_//Setze neue StartTime von Part C_
app.project.rootItem.children[5].setStartTime(playheadSeconds)
activeSequence.videoTracks[0].insertClip(importPartC_SM,playheadSeconds);
var clip = trackOne.clips[4];
var duration = clip.end.ticks;
_//Bewege Playhead zum Ende vom Schwarzbild_
app.project.activeSequence.setPlayerPosition(duration);
var playheadTime = activeSequence.getPlayerPosition()
var playheadSeconds= playheadTime.ticks;
activeSequence.videoTracks[0].insertClip(importBlack30,playheadSeconds);```
Okay I solved the issue of clips beginning with one frame offset simply by rounding var secondsModulus60. I almost finished my script today and have no more questions concerning the usage of timeObjects. Thanks for all you help!
Over and Out
Awesome news @titusFTV - I've been looking into the frame drop and it is very odd, it seems to appear sometimes but not other times... Glad you could get it working for your use case.
Is there a way to receive the player position (Seconds or tics..doesnt matter) as kind of a variable for calculations? F.e. my Player is at 1 sec, meaning it's lokated at 254016000000 ticks. Now I need this value in seconds (getting this by dividing by 254016000000) to do some simple maths for my Automation. Later on I want to use this value to insert another clip at a certain caltulated point like this: activeSequence.videoTracks[0].insertClip(PartB, "[calculated point]"). What ever I do, I receive 'illegal parameter' warning. Maybe you can help me..thanks!