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

Take more time to convert to HLS #63

Closed shanka12 closed 4 years ago

shanka12 commented 4 years ago

Thank you for the Great library :) This is not a Bug.

I tried to convert 389.4 MB, 30 Minutes mp4 file to hls on production server. It is take more than 1 hour to convert.

Is that issue with server or code? I use 4vCPU, 16GB RAM Cloud server. Is there any recommended specification for the server?

$config = [
            'timeout' => 0,
        ];
        $log = new Logger('FFmpeg_Streaming');
        $log->pushHandler(new StreamHandler('/logs/ffmpeg-streaming.log'));
        $format = new \Streaming\Format\X264();
        $format->on('progress', function ($video, $format, $percentage){
            echo sprintf("\rTranscoding...(%s%%) [%s%s]", $percentage, str_repeat('#', $percentage), str_repeat('-', (100 -     $percentage)));
        });

        $ffmpeg = FFMpeg::create($config, $log);
        $path = 'path/video.mp4';
        $save_path =  'path/'.$video_id.'.m3u8';

        $video = $ffmpeg->open($path);

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

        $video->hls()
            ->setFormat($format)
            ->setHlsTime(5) 
            ->setHlsAllowCache(false)
            ->addRepresentations($reps->getCalculatedReps())
            ->save($save_path);
aumkarthakur commented 4 years ago

Are 4CPU dedicated or shared. That makes a huge difference.

aumkarthakur commented 4 years ago

ffmpeg actually requires lot of CPU power. I use Digitalocean dedicated CPU-Optimized droplet ($80/mo) and it takes me 30min to convert 2gb video to different hls representations using this library.

shanka12 commented 4 years ago

Are 4CPU dedicated or shared. That makes a huge difference.

Dedicated CPU on cloud server.

shanka12 commented 4 years ago

ffmpeg actually requires lot of CPU power. I use Digitalocean dedicated CPU-Optimized droplet ($80/mo) and it takes me 30min to convert 2gb video to different hls representations using this library.

Thank you @aumkarthakur . Do you think, Dedicated server will solve this issue? (AMD EPYC 7502P 32 Core, 128GB RAM (https://www.hetzner.com/dedicated-rootserver/ax161)

one more question if you don't mind. How many videos we can convert at the same time with AMD 32-Core dedicated server?

aminyazdanpanah commented 4 years ago

The code is ok. Besides FFmpeg takes the time to package your media. The time of the packaging process depends on you how much you want to spend money and what is your priority.

As @aumkarthakur mentioned, FFmpeg uses a lot of CPU resources, and of course how much your CPU is fast, the packaging process will be faster.