PHP-FFmpeg-video-streaming icon indicating copy to clipboard operation
PHP-FFmpeg-video-streaming copied to clipboard

How do i stop streaming after i finished capturing my video

Open Tsolmonx opened this issue 2 years ago • 0 comments

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 ?

Tsolmonx avatar Nov 21 '23 14:11 Tsolmonx