AWS lambda function - call multiple block inside issue












0















I am call three block inside aws lambda function so there i want to execute call code block one by one means should be wait executetion time
can see my code



in this i have mentioned first block, second block and third block
i want to execute my first block code after that run second block and then third block should be execute.



I never want to use setTimeout function, i think this is not correct.



'use strict';

const ffmpeg = require("fluent-ffmpeg");

const finalVideoPath = __dirname + "/bin/video.mp4";

const margeVideoPath = __dirname + "/video/videofinal.mp4";

const Jimp = require("jimp");

const frames = [

__dirname + "/images/FullSizeRender-1.jpg",
__dirname + "/images/FullSizeRender-2.jpg",
__dirname + "/images/FullSizeRender-3.jpg",
__dirname + "/images/FullSizeRender-4.jpg",
__dirname + "/images/FullSizeRender-5.jpg",
__dirname + "/images/FullSizeRender-6.jpg",
__dirname + "/images/FullSizeRender-7.jpg",
__dirname + "/images/FullSizeRender-8.jpg",
__dirname + "/images/FullSizeRender-9.jpg",
__dirname + "/images/FullSizeRender-10.jpg",
__dirname + "/images/FullSizeRender-11.jpg",
__dirname + "/images/FullSizeRender-12.jpg",
__dirname + "/images/FullSizeRender-13.jpg",
__dirname + "/images/FullSizeRender-14.jpg",
__dirname + "/images/FullSizeRender-15.jpg",
__dirname + "/images/FullSizeRender-16.jpg",

];

module.exports.hello = async function

(event, context, callback) {
return new Promise(function (resolve, reject) {




/* First block*/
//resize images
frames.forEach(element => {
Jimp.read(element, (err, lenna) => {
if (err) console.log('error', err);
lenna
.resize(1000, 1000) // resize
.quality(10) // set JPEG quality
.write(element); // save
});
console.log('resize');
});


/* second block*/
//create video
setTimeout(() => {
ffmpeg().addInput(__dirname + "/images/FullSizeRender-%1d.jpg")
.complexFilter([{
filter: "zoompan",
options: {
x: "iw/2-(iw/zoom/2)",
y: "ih/2-(ih/zoom/2)",
z: "if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0040))",
d: "125",
s: "200x200"
}
}])
.addInputOption(["-framerate 20", ])
.addOutputOption(["-c:v libx264", "-r 30", "-pix_fmt yuv420p"])
.addOption("-crf", 26)
.format("mp4")
.videoBitrate("1024k")
.videoCodec("mpeg4")
.on("error", function (er) {
console.log("error occured: " + er.message, er);
reject('er.message');
})
.on("end", function (data) {
console.log("created video has been completed");

}).save(finalVideoPath);

}, 10000);


/* thitrd block*/
// marge video
setTimeout(() => {

new ffmpeg({
source: finalVideoPath,
nolog: true,
})
.mergeAdd(__dirname + "/video/video.mp4")
.mergeAdd(__dirname + "/video/video2.mp4")
.mergeToFile(margeVideoPath, function () {

console.log("marge video");
resolve();
});


}, 20000);

})


};









