我安装了FFmpeg,php-ffmpeg,laravel-ffmpeg。然后,我尝试将视频和音频文件转换为mp3的laravel。
然后它在Windows10 XAMPP上正常工作。但是,当我在我的linux共享服务器上安装它时,
获取错误:Class 'FFMpeg\Format\Audio\mp3' not found和
A composer dependency is missing You might be missing a composer dependency. A possible package that was found is php-ffmpeg/extras.所以,我做了composer require php-ffmpeg/extras并安装了,但是,它仍然产生同样的错误。那么这会是什么问题呢?
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');
}
}谢谢。
发布于 2020-12-29 08:48:58
您得到的错误是因为Class被称为\FFMpeg\Format\Audio\Mp3;,带有一个大写的M。
按照示例代码正确使用它:
FFMpeg::fromDisk('public')
->open('song.3gp')
->export()
->toDisk('public')
->inFormat(new \FFMpeg\Format\Audio\Mp3)
->save('song_converted.mp3');https://stackoverflow.com/questions/61949633
复制相似问题