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

Compressor works only first time #97

Closed mmmatjaz closed 2 years ago

mmmatjaz commented 2 years ago

When I try to compress another video onFailure gets called with error message: Failed to extract video meta-data, please try again

my usecase: ` VideoCompressor.start( null, // => This is required if srcUri is provided. If not, pass null. null, // => Source can be provided as content uri, it requires context. videoFile.getPath(), videoFileCompressed.getPath(), new CompressionListener() { @Override public void onStart() { // Compression start }

                    @Override
                    public void onSuccess() {
                        runOnUiThread(() -> {
                            Toast.makeText(VideoRecActivity.this, "compressed", Toast.LENGTH_SHORT).show();;
                        });
                    }

                    @Override
                    public void onFailure(String failureMessage) {
                        Log.e("compress", failureMessage);
                        runOnUiThread(() -> {
                            Toast.makeText(VideoRecActivity.this, "failed to compress", Toast.LENGTH_SHORT).show();;
                            //uploadFromUri(Uri.fromFile(videoFileCompressed));
                            //uploadFromUri(Uri.fromFile(videoFile));
                        });
                    }

                    @Override
                    public void onProgress(float v) {
                        // Update UI with progress value
                        /*
                        runOnUiThread(new Runnable() {
                            public void run() {
                                progress.setText(progressPercent + "%");
                                progressBar.setProgress((int) progressPercent);
                            }
                        });*/
                    }

                    @Override
                    public void onCancelled() {
                        // On Cancelled
                    }
                }, new Configuration()
        );

`

mmmatjaz commented 2 years ago

It seems I found the problem. I was trying to compress the file immediately after calling VideoCapture.stopRecording(), but the latter one is obviously non-blocking and needs some time to let go of the file. Therefore metadata reading failed. I'm now launching compression with a delay and it seems to work fine.