Video file transfer from Android phone to server

做~自己de王妃 提交于 2019-12-25 05:32:21

问题


I'm writing a video processing Android application. The user of the application would take a video, and the application would send the video to the server for some frame by frame processing. The server would then send back a result to the application.

What are the pros and cons of braking up the video into frames on the Android device before sending it to the server vs sending the video and then braking it up? What would be faster?

If I brake it up into frames on the Android phone, should I send bitmaps or should I send compressed images and then decompress on the server? What would be the cost and the gain of compression vs sending a Bitmap? I know the compression ratio can vary based on the image but I'm just asking for pros and cons.


回答1:


Sending video to server from byte[] may cause outOfMemoryError so its better to post video from MultiPart. You can download jar file from this link. http://hc.apache.org/downloads.cgi . Download and add httpmime-4.2.jar to your project.

public void uploadVideo(Context context, String videoPath) {
        try {
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost postRequest = new HttpPost(context.getString(R.string.url_service_fbpost));
            MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
            if(!videoPath.isEmpty()){

                FileBody filebodyVideo = new FileBody(new File(videoPath));
                reqEntity.addPart("uploaded", filebodyVideo);
            }
            postRequest.setEntity(reqEntity);
            HttpResponse response = httpClient.execute(postRequest);

            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    response.getEntity().getContent(), "UTF-8"));
            String sResponse;
            StringBuilder s = new StringBuilder();

            while ((sResponse = reader.readLine()) != null) {
                s = s.append(sResponse);
            }

            Log.e("Response: ", s.toString());
            return true;

        } catch (Exception e) {
            Log.e(e.getClass().getName(), e.getMessage());
            return false;
        }
}



回答2:


I found that the compression ratio could be about 16:1. Enough for me to choose to compress it in this situation. The above ratio is if I compressed it to a JPEG.



来源:https://stackoverflow.com/questions/17672952/video-file-transfer-from-android-phone-to-server

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