I installed FFmpeg, php-ffmpeg, laravel-ffmpeg. Then I tried to convert Video and Audio files to mp3 on laravel.
Then it worked properly on Windows10 XAMPP. However, when I installed the same on my linux shared server,
get error: Class 'FFMpeg\Format\Audio\mp3' not found
and
A composer dependency is missing You might be missing a composer dependency. A possible package that was found is php-ffmpeg/extras.
So, I did composer require php-ffmpeg/extras
and installed, however, still it produces same error.
So What would it be problem?
VoiceRecController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use App\User;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
use Illuminate\support\Facades\DB;
use FFMpeg;
class VoiceRecController extends Controller
{
public function update(Request $request, $id)
{
$form = Post::findOrFail($id);
if($request->capture->extension() == 'mp4'){
$request->capture->storeAs('public/voice/', $form->id .'.mp4');
// Open your video file
$video =FFMpeg::fromDisk('public')->open('/voice/'. $form->id .'.mp4');
// Set an audio format
$audio_format = new FFMpeg\Format\Audio\mp3();
// Extract the audio into a new file as mp3
$video->save($audio_format, public_path().'/storage/voice/'. $form->id .'.mp3');
if (file_exists(public_path().'/storage/voice/'. $form->id .'.mp3')){
\File::delete(public_path().'/storage/voice/'. $form->id .'.mp4');
}
}elseif($request->capture->extension() == 'mp3' || $request->capture->extension() == 'mpga'){
$request->capture->storeAs('public/voice/', $form->id .'.mp3');
}elseif($request->capture->extension() == 'wav'){
$request->capture->storeAs('public/voice/', $form->id .'.wav');
// Open your video file
$video =FFMpeg::fromDisk('public')->open('/voice/'. $form->id .'.wav');
// Set an audio format
$audio_format = new FFMpeg\Format\Audio\mp3();
// Extract the audio into a new file as mp3
$video->save($audio_format, public_path().'/storage/voice/'. $form->id .'.mp3');
if (file_exists(public_path().'/storage/voice/'. $form->id .'.mp3')){
\File::delete(public_path().'/storage/voice/'. $form->id .'.wav');
}
}else{
$request->capture->store('public/voice/');
}
return redirect('/home/mypage');
}
}
Thank you.