compress video file before uploading to server - android

I am trying to upload the video file to server , for small size video like 4 to 5 mb it works fine , but if when i am trying to upload the video more than 15 to 20 mb , it takes too much time for upload , that's why i want to compress the video , is there any library or tool available for compressing video before uploading to server.
thanks.

There are few approaches that you can take to upload larger size video on to the server:
1) You can make use of standard way of recording it across all mobiles which give you standard size:
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setVideoEncodingBitRate(690000 );
2) Make use of ffmpeg or work around with it, it might help to compress video.
https://github.com/halfninja/android-ffmpeg-x264
3) (Recommended) Compressing the video according to me will degrade the quality of video to far worse stage, so what the other work around and best which majorly used is:
Make a Byte array of the video
Make small Chunks of that byte array
Make a Web-service on Server reads this Chunk one by one, send it in queue.
Once received on server make a Video file out of it again.
Runs this Operation in Background async or as service anyways. So it doesnt effect foreground process. Once its done Just Notify!!
Hope this will help

You can try use the FFMpeg library.
It's easy way to compress videos.
Can you check the site https://www.ffmpeg.org/ for more information, or post as comment what are you need to compress.
If you change CRF with the command -crf "15~25". It's a good compress video with good quality.

Related

How to restrict captured video size(20MB to 30MB) in titanium?

I have a requirement that need to take video and upload to server. In server we have upload limit as 20MB to 30MB so my video size should not exceed that limit.
Is that possible to handle video size or video seconds 60 to 120 seconds. It should work in all type of devices like ipad,iPhone6 and iphone6plus same like android higher resolution devices too.
Whats the best approach to handle this requirement.
1) Video size restriction.
2) Video capturing seconds restriction.
3) Video edit cropping video to match the size.
Please suggest me any idea or approach.
There is the videoMaximumDuration property on the CameraOptionsType Object.
Ti.Media.showCamera({
videoMaximumDuration: 20
});
Restricting by the video filesize is not possible when capturing. You would have to set the videoMaximumDuration dynamically according to the capturing device - but thats not accurate.
If you just want to bypass the upload restriction you could chunk the upload of the videofile like so: http://lowb1rd.github.io/002-chunked-uploads-with-titanium.html

Compress video without using ffmpeg in android

I looking for any SDK-LEVEL(without using ffmpeg) approach for compress video programmatically in android.
I can't use ffmpeg cause its size overhead.Is there any lightweight solution for that ?
I want reduce size of video before uploaded to server (i can't modify server upload limit) so if you have any idea other than compressing video please share it.
note : my min-sdk version is 14

Compress video like whatsapp

I'm not an expert in Video Editing but what I want to understand the logic of Whatsapp video processing.
First of all I have noticed that whatever the file is, Whatsapp sets the limit of Uploaded videos to 16MB, after which whatsapp crops the video to not exceed the limit. is this a convention or it's a personal choice ?
Secondly, When a video is recorded using the Camera it's not compressed by default, so whatsapp compresses it using FFMPEG I guess, and it takes no time. (tried for a video of 1min 1920x1080 with 125MB of size, becomes 640x360 with 5MB of size in no time, and the upload starts automatically).. how may they do this ? and why the choice of 640x360, It seems to me very fast for 2 asynchronous tasks : Compression + Upload.
When I run the compression command ffmpeg -y -i in.mp4 -codec:v libx264 -crf 23 -preset medium -codec:a libfdk_aac -vbr 4 -vf scale=-1:640,format=yuv420p out.mp4 it takes approximatively 1 min and the video is being rotated !! :D
Finally, when we download a video from Youtube it's already compressed (I guess) and whatsapp doesn't even try to compress it. So I think that it automatically detects thats the video is compressed. How can we detect this ?
Thank you.
Here are possible answers to your questions:
Quest. 1: Its a personal choice. The whatsapp team is trying to offer the best User Experience (UX) they could to users of their app, that is why they have kept a limit of 16MB for video file. Imagine how long it would take to upload a file of about 125MB. Hence, the app compresses the file for quicker upload and seamless experience.
Quest. 2: I guess you already answered this question yourself - Asynchronous programming. The large video file you feed it, gets encoded into a compressed format according to the algorithm they have written for the app. As Devs., we all know about algorithms and we all know there are things you can do to speed up execution. I guess they implemented their very own algorithm using Asynchronous programming that speeds up the process. The ffmpeg library you mentioned i guess was coded in C which i think doesn't support async call (not so sure though). After this, upload takes over.
Quest. 3&Finally: Codecs are standards. If you encode a video file to MPEG4, then try to re-encode it again to MPEG4 even using another program, you will get the same result as far as both programs are using same encoding standards, i.e. they didn't implement a specific algorithm for their programs(this takes years of work). So, when your Whatsapp tries to encode the file, it gives the same result.
Hope I have been able to answer your questions.
MichVeline
Use media codec instead of ffmpeg for better performance. If your use case is only to compress the video, MediaCodec would be best option for android. It helps you to write the code asynchronously and also gives you lots of freedom to optimize you algorithm.

encoding images to video with ffpmeg

We are working on Android 3D Animation App.
We need to identify images, then save and encode the same to video using FFmpeg (Since Android API is not supporting). Once the video is generated, then audio is appended to the same.
We are facing 2 problems on this.
First is the memory leakage issue at the time of saving identified images for encoding. CPU of emulator is getting overloaded. Whether FFpmeg is called every time when an image is selected? How to resolve this issue?
Second (in case if we get through the first one) we are not able to encode the selected images, since this is generating green color video. What could be reason for this?
Whether is there any tool other than FFmpeg for video encoding from images to H264?
Whether images version (Rastar or Vector) will impact this video encoding?
Whether Android OS version is considered?
Any valuable inputs on this will be greatly appreciated.
Thanks
I played also with that idea using ffmpeg on an android phone, but I would suggest to do that on a server which has much more power. On a server you don't need to think about the cpu load of a smartphone.
In general for improving your ffmpeg run you need to publish the ffmpeg calls. ffmpeg is quiet complex where the order of the parameters directly correlates with the efficience.
I don't know which container format you preferer but maybe a simple mjpeg codec could work for you. AFIK there a just the jpeg frames connected to each other which should be much simple then encoding a video to h264/x264 (ffmpeg uses the last one).
A combination of both may be to generate a mjpeg stream which will be converted on the server side to a h264 video which may be downloaded to the client. but that really depends on the length of the video if you don't want to waste the traffic of your customers.

Is there possibility to compress audio and video file in android programmatically?

As I record the video file for 1min it take 3mb of size as i want to post this file to server it is taking more time.So I need to decrease the time by compassing the recorded video file and send it to server.Is there possibility to compress the video file programmatically.
Thanks in advance.
Teja.
Note that simply compressing it with some zip-algorithm (relatively easy to do in Java) wouldn't help you much. Try compressing the file yourself. (If it did make the file smaller, it would most likely already be a part of the video-file format, wouldn't it :-)
If you want to compress the video, you have to re-encode it with a lower bit-rate / lower resolution or something similar.

Categories

Resources