Open Gelassen opened 8 years ago
+1, I'm scratching my head trying to fix this issue and would love to be able to use .AAR as it's the simplest way to add ffmpeg to the project.
Another issue, killRunningProcesses()
sometimes doesn't seem to properly kill the process. This is mostly the way how the AsyncTask
is handled. I presume this is one of the cause for memory leak, isn't it?
The easiest way to do this is to edit the source code and build a new .AAR file, you will have to build one anyway because of #79.
So for me I add this function in FFmpeg
and call it every time I need to kill a process:
public void releaseContext(){
context = null;
}
Or better yet, just remove the singleton.
+1, Hi, did someone already create a fork where killRunningProcesses and the memory leak was fixed? This repro seems to be dead :(
I managed to fix the issue on my fork. Shameful self promotion here. :)
Steps to install:
allprojects {
repositories {
jcenter()
mavenCentral()
...
maven {
url 'https://jitpack.io'
}
}
}
build.gradle
dependencies.compile 'com.github.diegoperini:ffmpeg-android-java:v0.4.6'
Link for the fork: https://github.com/diegoperini/ffmpeg-android-java
Changelog:
whenFFmpegIsReady()
to properly wait for ffmpeg state.killRunningProcesses()
to properly kill the execution.FFmpeg.getInstance()
overload to work with a ContextProvider
instead of a context. It is a fix for a common memory leak caused by storing the context internally. Old factory method is still supported but marked as deprecated.@diegoperini , are you planning to maintain the code, it is really useful , no need to build another AAR of our own, it would be useful for others , there is a preblem with isFFmpegCommandRunning() alos they need to change it from
return ffmpegExecuteAsyncTask != null && !ffmpegExecuteAsyncTask.isProcessCompleted();
to
return ffmpegExecuteAsyncTask != null || !ffmpegExecuteAsyncTask.isProcessCompleted();
@pawaom , I am okay to commit bug fixes every now and then but to be honest, there are technical things I don't think I'm proficient enough such as,
ffmpeg
binaries for android in any architecture.Now these are mentioned, your suggestion is easy to apply. You can try and test it with my fork. I also updated the README on my fork.
Edit your project's build.gradle (not app) like this. (important line is jitpack)
allprojects {
repositories {
jcenter()
mavenCentral()
...
maven {
url 'https://jitpack.io'
}
}
}
Add below line to your app's build.gradle dependencies.
compile 'com.github.diegoperini:ffmpeg-android-java:v0.4.7'
@diegoperini , thanks for the reply, can you ask others to collaborate with you, can any one else help @diegoperini , to maintain the code, this code (writing minds) seems to be abandoned, no updates in the gradle, no one replays any thing
@diegoperini , have you solved the memory leak issue, as well , please keep this code on Github, i really dont know how to build an .AAR , can some one explain that process for us
The leak is solved @pawaom . Construct FFmpeg
with newly implemented getInstance(ContextProvider)
in a way that in the body of overridden ContextProvider.provide()
, you return context by calling your fragment's getActivity()
method.
Example:
FFmpeg f = FFmpeg.getInstance(new FFmpegContextProvider() {
@Override
public Context provide() {
return myFragment.getActivity();
}
}));
Could you please fix the memory leak for this wrapper?
The issue is the FFMPEG class is the singleton and contains the Context as member field. Application context is used as this context and makes app live till lifecycle of the application. Once initialized ffmpeg lib is keep in memory forever.
I would like to have an option to release the memory allocated for it. The good option from my point of view is to add a public method, e.g. onDispose() where context will be set in null.