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

How do i stop streaming after i finished capturing my video #139

Open Tsolmonx opened 10 months ago

Tsolmonx commented 10 months ago

Hi im pretty new to this and might be doing it wrong and help will be useful.

    public function __invoke(Stream $message)
    {
        $projectDir = $this->parameterBag->get('kernel.project_dir');
        $config = [
            'ffmpeg.binaries'  => '/opt/homebrew/bin/ffmpeg',
            'ffprobe.binaries' => '/opt/homebrew/bin/ffprobe',
            'timeout'          => 3600, // The timeout for the underlying process
            'ffmpeg.threads'   => 12,   // The number of threads that FFmpeg should use
        ];

        $log = new Logger('FFmpeg_Streaming');

        $log->pushHandler(new StreamHandler($projectDir . '/var/log/ffmpeg-streaming.log')); // path to log file

        $r_480p  = (new Representation)->setKiloBitrate(750)->setResize(720, 360);

        $ffmpeg = FFMpeg::create($config, $log);

        $capture = $ffmpeg->capture('FaceTime HD Camera', '0', ['framerate'=> 30,]);
        $capture->hls()
                ->x264()
                ->addRepresentation($r_480p)
                ->save('public/stream/hls-stream.mpd');

    }

I needed to make some live streaming service on my symfony backend and I wrote above code reading the docs and from and api call i start capturing video and saving hls file to public dir and client can see the video that im streaming http://localhost:8000/stream/hls-stream_360p.m3u8 and it works fine. Problem is how do i finish my recording. i had to shut down the server to stop the recording. any help ?