如何在Android中以编程方式上传到服务器之前减小视频大小
我想将视频上传到服务器,当我从图库中捕获视频或从摄像机录制时,服务器响应我该错误,但是当我上传2 MB大小的视频时,它已成功上传.如何压缩视频以减小尺寸?我从脸书上传了视频,手机上的视频大小为140 MB,但是脸书对视频进行了处理,并将其大小减小到1.35 MB
I want to upload video to server, when I catch video from gallery or record from camera , the server response to me that error but when I upload video with size 2 MB , it is uploading successfully. How can I compress the video to reduce the size? I uploaded the video from face book , the size of video on my mobile is 140 MB , but face book make a process on the video and reduce it's size to 1.35 MB
您有两种方法可以做到这一点:
You have two way to do that:
-
将其编码为较低的比特率和/或较低的分辨率.在这里看看:是否可以在Android上压缩视频?.
尝试压缩/压缩它.在这里看看: http://www.jondev.net/articles/Zipping_Files_with_Android_%28Programmatically %29
Try to zip/compress it. Have a look here: http://www.jondev.net/articles/Zipping_Files_with_Android_%28Programmatically%29
不幸的是,我从未尝试使用140MB的视频来做到这一点.这就是为什么我向您建议第一个库(FFmpeg 4 Android)的原因.
Unfortunately I never tried to do that with a 140MB video. This is why I suggested to you the first library (FFmpeg 4 Android).
顺便尝试增加服务器上的UPLOAD_LIMIT.但这不是问题,即使将其增加到10MB,也仍然必须对其进行压缩.不要尝试将UPLOAD_LIMIT增加到140MB,这肯定会导致HTTP超时.
By the way, try to increase also your UPLOAD_LIMIT on your server. But this is not the problem, even if you increase it to 10MB you still have to compress it. Do not try to increase the UPLOAD_LIMIT to 140MB, it will cause for sure an HTTP timeout.
否则,您需要启用分块上传.
Otherwise you need to enable a chunked upload.
看看这个讨论: