polarby / render

A package to render any native static and moving flutter widgets to exportable formats
https://pub.dev/packages/render
MIT License
49 stars 26 forks source link

Unhandled Exception: type 'RenderError' is not a subtype of type 'RenderResult' in type cast #20

Closed jerrypaulsam closed 11 months ago

jerrypaulsam commented 11 months ago

I am getting this error in Android phones. Unhandled Exception: type 'RenderError' is not a subtype of type 'RenderResult' in type cast

RenderError(timestamp: 0:00:06.225000, exception: RenderException([Ffmpeg execution error] [amediacodec @ 0xb400007cde9f4b80] android.media.MediaCodec$CodecException: Error 0xffffffc3
I/flutter (28087): , details: null), fatal: true)

The code:

final stream = await stream.firstWhere((event) => event.isResult || event.isFatalError);
result = stream as RenderResult; // The error is being thrown here

Please do help!

Thanks

polarby commented 11 months ago

Note that result.isResult the same is as result is RenderResult. In your case result is an error and therefore cannot be assumed to be RenderResult.

What you have to do is, check if the operation is successful (return is RenderResult) or unsuccessful (return type is an RenderFatalError).

jerrypaulsam commented 11 months ago

I was able to solve this error by manually specifying the video codec libx264 in every ffmpeg operation. Without it the operation were failing and returning the error.

polarby commented 11 months ago

You just eliminated the error (- which is great👍🏻) but I highly recommend you to test for errors as well! This way your app won’t stop working unexpectedly, but you can tell the user what went wrong.

PS. Could you also explain what you mean by specifying the codec? Did you use a different ffmpeg version?

jerrypaulsam commented 11 months ago

Hello @polarby

I tested the package with different devices, it isn't working with Oneplus 8 pro, redmi note , and realme device but is working fine in Samsung devices and iphones.

In realme device, I specified the "-c: v libx264" specifically to make it work, but it is still inconsistent and I don't think that's the real issue.

I tried with latest version of min_gpl and https_gpl packages. both throwing the same error.

I am getting the mediacodec error thrown by ffmpeg: RenderError(timestamp: 0:00:06.796000, exception: RenderException([Ffmpeg execution error] [amediacodec @ 0xb400007e4cefaa00] android.media.MediaCodec$CodecException: Error 0xffffffc3 I/flutter (15303): , details: null), fatal: true)

Is there a workaround for this? I tried with captureMotion and captureMotionWithStream and getting the same error in these devices.

captureImage works fine in all devices.

polarby commented 11 months ago

Oh! That sure is a different issue! Which we might need to move to another issue.

I am unaware of codec issue on certain devices -> especially what’s weird is that captureImage works. Must be something with video processing. Did you try to put a different output format?

Could you please open a new issue and set the logLevel to debug, so we can see the whole process what is going wrong?!

jerrypaulsam commented 11 months ago

Hello

Thanks for the response.

I opened a new issue.