AbedElazizShe / LightCompressor

A powerful and easy-to-use video compression library for android uses MediaCodec API.
Apache License 2.0
518 stars 117 forks source link

Compression time is taking too much #57

Closed arindamhit closed 3 years ago

arindamhit commented 3 years ago

If I am capturing a video using mobile camera for 1 minute, the video size is coming around 150 MB. If I am compressing it with Medium quality, the compression time is coming around 1 min 30 secs. Compressed video size is around 30 MB. I am happy with the size but the compression time is too high. I am using OnePlus 3T and Android version is Android 9. SDK version I am using is 21. I am adding the code here:

 runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            VideoCompressor.start(currentVideoPath, destVideoPath, new CompressionListener() {
                                @Override
                                public void onStart() {
                                    // Compression start,
                                    Log.d("Testing", "compressed onStart  ");
                                }

                                @Override
                                public void onSuccess() {
                                    // On Compression success
                                    Log.d("Testing", "compressed file size ");

                                }

                                @Override
                                public void onFailure(String failureMessage) {
                                    // On Failure
                                    Log.d("Testing", "compressed onFailure  ");
                                }

                                @Override
                                public void onProgress(float v) {
                                    Log.d("Testing", "Progress::  ");
                                    // Update UI with progress value
                                }

                                @Override
                                public void onCancelled() {
                                    // On Cancelled
                                    Log.d("Testing", "compressed onCancelled  ");
                                }
                            }, VideoQuality.MEDIUM, true, true);
                        }
                    });

In your original document, you have mentioned is: 151.2MB compressed to 14.7MB in 18 seconds with Medium Quality.

How can I get that kind of performance.

arindamhit commented 3 years ago

@AbedElazizShe Can you please have a look on the issue.

AbedElazizShe commented 3 years ago

@arindamhit Thank you for opening this issue, could you please try version 0.8.0 and let me know if the performance is better. Thank you

arindamhit commented 3 years ago

@AbedElazizShe Not much difference. Now I tried with LOW against latest SDK 0.8.0 as per your suggestion. It took 36 secs to compress 1 min captured video (size is approx 150 MB)

Here is the code: 'runOnUiThread(new Runnable() { @Override public void run() {

                        VideoCompressor.start(currentVideoPath, destVideoPath, new CompressionListener() {
                            @Override
                            public void onStart() {
                                // Compression start,
                                Log.d("Testing", "compressed onStart  ");
                            }

                            @Override
                            public void onSuccess() {
                                // On Compression success
                                Log.d("Testing", "compressed file size ");
                                Uri uploadUri = Uri.fromFile(new File(file.toString()));
                                Log.d("Testing", String.valueOf(new File(file.toString()).isDirectory())+"   "+uploadUri.getPath());
                                if(destVideoPath.length() > 0)
                                {
                                    Log.d("Testing", "sending video " );
                                    sendVideoToServer(destVideoPath);
                                }else{
                                    destVideoPath = "";
                                    Toast.makeText(getApplicationContext(),"Error capturing video",Toast.LENGTH_SHORT).show();
                                }
                            }

                            @Override
                            public void onFailure(String failureMessage) {
                                // On Failure
                                Log.d("Testing", "compressed onFailure  ");
                            }

                            @Override
                            public void onProgress(float v) {
                                Log.d("Testing", "Progress::  ");
                                // Update UI with progress value
                            }

                            @Override
                            public void onCancelled() {
                                // On Cancelled
                                Log.d("Testing", "compressed onCancelled  ");
                            }
                        }, VideoQuality.LOW, true, true);
                    }
                });'
AbedElazizShe commented 3 years ago

From 1 minute and 30 seconds, to 36 seconds is a huge improvement. I think that's the prefromance you have for that specific video on your testing phone. Speed may differ from on phone to another, I don't think this could be improved further, at least at the moment.

arindamhit commented 3 years ago

If I record a 5 min of video, the size of video is coming around 800 MB. When I am compressing it, is taking around 2 mins. I am trying VideoQuality.MEDIUM or VideoQuality.LOW. Is there a way to improve it?