问题
I am using laravel famework and i am using ffmpeg PHP library. If have not found any good links for video compression using ffmpeg. There are two cases of compression.
1) Video Already exists in folder - this i have done already
2) Video Upload through Form - this i am not able to do :(
Lets i am sharing 1st case code:-
Suppose my video is 13Mb and below code compressed to 4.5Mb (running fine)
$inputVideo = public_path('input/airplane_flight_airport_panorama_1080.mp4');
$outputVideo = public_path('uploads/output.mp4');
exec("ffmpeg -i $inputVideo -b 1000000 $outputVideo"); // this compressing or resize the video
Now second case is uploading using form:-
<form method="post" action="{{url('/api/upload-test-video')}}" enctype="multipart/form-data">
<input name="video" type="file"><br>
<input type="submit" value="Submit">
</form>
Now when i go to function:-
public function uploadTestVideo(Request $request){
echo "<pre>"; print_r($_FILES);
// now in this function i wnat to compress the video
}
Note:- I don't want to upload video in some folder and after that get the video and compress the video. Please help how can i resolve this problem. Thanks in advance :)
回答1:
What do you want to do? Compress the video on the users side? Or whilst uploading? You need the video on the filesystem to "compress" it using ffmpeg. There is no way around that as ffmpeg needs physical access to the videofile on the machine it runs on.
so the best bet would be to upload the video, put it into a temp-folder and compress it. Personally I'd do the ffmpeg step asyncronously as it will take a while but tgat's a different story.
来源:https://stackoverflow.com/questions/49144923/compress-the-video-using-ffmpeg-when-upload-using-php-form