Compress the video using ffmpeg when upload using php form?

时间秒杀一切 提交于 2019-12-11 23:17:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!