Sara Ree
Sara Ree

Reputation: 3543

How to trim a video stored in another sever via our node.js server

Trinning a video in Node.js is as easy as:

const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path
const ffmpeg = require('fluent-ffmpeg')
ffmpeg.setFfmpegPath(ffmpegPath)

    ffmpeg('path_to_video_on_server/video.mp4')
      .setStartTime('00:00:03')
      .setDuration('10')
      .output('video_out.mp4')
      .on('end', function(err) {
        if(!err) { console.log('conversion Done') }
      })
      .on('error', err => console.log('error: ', err))
      .run()

But the issue is what if we store our videos in another server?

I mean now we have a path for the video like :

path_to_video_on_server/video.mp4

But what if we have this video in another server with this path:

www.example.com/path_to_video_on_server/video.mp4 

Does replacing this new path work ?

If not how to trim a video stored in another sever via our node.js server ?

Upvotes: 0

Views: 230

Answers (1)

yeya
yeya

Reputation: 2204

There is no way to convert a file without having it somehow in your server memory.

The ffmpeg process needs to process the file data, otherwise you will not get any output.

There is a lot of options to solve it.

  1. Download the file to your local server with axios or similar, then use ffmpeg as you used to.
  2. Use external tool like rclone to mount the remote files, then use ffmpeg as you used to.
  3. Provide ffmpeg with a readStream of the file (can be done with axios too), that way your server will not have to store the entire original file.

It looks like you need only the first 10 seconds, so using a readStream is probably the best option, but also the most advanced. You need to learn how to use streams, and correctly handle streams errors.

Upvotes: 1

Related Questions