使用php表单上传时,使用ffmpeg压缩视频吗? [英] Compress the video using ffmpeg when upload using php form?

查看:1063
本文介绍了使用php表单上传时,使用ffmpeg压缩视频吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel famework,并且正在使用ffmpeg PHP库.如果尚未找到任何使用ffmpeg进行视频压缩的良好链接.压缩有两种情况.

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 :)

推荐答案

您想做什么 ?在用户端压缩视频?还是在上传时?您需要文件系统上的视频以使用ffmpeg压缩"它.由于ffmpeg需要对运行它的计算机上的视频文件进行物理访问,因此无法解决.

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.

所以最好的选择是上传视频,将其放入临时文件夹并进行压缩.就个人而言,我将异步执行ffmpeg步骤,因为这可能需要一段时间,但tgat的情况与此不同.

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.

这篇关于使用php表单上传时,使用ffmpeg压缩视频吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