Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compressed video seems to be corrupted. #161

Open
charlieaboumoussa opened this issue Nov 3, 2020 · 11 comments
Open

Compressed video seems to be corrupted. #161

charlieaboumoussa opened this issue Nov 3, 2020 · 11 comments

Comments

@charlieaboumoussa
Copy link

charlieaboumoussa commented Nov 3, 2020

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
Copy link
Author

charlieaboumoussa commented Nov 4, 2020

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

@maria-chris
Copy link

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
Copy link

ankitbatra11 commented Nov 6, 2020

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
Copy link
Author

charlieaboumoussa commented Nov 7, 2020

@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
Copy link
Author

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

@ankitbatra11
Copy link

ankitbatra11 commented Nov 8, 2020

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
Copy link
Author

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
Copy link

ankitbatra11 commented Nov 8, 2020

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
Copy link
Author

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

@charlieaboumoussa
Copy link
Author

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

@ankitbatra11
Copy link

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants