Video chunks merging issues in laravel 5.8

23 Views Asked by At

I'm trying to merge video chunks but getting the first chunk of data in the final video and other chunks of data not exist in the final video. I'm merging chunks using Laravel 5.8. The controller logic is as below.

$candidateDirectory = $request->userDirectory;
        $chunks_directory = public_path('chunks/'.$candidateDirectory);
        $recordingDirectory = public_path('recordings/'.$candidateDirectory);

        if (!file_exists($recordingDirectory)) {
            mkdir($recordingDirectory, 0755, true);
        }

        

        $targetFile = $recordingDirectory.'/'.date('d-M-Y').'_video.webm';
        $directoryContents = File::allFiles($chunks_directory);

 $chunks = array_diff($directoryContents, array('.', '..'));
        $combinedData = [];
        
        foreach ($chunks as $chunk) 
        {
            $chunkData = file_get_contents($chunk);
            $combinedData[] = $chunkData;
        }

        $file_merge = file_put_contents($targetFile, $combinedData);
if($file_merge)
        {
        dd('file merged');
    }else{
    dd('file not merged');
}

I want to merge all chunks and get complete data of all chunks in the final video.

0

There are 0 best solutions below