Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help-wanted 2 or more projects #41

Closed
leq382121 opened this issue Sep 11, 2017 · 6 comments
Closed

help-wanted 2 or more projects #41

leq382121 opened this issue Sep 11, 2017 · 6 comments

Comments

@leq382121
Copy link

Hey there, maybe you have some sort of example/code snippet how to make 2 or more projects by one run? Thanks!

@inlife
Copy link
Owner

inlife commented Sep 11, 2017

Hello,

What do you mean by "one-run" ?

@leq382121
Copy link
Author

leq382121 commented Sep 11, 2017

I mean like "node start.js" and it results 2+ projects by one run. For example, i have one template and i want to make 3 videos for 3 countries. The things are the same, just images are different. So I have this:

let project = new Project(
    {
        "template": "projektaz.aepx",
        "composition": "comp1",
        "type": "default",
        "settings": {
            "outputModule": "Lossless"
        },
        "assets": [
            { "type": "project", "name": "projektass.aepx",  "src": `http://localhost:${port}/assets/${aepxfile}`}, //1024x683 / 1280 720
            { "type": "image",   "name": "Fotolia_45139233_Subscription_Monthly_M.jpg",  "src": `http://localhost:${port}/assets/${background1}`, "filters": [ {"name":"cover", "params": [1688, 1126] }] },
            { "type": "image",   "name": "Fotolia_82766733_Subscription_Monthly_M.jpg",  "src": `http://localhost:${port}/assets/${background2}`, "filters": [ {"name":"cover", "params": [1688, 1126] }] },
            { "type": "image",   "name": "Fotolia_85037185_Subscription_Monthly_M.jpg",  "src": `http://localhost:${port}/assets/${background3}`, "filters": [ {"name":"cover", "params": [1688, 1126] }] },
        ]
    }
);

and this is the data for one video, but i want 3 videos f.ex. I tried to create 3 new let's for project class, but it renders just first one and he skips other two. I'm still a Junior dev so sorry in advance.. 🥇

@inlife
Copy link
Owner

inlife commented Sep 11, 2017

oh i see
well you've created 3 projects, but i believe you are still running only one of them
cuz the actual render code for your needs can look like this:

// start rendering
renderer.render(aebinary, project1).then(() => console.log('project1 finished')).catch(err => console.error(err));
renderer.render(aebinary, project2).then(() => console.log('project2 finished')).catch(err => console.error(err));
renderer.render(aebinary, project3).then(() => console.log('project3 finished')).catch(err => console.error(err));

also, if you i suggest you to read more about js promises, this is a good concept to understand for any js environment/project

@leq382121
Copy link
Author

I've came across it before, but I'm trying to figure out f.ex. if i have 200+ videos or unknown ammount and use some alternative like array.length . I've tried to make a for loop and repeat it 5 times [still hardcoded, but less code], but it started to render all at once and, of course, it stuck on loop and crashed. I'm also thinking of recursive counter and somehow i thought you will be definitely using this.. :D

@inlife
Copy link
Owner

inlife commented Sep 11, 2017

oh in case if you need variable amount of videos to render i can suggest you something like this:

let projects = []; // lets say this is array with Project objects

function render() {
    if (!projects.length) {
        return console.log('no more projects');
    }

    // otherwise take project and start rendering
    let project = projects.pop();
    
    // after finish or error, it will pick up next item recursively and start rendering
    renderer.render(aebinary, project).then(() => {
        console.log('one of the projects finished'); render()
    }).catch(err => {
        console.error('error happened in one of the projects', err); render()
    })
}

// start 3 rendering queues
for (var i = 0; i < 3; i++) {
    render();
}

@leq382121
Copy link
Author

Just a small fix for your code:

instead of only using array.pop:
let project = projects.pop();

You have to initiate a new class since your project.js requires it:
let project = new Project(projects.pop());

IT works perfectly. now I'm going to try solve the project naming challenge and saving the templates instead of unlinking them after render. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants