quasarstream / PHP-FFmpeg-video-streaming

📼 Package media content for online streaming(DASH and HLS) using FFmpeg

Home Page:https://www.quasarstream.com/op/php/ffmpeg-streaming?u=php-ff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Call to a member function getHeight()

shankar-bavan opened this issue · comments

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

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);