• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

PremirePro create subclips from CSV file script

New Here ,
Feb 21, 2023 Feb 21, 2023

Copy link to clipboard

Copied

I have been trying to create subclips from CSV file. Everything runs ok. But the new subclip doesn't have in and out points. I'm not sure if it's because is smpte - timecode format ( hour:minute:second:frame ). let me know what you think . Thank you so much if you can help me 

Screen Shot 2023-02-21 at 12.29.30 PM.png

 

 

 

here is the code

app.project.rootItem.createBin("Subclips"); // CREATE BIN FR OUR SUBCLIPS
var moveTo = findBinIndex(app.project.rootItem,"Subclips");

// LOOP THROUGH OUR IMPORTED CLIPS TO CREATE THE EDITED SUBCLIPS.
var numItems = importBin.children.length;

for(a=0;a<numItems;a++){
var currentItem = importBin.children[a];
for (var i = 0; i < infoArray.length; i++) { // LOOP THROUGH INFO ARRAY
 
if(currentItem.type == 1 && currentItem.nodeId == infoArray[ i ][ infoArray[i].length-1 ]){ // CHECK THAT ITEM IS A CLIP, AND THAT THE NODEID'S MATCH WITH OUR CSV LINE.

var inPoint = infoArray[i][2]; // GATHER TIMECODE INFORMATION INTO A FLAT SECONDS NUMBER
var outPoint = infoArray[i][2];
 
var newSub = currentItem.createSubClip(infoArray[i][0] , inPoint , outPoint , 0 , 1 , 1 ); // CREATE THE SUBCLIPS ( NAME , IN , OUT , BOUNDARIES (BINARY) , TAKE VIDEO , TAKE AUDIO)
newSub.moveBin(moveTo); // MOVE INTO THE SUBCLIPS BIN
 
}
}
}
TOPICS
Editing , Formats , Import , SDK

Views

928

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Feb 23, 2023 Feb 23, 2023

still don't see you declaring or using any Time objects. 🙂

> var inPoint = infoArray[i][2]

Presumably, that variable points to a text representation of timecode, right? You would need to create a Time object that represents the time, represented by that text.

Votes

Translate

Translate
Adobe Employee ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

I don't see any code that 'gathers timecode information into a flat seconds number'...?

createSubClip() takes Time objects as parameters, to set in and out points. Where are you creating those Time objects? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

Hi Bruce!

 

Thank you so much for taking a look. 

 

// GATHER TIMECODE INFORMATION INTO A FLAT SECONDS NUMBER (ignored this. I forgot to delete this comment) Actually I don't want to have flat seconds, In my CSV file I use smpte-timecode (hh:mm:ss:ff)

 

here is how it looks my csv file

Screen Shot 2023-02-23 at 9.03.53 AM.png

when I run the code it works great, Import the file and create the sublips assign the name, but the problem is with the In and Out 

here is the result when it imports the subclips, the In and Out are random numbers. It's like the infoArray is not taking the timecode

Screen Shot 2023-02-23 at 9.11.27 AM.png

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

here is the full code


var csvFile = File.openDialog ("Target CSV File","*.csv"); // PROMPT FOR CSV FILE
var csvFile = csvFile.fsName; // FORMAT CSV FILEPATH TO BE FRIENDLY

app.project.createNewSequence("Auto Seq", ""); // PROMPT TO CREATE A NEW SEQUENCE

var infoArray;
var bufferTime = 2; // HOW MUCH TIME (IN SECONDS) BETWEEN CLIPS WHEN PLACED IN TIMELINE

// Following opens the text file and stores it in var CSVFILE. Then splits it by every new line, and COMA into a multi-tiered array, INFOARRAY.
if(csvFile){
 
var file = File(csvFile) //OPEN, READ, AND CLOSE THE CSV FILE
file.open("r");
var fullText = file.read();
file.close();

infoArray = fullText.split("\n"); // SPLIT THE CSV FILE AT EVERY NEW LINE
 
for(var a=0;a<infoArray.length;a++){ // LOOP THROUGH EACH LINE, SPLIT THE LINE AT EVERY COMMA
infoArray[a] = infoArray[a].split(",");
}
}

if(infoArray[infoArray.length -1] == ""){ //SOMETIMES WHEN SPLITTING UP THE ARRAY, THE PROCESS CREATES AN EXTRA, EMPTY LINE. tHIS WILL JUST TEST AND REMOVE THAT IF IT HAPPENS
infoArray.splice(infoArray.length-1, 1)
}



app.project.rootItem.createBin("Original Clips"); // CREATE BIN FOR ORGANIZATION
var importBin = findBinIndex(app.project.rootItem,"Original Clips"); // STORE THE INDEX PATH TO THAT BIN

// IMPORTARY TO LOAD FILES. THIS IS WHERE YOU ADJUST FILEPATHS IF YOU NEED TO
var importAry = [];

