0

I am trying to use azure function to create thumbnail(png) from .mp4 file uploaded to azure storage location. Azure function is automatically triggered when a new video file is uploaded.

The issue that I am facing right now is that FFMPEG required local storage to create thumbnail and azure function does not have local storage attached to it.

I tried to find a way to use azure storage too but we need data stream(buffer) to upload file to azure storage and FFMPEG does not provide output in data stream(buffer).

Language : NodeJS

Following is the code that I am using with FFMPEG:

fs.writeFileSync(pathToCreate, data);
const targetPath = path.join(dirToCreate, 'thumbnail.png');
const width = parseInt(process.env.WIDTH || "360");
const ffmpeg = spawnSync(
    ffmpegStatic, [
    "-y",
    "-i",
    `${pathToCreate}`,
    "-ss",
    "00:00:01",
    "-vf",
    `scale=${width}:-1`,
    "-frames:v",
    "1",
    `${targetPath}`
    ], {
        shell: true
    });

Error when trying to read file is as following:

Error: ENOENT: no such file or directory, open /tmp/temp-file.png

Does anyone has any idea on how to solve this problem?

Regards

vishwas-trivedi
  • 516
  • 2
  • 8
  • 26
  • Does this answer your question? [How to resolve Nodejs: Error: ENOENT: no such file or directory](https://stackoverflow.com/questions/43260643/how-to-resolve-nodejs-error-enoent-no-such-file-or-directory) – Ecstasy Apr 25 '22 at 03:59
  • You can refer to [How to generate video thumbnail in Microsoft Azure function using Nodejs?](https://stackoverflow.com/questions/63136133/how-to-generate-video-thumbnail-in-microsoft-azure-function-using-nodejs) and [Unable to get output from ffprobe within Azure Function](https://stackoverflow.com/questions/57124805/unable-to-get-output-from-ffprobe-within-azure-function) – Ecstasy Apr 25 '22 at 04:09

1 Answers1

0

I would like to recommend the procedure of using fluent-ffmpeg because it can deal with both the images and video file types using withsize() method.

Refer the procedure mentioned in : https://www.npmjs.com/package/video-thumbnail-generator to generate thumbnail from video.

Refer the procedure mentioned in : https://www.npmjs.com/package/fluent-ffmpeg/v/1.7.0#generating-thumbnails to generate thumbnail from fluent-ffmpeg

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

new ffmpeg({ source: '/path/to/video1.extension' })
    .withSize('mention size')
    .on('error', function(err) {
        console.log('An error occurred: ' + err.message);
    })
    .on('end', function(name_of_file) {
        console.log('Thumbnail was successfully generated ' + filenames.join(', '));
    })
    .takeScreenshots(5, '/path/to/location_of_file');

to use the above code block, you must install ffmpeg

Sairam Tadepalli
  • 1,563
  • 1
  • 3
  • 11