1

I am using react-media-recorder to record the video on ReactJS application which further sends to my NodeJS backend to cut and contact/merge video using fluent-ffmpeg and ffmpeg-concat, before merging the video I am making all the uploaded video to same size 640x360.

NodeJS code to cut the video and make the same size 640x360 before merging, also added padding to keep the consistency of video ratio.

const allCutVideos = await Promise.all(convertVideoList.map(async (row) => {

  return await new Promise((resolve) => {

   ffmpeg(row.uploadedFile)
    .setStartTime(row.startTime)
    .setDuration(row.endTime)
    .size("640x360")
    .autopad()
    .withAudioCodec('copy')
    .on("start", function (commandLine) {
      console.log("Spawned FFmpeg with command: " + commandLine);
    })
    .on("error", function (err) {
      resolve({ ...row, status: false, message: err.message })
    })
    .on("end", function (err) {
      if (!err) {
        resolve({ ...row, status: true });
      }
    })
    .output(row.outputPath)
    .run();

  });

}));

Once I get all the video(recorded video or any mp4 which are downloaded from internet) from the above promises, I am merging it using ffmpeg-concat, below is the code

const contactVideoList = allCutVideos.map(row => row.status === true ? row.outputPath : null).filter(row => row);
await ContactVideos({
  output: "/app/folder/tmp/output.mp4",
  videos: contactVideoList,
  transition: {
    name: 'directionalWipe',
    duration: 500
  }
});

Here is my Dockerfile

FROM node:14
RUN mkdir /opt/prod_api
WORKDIR /opt/prod_api

RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg

COPY . .

RUN chmod 777 -R /opt

ENTRYPOINT ["/opt/prod_api/entrypoint.sh"]
EXPOSE 8080

On my local the above process working as expected (using macOS), I do not get any error while performing.

When I tried the same code using Dockerfile I get the below problems.

Problem 1: I am cutting video with fluent-ffmpeg which is recorded through react-media-recorder, I get error TypeError: Cannot destructure property 'width' of 'scenes[0]' as it is undefined., and here is full ffmpeg command, here I am getting error while cutting and resizing video.

ffmpeg -ss 0 -i /opt/prod_api/assets/tmp/6b7286081d/3fb0e15881097c1aa93f8393f863e79.mp4 -y -acodec copy -filter:v scale=w='if(gt(a,1.7777777777777777),640,trunc(360*a/2)*2)':h='if(lt(a,1.7777777777777777),360,trunc(640/a/2)*2)',pad=w=640:h=360:x='if(gt(a,1.7777777777777777),0,(640-iw)/2)':y='if(lt(a,1.7777777777777777),0,(360-ih)/2)':color=black -t 12.23 /opt/prod_api/assets/tmp/6b7286081d/9b6e5551011d120289b906abd2f2b69_output.mp4

Problem 2: After uploading any mp4 video which is download from the internet I do get another error while performing an action using ffmpeg-concat. Error - Failed to create OpenGL context. Please see https://github.com/stackgl/headless-gl#supported-platforms-and-nodejs-versions for compatibility. failed to create OpenGL context. (here in this case I do not get any error while performing fluent-ffmpeg)

Am I missing any steps in Dockerfile? Everything works fine in my local but getting the above problems in Docker container. Any help would be appreciated, thank you in advance.

Keval savani
  • 45
  • 1
  • 3
  • 11

0 Answers0