Android Compress Video before Upload to Server

与世无争的帅哥 提交于 2020-01-01 03:18:12

问题


How can I compress a video file in Android before uploading to a remote server? I'm not looking to zip up the file, because I don't think that will help much. I want to compress the video and re-encode it with a lower bit-rate or resolution. The idea is to get a standard 360х480, 30 FPS video file from every device. This way I can avoid users with better cameras being forced to upload huge video files.

I know iOS makes it fairly simple to force video file resolutions. 10 second video recorded on iPhone 4:

  • high (1280х720) = ~14MB = ~11Mbit/s
  • 640 (640х480) = ~4MB = ~3.2Mbit/s
  • medium (360х480) = ~1MB = ~820Kbit/s
  • low (144х192) = ~208KB = ~170Kbit/s

Is there any easy way to do this in Android? Do I need to find some external library that will let me re-encode the video file, then save it to the SD card (or overwrite the old video file), then upload that file? Mainly looking for general direction here and not code to copy and paste, although anything is helpful.


回答1:


I got a similar problem. Where I had to upload video in server having size within 5.4mb. But due to different camera resolutions of different phones, there was a problem. These are the solutions which I have opted

mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setVideoEncodingBitRate(690000 );

Hope these will help you




回答2:


We decided to save this functionality for another iteration of the project. We opted to warn the users of the large data payload (especially if they are not on Wi-Fi). I'm confident this can be done, and the link provided by tabbykitten is the best related SO post I've found on this topic to this date.




回答3:


From Android 18 onwards you have direct android API to do Video Encoding but if you are targeting Less than API level 18 it not straight forward

the below link does the encoding https://github.com/google/grafika/blob/master/src/com/android/grafika/VideoEncoderCore.java




回答4:


One of the app that I worked on earlier has this requirement of sending the video file after compressing it. Here are the steps I followed which worked:

  1. Compress the file using a Silicompressor library in android. Run the compression task on a background thread.

  2. The output file format will have the mime type "video/raw". You can check that in logcat. So, you need to add this mime type in your server so that the compressed file format is uploaded successfully.

  3. After this is done, trying sending the compressed file and it should work.

Make sure the mime type of the file you are uploading to server is accepted by the server.



来源:https://stackoverflow.com/questions/11314375/android-compress-video-before-upload-to-server

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