1

Hope everyone doing well.

I have a nodejs project, in which I am allowing the end user to upload images/videos. And in nodejs (express) I am receiving the media file using express-fileupload package, which basically attaches files property in request object. Now I want to check the video duration from the buffer data which express-fileupload attaches to the request object.

Here is the req.files object structure:

{
  media: {
    name: 'filename.mp4',
    data: <Buffer 00 00 00 18 66 74 79 70 6d 70 34 32 00 00 00 00 69 73 6f 6d 6d 70 34 32 00 00 27 03 6d 6f 6f 76 00 00 00 6c 6d 76 68 64 00 00 00 00 d9 af 85 a8 d9 af ... 1832626 more bytes>,
    size: 1832676,
    encoding: '7bit',
    tempFilePath: '',
    truncated: false,
    mimetype: 'video/mp4',
    md5: 'e01d7091f886e84769c2c05c77a83a06',
    mv: [Function: mv]
  }
}

** Note: size is available in bytes. (e.g: 1832676 / 1000000 = 1.8 MB video)

Now using this Buffer data, I want to check the duration of this video. I can check mimetype/extension & size of video, but not able to check the duration.

Any package is available out there or any other way of checking the duration?

Any kind of help will be greatly appreciated.

Shivam Verma
  • 905
  • 1
  • 8
  • 20
  • 1
    Well if video is being uploaded from client i.e browser then why don't you extract video information like filename, duration, extension etc extract at client side and send it to server with binary data of video. – Pawan Bishnoi Jun 02 '21 at 12:06
  • Ok this can be alternate solution, thanks for sharing the idea. If I won't get any package, in that case I will go with your solution. Thanks man :) – Shivam Verma Jun 03 '21 at 03:45
  • ffprobe is part of ffmpeg, and you can call it with NodeJS. It'll tell you duration, codecs, and a lot more. (example with ink to Github repo at https://ffprobe.a.video) – Doug Sillars Jun 04 '21 at 20:57
  • @PawanBishnoi This breaks the rule of never trusting the client. – twominds Apr 06 '22 at 20:36
  • @twominds if you are so concerned of security then send the data in encrypted form. – Pawan Bishnoi Apr 07 '22 at 04:15
  • @PawanBishnoi That has nothing to do with not trusting the client. Someone could upload a video at 1920x1080 but state in the requesting data that the video is actually 3840x2160 in order to have the servers upscale the video and utilize a better codec. Encryption only prevents middleman attacks. – twominds Apr 07 '22 at 13:24
  • @twominds i think your knowledge of encryption comes from Https, i am asking you to encrypt your API payload so whenever user selects the file then grab the metadata of file, encrypt the information and send to server so that end users can't see what is being sent to servers. – Pawan Bishnoi Apr 08 '22 at 03:36

0 Answers0