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

Duplicate class import error with ffmpeg package #8

Closed rlee1990 closed 1 year ago

rlee1990 commented 1 year ago

Hi is is possible to use the ffmpeg_kit_flutter instead of the one used in this package? It causes issues with other packages that all use ffmpeg_kit_flutter.

polarby commented 1 year ago

Hi, Renderuses ffmpeg_kit_flutter_https_gpl, which is a sub-package of ffmpeg_kit_flutter. Could you please provide the errors you are getting? I suspect this is an import issue , which would mean you need to change the imports a bit:

Example: Instead of

import 'package:flutter/services.dart';

do:

import 'package:flutter/services.dart' as service;

service.yourMethod();
rlee1990 commented 1 year ago

The error I get is Duplicate class com.arthenica.ffmpegkit.Statistics found in modules jetified-ffmpeg-kit-https-5.1-runtime I receive this trying to build for android. The other package that I am using is video_trimmer

polarby commented 1 year ago

Ok got it. Have you tried changing the imports, like i have shown? In case this resolves this, i will adjust the import line in Renderpackage, so you can import like you would do normally....

Could you prepare a quick example for debugging, if this doesnt work? I will be on it right away!

rlee1990 commented 1 year ago

Ok got it. Have you tried changing the imports, like i have shown? In case this resolves this, i will adjust the import line in Renderpackage, so you can import like you would do normally....

Should I be changing them in your package or in the code I write because I don't directly use the services import

polarby commented 1 year ago

No the import in your code. Sorry, the service import was just an example. Change your Ffmepg / video_trimmerimport like the example.

rlee1990 commented 1 year ago

Sorry trying that now

rlee1990 commented 1 year ago

I am using flutter 3.7 if that makes a difference. I also tried removing video_trimmer and then it will build. Tried adding video_trimmer and removing the render packager and it builds. Nope it still fails to build the application:

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.arthenica.ffmpegkit.Abi found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.AbiDetect found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.AbstractSession found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.AsyncFFmpegExecuteTask found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.AsyncFFprobeExecuteTask found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.AsyncGetMediaInformationTask found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.BuildConfig found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.CameraSupport found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Chapter found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegKit found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegKitConfig found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegKitConfig$1 found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegKitConfig$2 found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegKitConfig$SAFProtocolUrl found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegSession found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFmpegSessionCompleteCallback found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFprobeKit found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFprobeSession found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.FFprobeSessionCompleteCallback found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Level found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Log found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.LogCallback found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.LogRedirectionStrategy found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.MediaInformation found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.MediaInformationJsonParser found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.MediaInformationSession found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.MediaInformationSessionCompleteCallback found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.NativeLoader found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Packages found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.ReturnCode found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Session found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.SessionState found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Signal found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.Statistics found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.StatisticsCallback found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
     Duplicate class com.arthenica.ffmpegkit.StreamInformation found in modules jetified-ffmpeg-kit-https-5.1-runtime (com.arthenica:ffmpeg-kit-https:5.1) and jetified-ffmpeg-kit-https-gpl-5.1-runtime (com.arthenica:ffmpeg-kit-https-gpl:5.1)
polarby commented 1 year ago

Thanks for the issue. Could you provide me with a quick and dirty example with video_trimmer import so i can run it and debug it?

rlee1990 commented 1 year ago

Sure Ill get started on that right now

polarby commented 1 year ago

Also, can you check if this solution helps? This might be a multi dex issue and not related to this plugin.

rlee1990 commented 1 year ago

Also, can you check if this solution helps? This might be a multi dex issue and not related to this plugin.

Yup I tried it and it still doesn't work. I will leave that in the example also.

rlee1990 commented 1 year ago

Okay the quick example is just a fork of your example and I added the video_trimmer package without using it in the code and get the errors still: https://github.com/rlee1990/render

polarby commented 1 year ago

Alright, I am on it, it might take some time!

rlee1990 commented 1 year ago

