0

I've the following code that creates a screenshot for the video I've uploaded;

var thumbFileName = 'tmp_file.jpg';

ffmpegCommand = ffmpeg(videoFile)
  .on('end', function() {
    callback(null, tempUploadDir + thumbFileName)
  })
  .on('error', function(err) {
    callback(err);
  })
  .screenshots({
    timestamps: ['50%'],
    filename: thumbFileName,
    folder: tempUploadDir
  });

the code works pretty well and the screenshot is created. The callback read the file stream and store it into the database and eventually try to delete the thumbFileName from the filesystem.

And here is the issue I'm encountering, basically I'm not able to delete the file, even if I try it manually its say that the file is locked by another process (NodeJS) and I can't download it until I stop the application.

In the callback I've also tried to kill the command with ffmpegCommand.kill() before to delete the screenshot but I'm still having the same issue. The file will be removed using fs.unlink and its working when the thumbnail is generated for an image (even post-processed with effects, achieved with sharp) but not with ffmpeg. Apparently ffmpeg is still running and that's why I can't delete the thumb.

mirg
  • 312
  • 2
  • 16
  • you should be able to get the permissions on the file f-f creates... if u wait until ffmpeg raises the 'onend' event then its process has probably released the fs resources in-use .. So, following 'onend' if your node user has W-permissions then a delete action should work. – Robert Rowntree May 18 '18 at 03:25
  • It has writing permissions, it create the thumb but it can't be deleted. With normal thumbs created with sharp files can be deleted and the code is the same – mirg May 18 '18 at 03:27

0 Answers0