laravel-ffmpeg icon indicating copy to clipboard operation
laravel-ffmpeg copied to clipboard

TypeError in getDurationInMiliseconds()

Open rcerljenko opened this issue 2 years ago • 3 comments

Hi,

First of all many thanks for this package! It's awesome! You have a slight TypeError bug in getting video duration function:

ProtoneMedia\LaravelFFMpeg\Drivers\PHPFFMpeg::getDurationInMiliseconds(): Return value must be of type int, none returned

Seps to reproduce:

  1. Try to open any non-video file (eg. image)
  2. Try to get duration from it:
FFMpeg::open('/path/to/image.jpg')->getDurationInSeconds();

Since this function returns an int in your code, the obvious solution would be to either return 0 in the end of the function or to change function signature to return ?int and return null instead.

Third option would be to throw a custom Exception just for this case so that we can catch it in user space.

I can provide a PR depending on the option that you choose to proceed on.

rcerljenko avatar Feb 11 '22 08:02 rcerljenko

A PR with an exception would be great! Just wondering though, why would want to call that method on an image?

pascalbaljet avatar Feb 11 '22 10:02 pascalbaljet

Ok I'll provide a PR with Exception approach. Reason is that I'm using this code in custom Laravel file upload validation rule and user can upload any file they want.

rcerljenko avatar Feb 11 '22 10:02 rcerljenko

Here it is: https://github.com/protonemedia/laravel-ffmpeg/pull/380 I've used PHP base Exception but if you want I can create a special one just for this.

rcerljenko avatar Feb 11 '22 10:02 rcerljenko