I also just did a test with the fork without deploying it back to github were I switched the FFMPEG to use the same one in video_trimmer and its working without an issue.

polarby commented 1 year ago

I was not able to find a satisfying solution for this error. It appears this is a problem happens always if there are multiple FFmpeg instances within one project. This can either be by multiple plugins imports that use Ffmpeg or a plugin with FFmpeg usage and own FFmpeg import. This error will happen with any plugin, when you use multiple instances like this.

What needs to be done?

As far as my research goes so far, there is no current appropriate resolution to this problem. As this is a double import problem of two different versions, a possible solution is to sync the Ffmpeg version number (which is not always easy, as some operations require different ffmpeg version). It would be great to isolate the plugins that are used within a package, but I am not aware of any way to do this.

In this specific issue we have both a jetified-ffmpeg-kit-https-gpl-5.1(used by Render) and the jetified-ffmpeg-kit-https-5.1(used by video_trimmer) FFmpeg usage:

2 files found with path 'lib/arm64-v8a/libavcodec.so' from inputs:
      - /Users/myName/.gradle/caches/transforms-3/29473f64bb3a0e5823587658e804b0da/transformed/jetified-ffmpeg-kit-https-gpl-5.1/jni/arm64-v8a/libavcodec.so
      - /Users/myName/.gradle/caches/transforms-3/ac7665f545673455679b57f9a4d09ae7/transformed/jetified-ffmpeg-kit-https-5.1/jni/arm64-v8a/libavcodec.so

As jetified-ffmpeg-kit-https-gpl-5.1 includes jetified-ffmpeg-kit-https-5.1, it is possible to remove the import of the lower package and therefore only depend on one -the higher- import. Therefore in the following I will give a standardized solution to how to resolve it by correcting the imports:

Dirty solution

  1. Find the package with the denominator import by running flutter pub deps and search for all FFmpeg instances (highest import, with most functions -> in this case jetified-ffmpeg-kit-https-gpl-5.1, see hierarchy ffmpeg packages)

Do the the following procedure for all sub import plugins

  1. git clone <url to package> ./lib/package_name_copy (for the render example flutter project ./example/lib -> git clone https://github.com/sbis04/video_trimmer ./example/lib/video_trimmer_copy)
  2. Manually go to ./lib/package_name_copy/pubspec.yaml and change the ffmpeg dependency to the denominator one (in our case ffmpeg_kit_flutter_https_gpl: ^5.1.0)
  3. run flutter clean & flutter pub get

Note that you will archive the current version of this package to a local directory. This is a dirty solution as updating needs to be done manually like the described solution, and therefore can only be maintained with very few packages (aka Renderand Video_trimmer).

Using FFmpeg package with Renderplugin

  1. Find the package with the denominator-import by running flutter pub deps and search for all FFmpeg instances (see above)
  2. Use the denominator-import incase your default ffmpeg_kit_flutter import

If you find a better solution I would like to ask you to post it here as well so others can maybe do a cleaner import resolution.

Same issues

Just for references, here is a small segment many more issues that have the exact same problem:

Here are problems with same issues and with solutions, that I could not reproduce:

polarby commented 1 year ago

I am gonna close this issue for now, as there is a temporary solution. Please be sure to notify me if you think this issue is ongoing and update this issue if there is a better alternative!!!

rlee1990 commented 1 year ago

@polarby is there a reason why you don't use the same exact package of ffmpeg as video_trimmer?

polarby commented 1 year ago

Yes, in order to work with the audio conversion the x264 of the https-gpl (http, which video_trimmer uses is not enough) is required:

https://github.com/polarby/render/blob/e110fce6cc4bf074319ebc6d441039571b595082/lib/src/formats/abstract.dart#L128-L131

I am sorry that there currently isn't a better way to do this (or I couldn't find it yet), but I hope that you still decide to take advantage of the great functions of FFmpeg.

rlee1990 commented 1 year ago

@polarby thanks good to know. I am keeping the package and looking for alternatives for video_trimmer that will work.