laravel-ffmpeg
laravel-ffmpeg copied to clipboard
TypeError in getDurationInMiliseconds()
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:
- Try to open any non-video file (eg. image)
- 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.
A PR with an exception would be great! Just wondering though, why would want to call that method on an image?
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.
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.