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

Converting large mp4 to hls fails on centos #467

Open mustafa-940 opened 1 year ago

mustafa-940 commented 1 year ago

I'm trying to convert a large mp4 files ( + 1GB ), when converting them locally on windows 10 the package works perfectly, when trying to convert large files on centos 7 OS the conversion fails. does anybody have an idea where the problem could be?

The following is the code I use for conversion.

` $lowBitrate = (new X264('aac', 'libx264'))->setKiloBitrate(500); $midBitrate = (new X264('aac', 'libx264'))->setKiloBitrate(750); $highBitrate = (new X264('aac', 'libx264'))->setKiloBitrate(1250); $veryHighBitrate = (new X264('aac', 'libx264'))->setKiloBitrate(3000); $ultraHighBitrate = (new X264('aac', 'libx264'))->setKiloBitrate(10000);

    try {
         // open the uploaded video from the right disk...
        //  $file_name = explode('/',$this->file->path);
        //  $file_name = explode('.',$file_name[array_key_last($file_name)]);

        FFMpeg::fromDisk($this->file->disk)
                ->open($this->file->path)
                ->exportForHLS()
                ->withRotatingEncryptionKey(function ($filename,$content)
                {
                    Storage::disk('secrets')->put($filename,$content);
                })
                ->toDisk(config('filesystems.default'))
                ->addFormat($lowBitrate)
                ->addFormat($midBitrate)
                ->addFormat($highBitrate)
                ->save($this->folder.'/'.pathinfo($this->file->path)['filename'] . '.m3u8');
    } catch (EncodingException $exception) {
        $command = $exception->getCommand();
        $errorLog = $exception->getErrorOutput();
        Log::alert($command);
        Log::alert("FFMPEG ERROR : ".$errorLog);
        if(Storage::exists($this->folder))
        {
            Storage::delete($this->folder);
        }

    }`

    Sample of the error
    `[crypto @ 0x6242ac0] encryption IV not set

[hls @ 0x4d15580] Failed to open file '/home/edujoacademy/public_html/code_pro_file_uploader/storage/app/Files/main/malek-sadaqaa/seventh-grade/second_semster/مالك-صدقة-العلاقات-التناسبية/7WgReSywLCDxLaIMhFfWM2Gza0WlB1sa9Baugjmp_1_750_00242.ts' [hls @ 0x4d15580] Opening '/home/edujoacademy/public_html/code_pro_file_uploader/storage/app/Files/main/malek-sadaqaa/seventh-grade/second_semster/مالك-صدقة-العلاقات-التناسبية/temporary_segment_playlist_1.m3u8' for writing frame=64894 fps=279 q=-1.0 Lq=-1.0 size=N/A time=00:43:15.75 bitrate=N/A speed=11.2x
video:385867kB audio:1870kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown [libx264 @ 0x4e01640] frame I:1352 Avg QP:10.53 size:109433 [libx264 @ 0x4e01640] frame P:16323 Avg QP:13.32 size: 368 [libx264 @ 0x4e01640] frame B:47219 Avg QP:11.60 size: 244 [libx264 @ 0x4e01640] consecutive B-frames: 2.2% 0.1% 6.3% 91.3% [libx264 @ 0x4e01640] mb I I16..4: 64.1% 14.4% 21.5% [libx264 @ 0x4e01640] mb P I16..4: 0.3% 0.2% 0.0% P16..4: 1.5% 0.1% 0.0% 0.0% 0.0% skip:97.9% [libx264 @ 0x4e01640] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 3.3% 0.0% 0.0% direct: 0.0% skip:96.6% L0:23.7% L1:76.3% BI: 0.0% [libx264 @ 0x4e01640] final ratefactor: 19.26 [libx264 @ 0x4e01640] 8x8 transform intra:16.2% inter:89.1% [libx264 @ 0x4e01640] coded y,uvDC,uvAC intra: 23.7% 48.4% 44.3% inter: 0.0% 0.2% 0.0% [libx264 @ 0x4e01640] i16 v,h,dc,p: 32% 65% 3% 1% [libx264 @ 0x4e01640] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 48% 21% 2% 1% 1% 1% 3% 2% [libx264 @ 0x4e01640] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 37% 32% 8% 3% 4% 4% 5% 3% 4% [libx264 @ 0x4e01640] i8c dc,h,v,p: 37% 52% 9% 3% [libx264 @ 0x4e01640] Weighted P-Frames: Y:0.2% UV:0.2% [libx264 @ 0x4e01640] ref P L0: 88.5% 0.7% 8.9% 1.9% 0.0% [libx264 @ 0x4e01640] ref B L0: 28.3% 71.5% 0.2% [libx264 @ 0x4e01640] ref B L1: 99.8% 0.2% [libx264 @ 0x4e01640] kb/s:510.07 [aac @ 0x4d2af80] Qavg: 64851.926 [libx264 @ 0x4e04180] frame I:1263 Avg QP: 3.59 size:173661 [libx264 @ 0x4e04180] frame P:15218 Avg QP:10.25 size: 294 [libx264 @ 0x4e04180] frame B:44129 Avg QP: 4.12 size: 136 [libx264 @ 0x4e04180] consecutive B-frames: 2.2% 0.1% 6.3% 91.5% [libx264 @ 0x4e04180] mb I I16..4: 70.2% 6.1% 23.7% [libx264 @ 0x4e04180] mb P I16..4: 0.3% 0.2% 0.0% P16..4: 1.0% 0.0% 0.0% 0.0% 0.0% skip:98.4% [libx264 @ 0x4e04180] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 1.0% 0.0% 0.0% direct: 0.0% skip:99.0% L0:48.2% L1:51.8% BI: 0.0% [libx264 @ 0x4e04180] final ratefactor: 11.66 [libx264 @ 0x4e04180] 8x8 transform intra:7.6% inter:49.2% [libx264 @ 0x4e04180] coded y,uvDC,uvAC intra: 26.4% 49.4% 46.5% inter: 0.0% 0.1% 0.0% [libx264 @ 0x4e04180] i16 v,h,dc,p: 36% 61% 2% 1% [libx264 @ 0x4e04180] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 50% 33% 1% 0% 0% 0% 1% 1% [libx264 @ 0x4e04180] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 31% 8% 4% 4% 4% 5% 4% 5% [libx264 @ 0x4e04180] i8c dc,h,v,p: 35% 55% 8% 3% [libx264 @ 0x4e04180] Weighted P-Frames: Y:0.1% UV:0.1% [libx264 @ 0x4e04180] ref P L0: 60.7% 0.5% 32.3% 6.5% 0.0% [libx264 @ 0x4e04180] ref B L0: 66.1% 33.6% 0.2% [libx264 @ 0x4e04180] ref B L1: 99.5% 0.5% [libx264 @ 0x4e04180] kb/s:758.31 [aac @ 0x4e33700] Qavg: 65276.035 Conversion failed!`