protonemedia / laravel-ffmpeg

This package provides an integration with FFmpeg for Laravel. Laravel's Filesystem handles the storage of the files.
https://protone.media/en/blog/how-to-use-ffmpeg-in-your-laravel-projects
MIT License
1.66k stars 194 forks source link

Some Video has been a problem to convert HLS #301

Closed pzanwar03 closed 3 years ago

pzanwar03 commented 3 years ago

Hello Admin,

I got some problem converting HLS. I've fix it could you please fix the problem in the package.

Problem Line number: vendor\pbmedia\laravel-ffmpeg\src\Exporters\HLSPlaylistGenerator.php:34

We need add (int) before $frameRate variable.

image

Also, I've uploaded a video that I got the problem convertingHLS.

https://user-images.githubusercontent.com/25006760/110253453-98d70000-7fb4-11eb-8d70-c3c71341210e.mp4

pascalbaljet commented 3 years ago

What's the problem and how does your solution solve it?

johnpuddephatt commented 3 years ago

When using HLS if I set a format as follows:

$lowBitrateFormat  = (new X264('aac','libx264'))->setKiloBitrate(200)->setAdditionalParameters([
            "-preset",
            "ultrafast",
            "-r",
            16.667
          ]);

I get the following error, which I think is what @pzanwar03 is referring to – line 34 of HLSPlaylistGenerator.php.

ErrorException: A non well formed numeric value encountered in /Users/johnpuddephatt/Sites/mimi2/vendor/pbmedia/laravel-ffmpeg/src/Exporters/HLSPlaylistGenerator.php:34
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'A non well form...', '/Users/johnpudd...', 34, Array)
#1 /Users/johnpuddephatt/Sites/mimi2/vendor/pbmedia/laravel-ffmpeg/src/Exporters/HLSPlaylistGenerator.php(34): number_format('50/3', 3, '.', '')
#2 /Users/johnpuddephatt/Sites/mimi2/vendor/pbmedia/laravel-ffmpeg/src/Exporters/HLSPlaylistGenerator.php(72): ProtoneMedia\LaravelFFMpeg\Exporters\HLSPlaylistGenerator->getFrameRate(Object(ProtoneMedia\LaravelFFMpeg\MediaOpener))
...
johnpuddephatt commented 3 years ago

Worth mentioning that I'm only seeing this error after upgrading to version 7 – if I remove setAdditionalParameters it processes as expected.

pzanwar03 commented 3 years ago

Yes, @johnpuddephatt is right

johnpuddephatt commented 3 years ago

A workaround seems to be to not set the framerate through additionalParameters but instead to do it with a custom filter, e.g.

$lowBitrateFormat  = (new X264('aac','libx264'))->setKiloBitrate(200);
...
...
...
->addFormat($lowBitrateFormat, function($media){
    $media->addFilter(function ($filters, $in, $out) {
        $filters->custom($in, "fps=20", $out); // $in, $parameters, $out
    });
})

I've manually verified that the outputted video files(s) match the value sat for fps. I can't work out whether there's any substantial difference between setting the framerate with the -r flag vs the fps filter, but having read this post on StackOverflow I can't interpret any difference.

pascalbaljet commented 3 years ago

I just tagged v7.5.8 which should solve this problem.