title: Concatenate mp4 video files using ffmpeg on nodejs
body: <p>I'm trying to concatenate several videos using FFmpeg with Nodejs. I'm receiving the &quot;No such file or directory&quot; error. The written code is:</p>
  <pre><code>const glob = require(&quot;glob&quot;);
  
  //store all the filenames with path to the videos
  var inputVideos = glob.sync(&quot;/home/r/clips/*.mp4&quot;);
  const output = &quot;./output/output.mp4&quot;;
  
  const util = require(&quot;util&quot;);
  const exec = util.promisify(require(&quot;child_process&quot;).exec);
  
  async function concatVideos(inputVideos, outputVideoPath) {
    
  
    //imported to get the name of videofile easily
    var path = require(&quot;path&quot;);
  
    //the next ffmpeger variable,will keep the lines
    //ffmpeg -i videofile1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate_videofile1.ts
    //ffmpeg -i videofile2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate2_videofile2.ts
  
  var ffmpeger = &quot;&quot;;
    ffmpeger = inputVideos
      .map(
        video =&gt;
          ` ffmpeg -i ${video} -c copy
      -bsf:v h264_mp4toannexb -f mpegts ./intermediate_${
        path.parse(video).name
      }.ts`
      )
      .join(&quot;\n&quot;);
  
    //concatenator keeps the segment
    //&quot;concat:intermediate_videofile1.ts|intermediate_videofile2.ts&quot;
    var concatenator = '&quot;concat:';
    concatenator +=
      inputVideos
        .map(video =&gt; `./intermediate_${path.parse(video).name}.ts`)
        .join(&quot;|&quot;) + '&quot;';
  
    await exec(
      `
      ${ffmpeger}
      ffmpeg -i ${concatenator} -c copy -bsf:a aac_adtstoasc ${outputVideoPath}`
    );
  }
  concatVideos(inputVideos, output);
  
  </code></pre>
  <p>and the error is</p>
  <pre><code>concat:./intermediate_0.ts|./intermediate_1.ts|./intermediate_2.ts|./intermediate_3.ts|./intermediate_4.ts|./intermediate_5.ts|./intermediate_6.ts|./intermediate_diegoortiz1399.ts|./intermediate_dog.ts|./intermediate_dogstify.ts|./intermediate_dylan50568.ts|./intermediate_gabrieleecorrea.ts|./intermediate_golden_leo.ts|./intermediate_helenapatiih.ts|./intermediate_kaiobreno2.ts|./intermediate_khancorso.ts|./intermediate_kitakaze_s_lili.ts|./intermediate_oliver45743.ts|./intermediate_pinkie_pets.ts|./intermediate_shibakoma.ts|./intermediate_thepetcollective.ts|./intermediate_tod_the_foxx.ts|./intermediate_userpub3y9m7kb.ts|./intermediate_warriorbulldogs.ts: No such file or directory```
  
  So the command line would be:
  </code></pre>
  <p>ffmpeg -i videofile1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate_videofile1.ts
  ffmpeg -i videofile2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate_videofile2.ts
  ffmpeg -i &quot;concat:intermediate_videofile1.ts|intermediate_videofile2.ts&quot; -c copy -bsf:a aac_adtstoasc ./output/output.mp4</p>
  <p>Could you help us? Many thanks. Truly.:&gt;</p>