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.63k stars 194 forks source link

Error: undefined method `FFMpeg\Media\Frame::getStreams()` #443

Closed egyjs closed 1 year ago

egyjs commented 1 year ago

https://flareapp.io/share/x5Mo9zMP#F79L39

code

$this->ffmpeg = FFMpeg::fromDisk($this->disk)
            ->open($video);
    public function generateResolutions()
    {
        $format = X264::class;
        $lowBitrate = (new $format)->setKiloBitrate(250);
        $midBitrate = (new $format)->setKiloBitrate(500);
        $highBitrate = (new $format)->setKiloBitrate(1000);
        $superBitrate = (new $format)->setKiloBitrate(1500);

        $this->ffmpeg
            ->exportForHLS()
            ->addFormat($lowBitrate, fn (HLSExporter $media) => $media->resize(640, 480))
            ->addFormat($midBitrate, fn (HLSExporter $media) => $media->resize(960, 720))
            ->addFormat($highBitrate, fn (HLSExporter $media) => $media->resize(1280, 960))
            ->addFormat($superBitrate, fn (HLSExporter $media) => $media->resize(1920, 1440))
//            ->toDisk($this->disk)
            ->dd('adaptive_steve.m3u8');

        return $this;
    }
Jandelson commented 1 year ago

Hi @egyjs I use a trait or can use this code

FFMpeg::fromDisk()->open($video->path)->getAdvancedDriver()->getVideoStream();

follow trait below:

image

egyjs commented 1 year ago

hi @Jandelson, how are you i found the issue recently, and i fix it but i dont know how 😃 , i was creating a Class with this structure:

  1. i create a class property called $ffmpeg
  2. then in the class boot method (like __construct), i assign the value to it: $this->ffmpeg = FFMpeg::fromDisk($video_disk)->open($video)
  3. in other methods I try to use the $this->ffmpeg like this, for example: getThumbnail()

    public function getThumbnail($video = null): string
    {
        if ($video == null) {
            return $this->video_thumbnail;
        }
    
        // laravel-ffmpeg
        $thumbnail = md5($video.uniqid()) . '.jpg';
    
        return $this->ffmpeg->getFrameFromSeconds(round($this->getVideoDuration() / 2))
            ->export()
            ->toDisk($this->final_disk)
            ->withVisibility('public')
            ->save($this->final_path.$thumbnail);;
    }
  4. then the method after that generateResolutions()

    public function generateResolutions()
    {
        $format = X264::class;
        $lowBitrate = (new $format)->setKiloBitrate(250);
        $midBitrate = (new $format)->setKiloBitrate(500);
        $highBitrate = (new $format)->setKiloBitrate(1000);
        $superBitrate = (new $format)->setKiloBitrate(1500);
    
        $this->ffmpeg
            ->exportForHLS()
            ->addFormat($lowBitrate, fn (HLSExporter $media) => $media->resize(640, 480))
            ->addFormat($midBitrate, fn (HLSExporter $media) => $media->resize(960, 720))
            ->addFormat($highBitrate, fn (HLSExporter $media) => $media->resize(1280, 960))
            ->addFormat($superBitrate, fn (HLSExporter $media) => $media->resize(1920, 1440))
    //            ->toDisk($this->disk)
            ->dd('adaptive_steve.m3u8');
    
        return $this;
    }
  5. after a lot of research 😆, i found that I must re-assign the value every time to the property, for example: in getThumbnail():
    - return $this->ffmpeg->getFrameFromSeconds(round($this->getVideoDuration() / 2))
    + $this->ffmpeg = $this->ffmpeg->getFrameFromSeconds(round($this->getVideoDuration() / 2))

    in generateResolutions():

    - $this->ffmpeg
    -           ->exportForHLS()
    -           ->addFormat($lowBitrate, fn (HLSExporte #...
    +  $this->ffmpeg = $this->ffmpeg
    +           ->exportForHLS()
    +           ->addFormat($lowBitrate, fn (HLSExporte #...