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

When try to compress video output as black screen with audio #15

Closed maulikdadhaniya closed 4 years ago

maulikdadhaniya commented 4 years ago

i try this library , when i try to compress video that output will only black screen video. here is my code

                            selectedContentUri = contentURI
                            selectedVideoPath = getMediaPath(context!!, selectedContentUri)
                            videoUriList.add(contentURI)
                            type = "video"
                            val file = File(selectedVideoPath)

                            val downloadsPath =
                                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
                            val desFile = File(downloadsPath, "${System.currentTimeMillis()}_${file.name}")
                            if (desFile.exists()) {
                                desFile.delete()
                                try {
                                    desFile.createNewFile()
                                } catch (e: IOException) {
                                    e.printStackTrace()
                                }

                            }

                            VideoCompressor.start(
                                selectedVideoPath,
                                desFile.path,
                                object : CompressionListener {
                                    override fun onProgress(percent: Float) {
                                         progressDialog = ProgressDialog(context)
                                        progressDialog!!.setMessage("Please wait ${percent.toLong()}")
                                        progressDialog!!.show()

                                    }

                                    override fun onStart() {

                                    }

                                    override fun onSuccess() {

                                        Toast.makeText(context,"Sucess",Toast.LENGTH_SHORT).show()
                                        selectedVideoPath = desFile.path
                                        Log.e("SUCESSS","Sucess === "+selectedVideoPath)

                                    }

                                    override fun onFailure(failureMessage: String) {
                                        Toast.makeText(context,""+failureMessage,Toast.LENGTH_SHORT).show()
                                    }

                                    override fun onCancelled() {

                                    }
                                }, VideoQuality.MEDIUM, isMinBitRateEnabled = false, keepOriginalResolution = false)
AbedElazizShe commented 4 years ago

Thank you for raising this issue. Could you please let me know what is the device you're using and which Android version?

maulikdadhaniya commented 4 years ago

I using Samsung Galaxy M31 (Android 10) and xiaomi MI Redmi 3s (Android 6) both device getting black video in output.

AbedElazizShe commented 4 years ago

I will look into the issue. Do you see any errors at logcat?

maulikdadhaniya commented 4 years ago

look this image I got this error in Compressor.kt object file

AbedElazizShe commented 4 years ago

Thank you for sharing this. Does it fail with any video? Would you mind sharing one of these videos as I never encounter the problem before and it can be tricky to fix without recreating the issue.

maulikdadhaniya commented 4 years ago

fail with all video. yaa sure i will share video on your mail id. Thank you

AbedElazizShe commented 4 years ago

Thank you. Could you please post from where you're calling VideoCompresor.start()?

maulikdadhaniya commented 4 years ago

againsubmit Here selectedVideoPath is my selected video path.

AbedElazizShe commented 4 years ago

It's not showing much, just ensure your code is not running on a thread that has a looper!

maulikdadhaniya commented 4 years ago

runonUithread My Code in Seperate thread Please look shared image

AbedElazizShe commented 4 years ago

Could you please try to use the sample app and let me know if it working there, and please send me one of these videos. It may be related to codecs.

maulikdadhaniya commented 4 years ago

in sample app , working fine , but when i used lib , display black video. Yaa sure i send video in few minutes.

maulikdadhaniya commented 4 years ago

I sent mail with atteched video please check it out

AbedElazizShe commented 4 years ago

Received, thanks. Since it is working with sample app, most probably the compression is fine. I will create a testing app later today and try to identify the possible cases leading to such an issue. Will update you. Thank you for your help

maulikdadhaniya commented 4 years ago

Your welcome , Please let me know . Thank you.

maulikdadhaniya commented 4 years ago

and one more thing i tell you i use Fragment.

AbedElazizShe commented 4 years ago

Could you please try to remove runOnUiThread and everything inside onProgress() and try again? I believe that piece of code is what causing the issue

maulikdadhaniya commented 4 years ago

will check in minutes

maulikdadhaniya commented 4 years ago

Hi mp4 generate sucessfully , but now i try to open that file it display Can't play this file from FileManager

AbedElazizShe commented 4 years ago

Would you mind sharing the code again, showing the entire function when the compression code is added and from where that function is called.

AbedElazizShe commented 4 years ago

Does the issue still happening? Did you figure out a solution ? And did you try the sample app?

maulikdadhaniya commented 4 years ago

Yes still issue. yes also try in sample app it work perfectly but in my code its not work like sample app

AbedElazizShe commented 4 years ago

Thank you. If it works fine in the sample, then you're implementatin is not correct. Try to play around, create a playground app, test the compression there and try to identify why it's not working in your app. If by any chance your project is available on Github, you can share it and I will help you fix the issue. Wll close this by now.