share|improve this question



























    0















    I am call three block inside aws lambda function so there i want to execute call code block one by one means should be wait executetion time
    can see my code



    in this i have mentioned first block, second block and third block
    i want to execute my first block code after that run second block and then third block should be execute.



    I never want to use setTimeout function, i think this is not correct.



    'use strict';

    const ffmpeg = require("fluent-ffmpeg");

    const finalVideoPath = __dirname + "/bin/video.mp4";

    const margeVideoPath = __dirname + "/video/videofinal.mp4";

    const Jimp = require("jimp");

    const frames = [

    __dirname + "/images/FullSizeRender-1.jpg",
    __dirname + "/images/FullSizeRender-2.jpg",
    __dirname + "/images/FullSizeRender-3.jpg",
    __dirname + "/images/FullSizeRender-4.jpg",
    __dirname + "/images/FullSizeRender-5.jpg",
    __dirname + "/images/FullSizeRender-6.jpg",
    __dirname + "/images/FullSizeRender-7.jpg",
    __dirname + "/images/FullSizeRender-8.jpg",
    __dirname + "/images/FullSizeRender-9.jpg",
    __dirname + "/images/FullSizeRender-10.jpg",
    __dirname + "/images/FullSizeRender-11.jpg",
    __dirname + "/images/FullSizeRender-12.jpg",
    __dirname + "/images/FullSizeRender-13.jpg",
    __dirname + "/images/FullSizeRender-14.jpg",
    __dirname + "/images/FullSizeRender-15.jpg",
    __dirname + "/images/FullSizeRender-16.jpg",

    ];

    module.exports.hello = async function

    (event, context, callback) {
    return new Promise(function (resolve, reject) {




    /* First block*/
    //resize images
    frames.forEach(element => {
    Jimp.read(element, (err, lenna) => {
    if (err) console.log('error', err);
    lenna
    .resize(1000, 1000) // resize
    .quality(10) // set JPEG quality
    .write(element); // save
    });
    console.log('resize');
    });


    /* second block*/
    //create video
    setTimeout(() => {
    ffmpeg().addInput(__dirname + "/images/FullSizeRender-%1d.jpg")
    .complexFilter([{
    filter: "zoompan",
    options: {
    x: "iw/2-(iw/zoom/2)",
    y: "ih/2-(ih/zoom/2)",
    z: "if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0040))",
    d: "125",
    s: "200x200"
    }
    }])
    .addInputOption(["-framerate 20", ])
    .addOutputOption(["-c:v libx264", "-r 30", "-pix_fmt yuv420p"])
    .addOption("-crf", 26)
    .format("mp4")
    .videoBitrate("1024k")
    .videoCodec("mpeg4")
    .on("error", function (er) {
    console.log("error occured: " + er.message, er);
    reject('er.message');
    })
    .on("end", function (data) {
    console.log("created video has been completed");

    }).save(finalVideoPath);

    }, 10000);


    /* thitrd block*/
    // marge video
    setTimeout(() => {

    new ffmpeg({
    source: finalVideoPath,
    nolog: true,
    })
    .mergeAdd(__dirname + "/video/video.mp4")
    .mergeAdd(__dirname + "/video/video2.mp4")
    .mergeToFile(margeVideoPath, function () {

    console.log("marge video");
    resolve();
    });


    }, 20000);

    })


    };









    share|improve this question

























      0












      0








      0








      I am call three block inside aws lambda function so there i want to execute call code block one by one means should be wait executetion time
      can see my code



      in this i have mentioned first block, second block and third block
      i want to execute my first block code after that run second block and then third block should be execute.



      I never want to use setTimeout function, i think this is not correct.



      'use strict';

      const ffmpeg = require("fluent-ffmpeg");

      const finalVideoPath = __dirname + "/bin/video.mp4";

      const margeVideoPath = __dirname + "/video/videofinal.mp4";

      const Jimp = require("jimp");

      const frames = [

      __dirname + "/images/FullSizeRender-1.jpg",
      __dirname + "/images/FullSizeRender-2.jpg",
      __dirname + "/images/FullSizeRender-3.jpg",
      __dirname + "/images/FullSizeRender-4.jpg",
      __dirname + "/images/FullSizeRender-5.jpg",
      __dirname + "/images/FullSizeRender-6.jpg",
      __dirname + "/images/FullSizeRender-7.jpg",
      __dirname + "/images/FullSizeRender-8.jpg",
      __dirname + "/images/FullSizeRender-9.jpg",
      __dirname + "/images/FullSizeRender-10.jpg",
      __dirname + "/images/FullSizeRender-11.jpg",
      __dirname + "/images/FullSizeRender-12.jpg",
      __dirname + "/images/FullSizeRender-13.jpg",
      __dirname + "/images/FullSizeRender-14.jpg",
      __dirname + "/images/FullSizeRender-15.jpg",
      __dirname + "/images/FullSizeRender-16.jpg",

      ];

      module.exports.hello = async function

      (event, context, callback) {
      return new Promise(function (resolve, reject) {




      /* First block*/
      //resize images
      frames.forEach(element => {
      Jimp.read(element, (err, lenna) => {
      if (err) console.log('error', err);
      lenna
      .resize(1000, 1000) // resize
      .quality(10) // set JPEG quality
      .write(element); // save
      });
      console.log('resize');
      });


      /* second block*/
      //create video
      setTimeout(() => {
      ffmpeg().addInput(__dirname + "/images/FullSizeRender-%1d.jpg")
      .complexFilter([{
      filter: "zoompan",
      options: {
      x: "iw/2-(iw/zoom/2)",
      y: "ih/2-(ih/zoom/2)",
      z: "if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0040))",
      d: "125",
      s: "200x200"
      }
      }])
      .addInputOption(["-framerate 20", ])
      .addOutputOption(["-c:v libx264", "-r 30", "-pix_fmt yuv420p"])
      .addOption("-crf", 26)
      .format("mp4")
      .videoBitrate("1024k")
      .videoCodec("mpeg4")
      .on("error", function (er) {
      console.log("error occured: " + er.message, er);
      reject('er.message');
      })
      .on("end", function (data) {
      console.log("created video has been completed");

      }).save(finalVideoPath);

      }, 10000);


      /* thitrd block*/
      // marge video
      setTimeout(() => {

      new ffmpeg({
      source: finalVideoPath,
      nolog: true,
      })
      .mergeAdd(__dirname + "/video/video.mp4")
      .mergeAdd(__dirname + "/video/video2.mp4")
      .mergeToFile(margeVideoPath, function () {

      console.log("marge video");
      resolve();
      });


      }, 20000);

      })


      };









      share|improve this question














      I am call three block inside aws lambda function so there i want to execute call code block one by one means should be wait executetion time
      can see my code



      in this i have mentioned first block, second block and third block
      i want to execute my first block code after that run second block and then third block should be execute.



      I never want to use setTimeout function, i think this is not correct.



      'use strict';

      const ffmpeg = require("fluent-ffmpeg");

      const finalVideoPath = __dirname + "/bin/video.mp4";

      const margeVideoPath = __dirname + "/video/videofinal.mp4";

      const Jimp = require("jimp");

      const frames = [

      __dirname + "/images/FullSizeRender-1.jpg",
      __dirname + "/images/FullSizeRender-2.jpg",
      __dirname + "/images/FullSizeRender-3.jpg",
      __dirname + "/images/FullSizeRender-4.jpg",
      __dirname + "/images/FullSizeRender-5.jpg",
      __dirname + "/images/FullSizeRender-6.jpg",
      __dirname + "/images/FullSizeRender-7.jpg",
      __dirname + "/images/FullSizeRender-8.jpg",
      __dirname + "/images/FullSizeRender-9.jpg",
      __dirname + "/images/FullSizeRender-10.jpg",
      __dirname + "/images/FullSizeRender-11.jpg",
      __dirname + "/images/FullSizeRender-12.jpg",
      __dirname + "/images/FullSizeRender-13.jpg",
      __dirname + "/images/FullSizeRender-14.jpg",
      __dirname + "/images/FullSizeRender-15.jpg",
      __dirname + "/images/FullSizeRender-16.jpg",

      ];

      module.exports.hello = async function

      (event, context, callback) {
      return new Promise(function (resolve, reject) {




      /* First block*/
      //resize images
      frames.forEach(element => {
      Jimp.read(element, (err, lenna) => {
      if (err) console.log('error', err);
      lenna
      .resize(1000, 1000) // resize
      .quality(10) // set JPEG quality
      .write(element); // save
      });
      console.log('resize');
      });


      /* second block*/
      //create video
      setTimeout(() => {
      ffmpeg().addInput(__dirname + "/images/FullSizeRender-%1d.jpg")
      .complexFilter([{
      filter: "zoompan",
      options: {
      x: "iw/2-(iw/zoom/2)",
      y: "ih/2-(ih/zoom/2)",
      z: "if(lte(zoom,1.0),1.5,max(1.001,zoom-0.0040))",
      d: "125",
      s: "200x200"
      }
      }])
      .addInputOption(["-framerate 20", ])
      .addOutputOption(["-c:v libx264", "-r 30", "-pix_fmt yuv420p"])
      .addOption("-crf", 26)
      .format("mp4")
      .videoBitrate("1024k")
      .videoCodec("mpeg4")
      .on("error", function (er) {
      console.log("error occured: " + er.message, er);
      reject('er.message');
      })
      .on("end", function (data) {
      console.log("created video has been completed");

      }).save(finalVideoPath);

      }, 10000);


      /* thitrd block*/
      // marge video
      setTimeout(() => {

      new ffmpeg({
      source: finalVideoPath,
      nolog: true,
      })
      .mergeAdd(__dirname + "/video/video.mp4")
      .mergeAdd(__dirname + "/video/video2.mp4")
      .mergeToFile(margeVideoPath, function () {

      console.log("marge video");
      resolve();
      });


      }, 20000);

      })


      };






      node.js aws-lambda






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 17 '18 at 5:49









      Pramod GehlotPramod Gehlot

      116211




      116211
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348613%2faws-lambda-function-call-multiple-block-inside-issue%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348613%2faws-lambda-function-call-multiple-block-inside-issue%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)