I am trying to record the video and upload into the aws s3 server. Vuejs as front end and php Laravel as backend, I was not using any conversion before saving it to s3. Due to this if any recording recorded from android cannot be played in apple device due to some codecs.. To over come this, I am using ffmpeg to encode in X264() format to make it play in apple and android device regardless on which device the recording is done.
1 min video taking 6-7 minutes using ffmpeg. I thought may be aws s3 taking time to save, i commented "saving to s3 bucket code" still very slow to save temp public folder in php.
please check the code if i am missing anything to make conversion quick. if any solution update answer with reference link or code snippet with reference to my code below.
public function video_upload(Request $request)
{
// Response Declaration
$response=array();
$response_code = 200;
$response['status'] = false;
$response['data'] = [];
// Validation
// TODO: Specify mimes:mp4,webm,ogg etc
$validator = Validator::make(
$request->all(), [
'file' => 'required'
]
);
if ($validator->fails()) {
$response['data']['validator'] = $validator->errors();
return response()->json($response);
}
try{
$file = $request->file('file');
//convert
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open($file);
$format = new X264();
//end convert
$file_name = str_replace (' ', '-', Hash::make(time()));
$file_name = preg_replace('/[^A-Za-z0-9\-]/', '',$file_name).'.mp4';
$video->save($format, $file_name);
$file_folder = 'uploads/video/';
// Store the file to S3
// $store = Storage::disk('s3')->put($file_folder.$file_name, file_get_contents($file));
$store = Storage::disk('s3')->put($file_folder.$file_name, file_get_contents($file_name));
if($store){
// Replace old file if exist
//delete the file from public folder
$file = public_path($file_name);
if (file_exists($file)) {
unlink($file);
}
if(isset($request->old_file)){
if(Storage::disk('s3')->exists($file_folder.basename($request->old_file))) {
Storage::disk('s3')->delete($file_folder.basename($request->old_file));
}
}
}
$response['status'] = true;
$response['data']= '/s3/'.$file_folder. $file_name;
}catch (\Exception $e) {
$response['data']['message']=$e->getMessage()."line".$e->getLine();
$response_code = 400;
}
return response()->json($response, $response_code);
}
Its blocking point for me. I cannot let user to wait 5-6 mins to upload 1 min video.