Tourenathan-G5organisation / SiliCompressor

A powerful, flexible and easy to use Video and Image compression library for Android.
Apache License 2.0
1.39k stars 292 forks source link

Compressed video seems to be corrupted. #161

Open charlieaboumoussa opened 4 years ago

charlieaboumoussa commented 4 years ago

I am using an Async Task:

VideoCompressAsyncTask compressAsyncTask = new VideoCompressAsyncTask(getApplicationContext(), imageWithTextMessage, videoThumbnail);
                    compressAsyncTask.execute("true", mUriVideo.toString()), getApplicationContext().getExternalFilesDir(Environment.DIRECTORY_MOVIES).getPath());
class VideoCompressAsyncTask extends AsyncTask<String, String, String> {

        Context mContext;
        Message mMessage;
        Bitmap mThumbnailBitmap;

        public VideoCompressAsyncTask(Context context, Message message, Bitmap thumbnailBitmap) {
            mContext = context;
            mMessage = message;
            mThumbnailBitmap = thumbnailBitmap;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mLoadingView.setVisibility(View.VISIBLE);
        }

        @Override
        protected String doInBackground(String... paths) {
            String filePath = null;
            try {

                //This bellow is just a temporary solution to test that method call works
                boolean b = Boolean.parseBoolean(paths[0]);
                if (b) {
                    filePath = SiliCompressor.with(mContext).compressVideo(paths[1], paths[2],1280,
                            720,
                            1500000);
                } else {
                    Uri videoContentUri = Uri.parse(paths[1]);
                    // Example using the bitrate and video size parameters
                    /*filePath = SiliCompressor.with(mContext).compressVideo(
                            videoContentUri,
                            paths[2],
                            1280,
                            720,
                            1500000);*/
                    filePath = SiliCompressor.with(mContext).compressVideo(
                            videoContentUri,
                            paths[2]);
                }

            } catch (URISyntaxException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return filePath;

        }
     @Override
        protected void onPostExecute(String compressedFilePath) {
            super.onPostExecute(compressedFilePath);
            mViewModel.sendVideoMessage(mMessage, Uri.parse(compressedFilePath), FileHelper.getInstance().compressBitmap(mThumbnailBitmap, 60), mCurrentGroupId);
        }
    }

The compressed video seems to be corrupted. It appears as a normal mp4 file, but when I click on it the device gives me a notice: "Failed to play video. An unknown error has occured.".
The original video that corresponds to mVideoUri works just fine on the device. Does it have have to do with the orignal video's audio/video codec? Can anyone help me please?

PS: I am using this library as the app's camera. https://github.com/natario1/CameraView implementation 'com.otaliastudios:cameraview:2.6.4'

charlieaboumoussa commented 4 years ago

I would really love if anyone shares if he/she encountered this issue.

maria-chris commented 4 years ago

Just wait until compression is finished and than open the video file compressed. You can see that compression file mp4 on device even if compression hasn't finished yet. That's why you see : "Failed to play video. An unknown error has occured.".

ankitbatra11 commented 4 years ago

Just wait until compression is finished and than open the video file compressed. You can see that compression file mp4 on device even if compression hasn't finished yet. That's why you see : "Failed to play video. An unknown error has occured.".

I think @charlieaboumoussa is correctly using the URI in onPostExecute i.e. when the background task is completed.

I am also facing this issue but with a different video.

charlieaboumoussa commented 4 years ago

@maria-chris So I cannot do anything with the compressedUri until the file is compressed, or else the compression would be interrupted. Is that what you mean? Yet I am waiting for the compression to finish in onPostExecute. How can we fix this? And is there another reliable library? Thank you

charlieaboumoussa commented 4 years ago

@ankitbatra11 So it seems you have the same issue. How did you solve this? Thank you

ankitbatra11 commented 4 years ago

I am using my own fork of this video compressor which also provides a progress listener.

VIDEO_COMPRESSOR_VERSION = 1.0.3
implementation group: 'com.github.ankitbatra11', name: 'VideoCompressor', version: VIDEO_COMPRESSOR_VERSION
charlieaboumoussa commented 4 years ago

Hello @ankitbatra11 I have added implementation 'com.github.ankitbatra11:VideoCompressor:1.0.3' I have the following error: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.ankitbatra11:VideoCompressor:1.0.3 Any suggestions?

ankitbatra11 commented 4 years ago

Hello @ankitbatra11 I have added implementation 'com.github.ankitbatra11:VideoCompressor:1.0.3' I have the following error: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.ankitbatra11:VideoCompressor:1.0.3 Any suggestions?

You must use jitpack as one of the repos in your android project.

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://www.jitpack.io"
        }
    }
}
charlieaboumoussa commented 4 years ago

@ankitbatra11 Hello. It is still showing the same error. It is a hassle to implement compression on android. What to do?

charlieaboumoussa commented 4 years ago

@Tourenathan-G5organisation if you could help, it would be great! thank you

ankitbatra11 commented 4 years ago

@ankitbatra11 Hello. It is still showing the same error. It is a hassle to implement compression on android. What to do?

Can you paste your root build.gradle file?