// LOOP THROUGH INFOARRAY
if (infoArray){
for (var i = 1; i < infoArray.length; i++) { // START WITH i AS 1 BECAUSE THE FIRST LINE OF OUR CSV IS HEADERS
importAry[0] = infoArray[i][3]; // SET importAry ITEM TO THE FILEPATH. fORMAT CORRECTLY HERE
 
app.project.importFiles(importAry,1,importBin,0); // IMPORT ONE MOVIE AT A TIME INTO THE NEW BIN, SO WE CAN RENAME IT ACCORDINGLY AS IT COMES IN
importCount++;
 
for (var a = 0; a < importBin.children.numItems; a++){ // LOOP THROUGH THE IMPORT BIN
if( importBin.children[a].name.indexOf(" - ")==-1){
importBin.children[a].name = " "+ importCount + " - " + importBin.children[a].name; // RENAME WITH A THE NUMBER IT WAS IMPORTED, THIS HOLDS THE ORDER OF THE CSV
infoArray[i][infoArray[i].length] = importBin.children[a].nodeId; // STORE THE ITEMS NODEID IN THE CSV ARRAY
}
}
}
}


//~ /* ================================================= END VIDEO 1 ===============================================================*/

app.project.rootItem.createBin("Subclips"); // CREATE BIN FR OUR SUBCLIPS
var moveTo = findBinIndex(app.project.rootItem,"Subclips");

for(a=0;a<app.project.sequences.numSequences;a++){ // LOOP THROUGH ALL SEQS
if(app.project.sequences[a].name=="Auto Seq"){ // FIND OUR CREATED SEQUENCE
app.project.activeSequence = app.project.sequences[a]; // SET THE SEQUENCE TO BE OUR ACTIVE SEQ
}
}


// LOOP THROUGH OUR IMPORTED CLIPS TO CREATE THE EDITED SUBCLIPS.
var numItems = importBin.children.numItems;

for(a=0;a<numItems;a++){
var currentItem = importBin.children[a];
for (var i = 1; i < infoArray.length; i++) { // LOOP THROUGH INFO ARRAY
 
if(currentItem.type == 1 && currentItem.nodeId == infoArray[ i ][ infoArray[i].length-1 ]){ // CHECK THAT ITEM IS A CLIP, AND THAT THE NODEID'S MATCH WITH OUR CSV LINE.

var subclipStart = (infoArray[i][1]);
var subclipEnd = (infoArray[i][2]);
 
var newSub = currentItem.createSubClip(infoArray[i][0] , subclipStart , subclipEnd , 0 , 1 , 1 ); // CREATE THE SUBCLIPS ( NAME , IN , OUT , BOUNDARIES (BINARY) , TAKE VIDEO , TAKE AUDIO)
newSub.moveBin(moveTo); // MOVE INTO THE SUBCLIPS BIN
 
var activeSeq = app.project.activeSequence;
placeClip(activeSeq, newSub , bufferTime); //subCounter++;
}
}
}

/* ================================================= WOOHOO WERE DONE! ===============================================================*/

// FUNCTION LIST
function findBinIndex(currentItem, nameToFind){
if(nameToFind){
for (var j = 0; j < currentItem.children.numItems; j++){
var currentChild = currentItem.children[j];
 
if (currentChild.type == ProjectItemType.BIN && currentChild.name.toUpperCase() == nameToFind.toUpperCase() ){
globalBind = currentChild;
return currentChild;
}
 
if (currentChild.type == ProjectItemType.BIN){
findBinIndex(currentChild, nameToFind);
}
}
 
} else {
alert("No bin was targeted");
}
}
function timecodeToSeconds(arrayObject){     (I avoid this function because I don't want flat number seconds)
var timeCodeArray = [];
timeCodeArray = arrayObject.split(":");
var timeCode = (Number(timeCodeArray[0])*60) + Number((timeCodeArray[1]));
return timeCode;
}

function placeClip(activeSeq , subClip , buffer){
subClip.setScaleToFrameSize();// SET SCALE TO FRAME SIZE
 
if(activeSeq.videoTracks[0].clips.numItems == 0){ // IF THERE ARE NOT CLIPS IN THE SEQUENCE, PLACE FRIST CLIP AT TIME ZERO
activeSeq.videoTracks[0].insertClip(subClip,0)
//clipCounter++;
} else { // IF THERE ARE CLIPS IN THE SEQUENCE, PLACE AT THE TIMECODE OF END OF THE LAS CLIP + THE BUFFER TIME
var numClips = activeSeq.videoTracks[0].clips.numItems;
var insertTime = activeSeq.videoTracks[0].clips[numClips - 1].end.seconds + buffer;
activeSeq.videoTracks[0].insertClip(subClip,insertTime);
//clipCounter++;
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

still don't see you declaring or using any Time objects. 🙂

> var inPoint = infoArray[i][2]

Presumably, that variable points to a text representation of timecode, right? You would need to create a Time object that represents the time, represented by that text.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

Thank you so much! I'll try to look on the internet if I can find a code. I'm a video editor; I'm not coding but I can try to figure it out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

No promises, but...send me a representative .csv file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 23, 2023 Feb 23, 2023

Copy link to clipboard

Copied

LATEST

Sent it!  thank you so much. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines