我可以通过 cmd 运行此代码。我的问题是如何在本地和实时服务器上运行这个命令到我的 laravel 项目?
ffmpeg -i input1.webm -i input2.webm output.mp3
提前致谢。
我可以通过 cmd 运行此代码。我的问题是如何在本地和实时服务器上运行这个命令到我的 laravel 项目?
ffmpeg -i input1.webm -i input2.webm output.mp3
提前致谢。
公共函数存储(请求 $request){
$rules = [
'title' => 'required',
'description' => 'required',
'meta_title' => 'required',
'category_id' => 'required',
'video_file' => 'required',
'tags' => 'required',
];
$messages = [
'category_id.required' => 'Category field required.',
'tags.required' => 'Tag field required',
];
$validator = Validator::make($request->all(),$rules, $messages);
$validator->sometimes('file', 'nullable|mimes:csv,xlsx|max:1024000', function ($request) {
$messages = ['file.mimes'=>'file type must be csv or xlsx.'];
return ($request->category_id == 2 || $request->category_id == 4);
});
$validator->sometimes('file', 'nullable|mimes:pdf|max:1024000', function ($request) {
$messages = ['file.mimes'=>'file type must be pdf.'];
return ($request->category_id == 1);
});
if($validator->fails()) {
return response()->json(['error'=>$validator->errors(),'status'=>false]);
}else {
DB::beginTransaction();
try {
$formData = new Video();
$formData->title = $request->title;
$formData->user_id = Auth::id();
$formData->description = $request->description;
$formData->upload_date = Carbon::now();
//$formData->meta_title = implode(",",$request->meta_title);
$formData->meta_description =isset($formData->meta_description)?implode(",", $request->meta_description):'';
//$formData->tags = implode(",",$request->tags);
$formData->category_id = $request->category_id[0];
if($request->hasFile('image_file')) {
$uploadedFile = $request->file('image_file');
$filename = time().$uploadedFile->getClientOriginalName();
$imagePath = Storage::disk('public')->putFileAs(
'images',
$uploadedFile,
$filename
);
$formData->image_file = $imagePath;
}
if($request->hasFile('video_file')) {
$uploadedFile = $request->file('video_file');
$filename = trim(time().$uploadedFile->getClientOriginalName());
$removeSpaceFromFile = preg_replace('/[^A-Za-z0-9\-]/', '', $filename);
$filePath = Storage::disk('public')->putFileAs(
'videos',
$uploadedFile,
$removeSpaceFromFile
);
$formData->video_file = $filePath;
$video_id = DB::getPdo()->lastInsertId();
$filefullPath = asset('storage').'/'.$filePath;
$getOutputFilePath = Mp3AndTumbnails::where('id',1)->first();
$outputMp3File = $getOutputFilePath->mp3_output_path;
$outputImageFile = $getOutputFilePath->thumbnails_path;
// $mp3Filename = $video_id.'.mp3';
// $imageFileName = $video_id;
$mp3Filename = preg_replace('/[^A-Za-z0-9\-]/', '_',$request->title).'.mp3';
$imageFileName = preg_replace('/[^A-Za-z0-9\-]/', '_',$request->title);
$output = shell_exec('ffmpeg -i '. $filefullPath.' -vn -ar 44100 -ac 2 -ab 192 -f mp3 '. $outputMp3File.'/'.$mp3Filename);
$imageOutput = shell_exec('ffmpeg -i '.$filefullPath.' -ss 00:00:10 -vframes 1 -s 370x220 '.$outputImageFile.'/'.$imageFileName.'.jpg -hide_banner');
$formData->mp3_file = $mp3Filename;
$formData->image_file = 'images/'.$imageFileName.'.jpg';
$dur = shell_exec("ffmpeg -i ".$filefullPath." 2>&1");
preg_match("/Duration: (.{2}):(.{2}):(.{2})/", $dur, $duration);
if(isset($duration[1])) {
$hours = $duration[1];
$minutes = $duration[2];
$seconds = $duration[3];
$video_length = $hours.':'.$minutes.':'.$seconds;
$formData->video_length = $video_length;
}
}
if($request->hasFile('file')) {
$lyricsFile = $request->file('file');
$categoryInfo = Category::where('id',$request->category_id[0])->first();
$filename = time().$lyricsFile->getClientOriginalName();
$lyricsFile->move(public_path("download".'/'.$categoryInfo->name), $filename);
$path = $filename;
$formData->lyrics_file = $path;
}
$formData->save();
foreach ($request->category_id as $key => $value) {
$category = new VideoCategoryUpload();
$category->video_id = $formData->id;
$category->category_id = $value;
$category->save();
}
$updateEncodeVideoId = Video::where('id',$formData->id)
->update(['base64_encode_video_id'=>base64_encode($formData->id)]);
foreach ($request->tags as $key => $value) {
$tagData = new TagModel();
$tagData->user_id = Auth::id();
$tagData->video_id = $formData->id;
$tagData->name = $value;
$tagData->slug_name = $value;
$tagData->save();
}
foreach ($request->meta_title as $key => $value) {
$metaTitleData = new MetaTitleModel();
$metaTitleData->user_id = Auth::id();
$metaTitleData->video_id = $formData->id;
$metaTitleData->title_name = $value;
$metaTitleData->title_slug_name = $value;
$metaTitleData->save();
}
DB::commit();
return response()->json(['status'=>true,'msg'=>'File uploaded successfully !!.']);
}catch(\Exception $e) {
DB::rollback();
return response()->json(['status'=>'exception','msg'=>'Something Went Wrong !!.']);
}
}
}