quasarstream / PHP-FFmpeg-video-streaming

📼 Package media content for online streaming(DASH and HLS) using FFmpeg
https://www.quasarstream.com/op/php/ffmpeg-streaming?u=php-ff
MIT License
514 stars 117 forks source link

Call to a member function getHeight() #82

Closed shankar-bavan closed 3 years ago

shankar-bavan commented 3 years ago

I getting following error when I convert 240p videos.

ERROR: Call to a member function getHeight() on null {"exception":"[object] (Error(code: 0): Call to a member function getHeight() on null at vendor/aminyazdanpanah/php-ffmpeg-video-streaming/src/HLS.php:305

 $reps = new AutoReps($video, $format, [360, 480, 720, 1080]);
        $video->hls()
            ->encryption($save_to, $url, 1)
            ->setFormat($format)
            ->setHlsTime(5) // Set Hls Time. Default value is 10
            ->setHlsAllowCache(false)
            ->addRepresentations($reps->getCalculatedReps())
            ->save($save_path);

aminyazdanpanah/php-ffmpeg-video-streaming: "^1.2", (1.2.12) ffmpeg version 4.2.4-1ubuntu0.1

aminyazdanpanah commented 3 years ago

Maybe the $reps->getCalculatedReps() is an empty array and then the getHeight() does not exist.

You should debug your code to find out the error!

You can also write an 'if condition' to avoid this error:

$reps = new AutoReps($video, $format, [360, 480, 720, 1080]);

$representations = (count($reps->getCalculatedReps() > 0) ? $reps->getCalculatedReps() : $reps->getOriginalRep();

$video->hls()
      ->encryption($save_to, $url, 1)
      ->setFormat($format)
       ->setHlsTime(5) // Set Hls Time. Default value is 10
       ->setHlsAllowCache(false)
       ->addRepresentations($representations )
       ->save($save_path);