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

Always get java.lang.IllegalStateException: mediaMetadataRetriever.e…ETADATA_KEY_VIDEO_HEIGHT) must not be null #16

Closed
lobothijau opened this issue Jul 24, 2020 · 10 comments

Comments

@lobothijau
Copy link

I use light compressor to compress video right after completing it's recording.

Before starting light compressor, I export the video with this code:

final ContentValues values = new ContentValues(5);
// The number 5 above, refer to these 5 lines
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.DATA, filePath);
values.put(MediaStore.Video.Media.DURATION, videoDuration);
values.put(MediaStore.Video.Media.HEIGHT, videoHeight);
values.put(MediaStore.Video.Media.WIDTH, videoWidth);

Uri uri = context.getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
        values);
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));

I have added MediaStore.Video.MEDIA.HEIGHT value, but why the exception state that it's null? Is it because the different value?

@AbedElazizShe
Copy link
Owner

Thank you for raising this issue. Could you please try to save your source video with the values added and try the sample app of the library? Let me know if you face the same issue.

Thank you

@lobothijau
Copy link
Author

I also experiencing similar issue with other video compressor library. I think it is because the DURATION metadata sometimes return NULL which causes crash while the compressor trying to parse it into Long.

I tried to catch the exception from my code to prevent crash but not success.

I have also tried to import the library as a module to modify compressor code to set the process as failed if one of the required data is null (to prevent crash), but since I'm using Java there is some error associated with compilation and I don't know where the cause is because the compiler didn't tell me where.

e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation

What do you think?

@AbedElazizShe
Copy link
Owner

It's a bit difficult to identify the issue. But there are a few things you can try to narrow down the causes. For example, will it work if you don't set a hight and width? Are you sure the values you pass are not Null? How can the duration be null? You can start with hardcoded values, and see if the problem is with the library handling the values, or the problem in the original values passed to the library.

Looking forward to hearing from you

@lobothijau
Copy link
Author

Are you sure the values you pass are not Null? Yes, because the duration is computed while recording the video. If the video itself present and can be played, how can the duration be null? I'm pretty sure that the duration is not null, because the video is there, it can be played, and there is a duration information on the video file. But this problem is not on every device, currently it's on Xiaomi where it's keep getting crashed.

Is it possible to send custom height, width or duration to the library? The compressVideo on Compressor.kt doesn't have them on the function definition:

fun compressVideo(
        source: String,
        destination: String,
        quality: VideoQuality,
        isMinBitRateEnabled: Boolean,
        keepOriginalResolution: Boolean,
        listener: CompressionProgressListener
    )

@lobothijau
Copy link
Author

lobothijau commented Aug 2, 2020

It's fine if the library couldn't continue to process the compression because the needed information is incomplete. I could just tell the user to use the file as is or re-record a new video. But, I would like to prevent it from crashing the app.

@AbedElazizShe
Copy link
Owner

Thank you for your feedback. I can add this option to pass video height, width, and duration if needed. But what would be the purpose of doing that? Since the library would extract that while keeping the ratio of the video so It does not get stretched for instance.

@lobothijau
Copy link
Author

lobothijau commented Aug 2, 2020

I don't think you need to add option to pass the values, I mean this problem only happen on some phone (in my Samsung I never experience this). But, how about sending a failed flag if the required data is null before converting the null value to int or long?

@AbedElazizShe
Copy link
Owner

Yes sure, I will handle this and will notify you when it's done. Thank you a lot :D

@AbedElazizShe
Copy link
Owner

Please try version 0.6.2 and close the issue if everything is ok

@lobothijau
Copy link
Author

Tested and never crashed on the devices which got it before.

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

2 participants