I'm using RecordRTC to record a video in 1000ms chunks, which are sent as blobs via AJAX to my server. The server saves these files, and at the end of the recording I need to rebuild them all into a single .webm
.
I thought this would be as simple as concatenating the files and giving it the correct extension. Unfortunately not.
Below is my code for building the final file. It's in Laravel, but it's pretty self-explanatory:
public function buildBlob(Request $request)
{
$files = Storage::disk('local')->files('blobs');
$contents = '';
foreach($files as $file) {
$contents.= file_get_contents(storage_path('app/'. $file));
}
Storage::put('video.webm', $contents);
return ['success' => true];
}
VLC will not play this file. Firefox complains it's an unknown filetype. Chrome just doesn't play it at all.
I guess my question is: how do I compile a new blob in PHP with the correct mimetype? In JavaScript I can do:
let blob = new File(this.blobs, 'video.webm', {
type: 'video/webm'
});
So I suppose I need an equivalent.