1

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

kunal
  • 4,122
  • 12
  • 40
  • 75

1 Answers1

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.

heiglandreas
  • 3,803
  • 1
  • 17
  • 23
  • You mean firstly i will upload video in some temp folder and after that i will compress and after compression i will delete the file from temp folder? – kunal Mar 07 '18 at 06:55
  • That was the general idea. – heiglandreas Mar 07 '18 at 06:58
  • what about the time ... it will take more time to implement this process :( – kunal Mar 07 '18 at 06:58
  • Re-encoding videos takes time. There is no shortcut to that. And as it might take a long time I suggested doing it asynchronously. The user uploads the video and then gets anconfirmation "Thanks we got the video! We are preparing it now. Please check back..." And when the encoding is finished the user gets a message "We're done. Here's the result. " – heiglandreas Mar 07 '18 at 07:01