7

I have downloaded video trimming code from github from this link.

It’s working perfectly for the first time, but when I try to run it for the second time the code crashes without any exception then again when I try to run it for the 3rd time after the crash it works! Does any one have any idea for this kind of behaviour?

I am also developing an application which has one module of trimming videos. I would really appreciate it, if any one could help me .

Prasad G
  • 6,702
  • 7
  • 42
  • 65
Karan_Rana
  • 2,813
  • 2
  • 26
  • 35

4 Answers4

4

https://lists.ffmpeg.org/pipermail/libav-user/2012-May/001964.html

Calling native method twice of third party library in an Activity causes the Android application to close down

read about the issue with static vars in 'ffmpeg.c' ...

I would bet that u have the same problem and need to do something (3 alternate choices) to reset or GC those vars:

  1. get the java classloader that loaded the lib and GC it

  2. in the c-layer do what the OP did in above link

  3. write a 2nd shared lib that uses 'dlsym' and 'dlclose' on the first library during each call cycle

github , see the 'README' here

same issue that u r having

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43
  • Excellent answers mate, the README from github link was useful, can you please provide sample demos for your answers 1, 2 and 3? The 3rd answer given by OP is merely symbolic and being a novice in C programming I cannot figure out what he is doing so is there any other link which explains it better? – Arif Nadeem Aug 29 '12 at 08:21
  • 1
    go with 3. build a 2nd shared module in C that gets the vars in string arrary for ffmpeg then uses dlsym to get the handle then does call - Java_net_video_trimmer_natives_VideoTrimmer_trim and then DOES DLCLOSE .. the dlclose wipes all the residue from the first call. The third link in my orig ANS HAS CODE explain in it. clone it and look at 'ffmpeg_invoke' – Robert Rowntree Aug 29 '12 at 13:54
  • I wonder how you got dlclose to work, in ndk-documentation it clearly states that "Static destructors are never called at the moment, either at program exit, or when dlclose() is called." PLEASE REFER TO SYSTEM-ISSUES document in your ndk folder – Arif Nadeem Sep 06 '12 at 07:35
  • 5 steps:(*env)->GetStringUTFChars, dlopen, (*env)->ReleaseStringUTFChars, make the main call from the wrapper to your jni lib... , dlclose – Robert Rowntree Sep 06 '12 at 14:13
  • For anyone still wanting to do this with the load and unload method (it seems like it is still the most popular approach) I have added some notes on a recent implementation here: http://stackoverflow.com/a/28752190/334402 – Mick Feb 26 '15 at 20:33
3

Just make a method in your ffmpeg.c which will seems like this

void exitmycode(){
       ffmpeg_exit(0);

}

ffmpeg_exit(0) method is already there in the ffmpeg.c you just have to call exitmycode(); from your main C file after the completion of video trimming.

Now what was happening is that when you trim a video or anything else with the ffmpeg it doesn't get exit completely, so the next time you run the command it get exited, but it also don't run your trim command.Again if you run that third time, command get executed perfectly. So, what I had done is calling the ffmpeg_exit(0) manually at the end of processing done.

Jagdeep Singh
  • 1,200
  • 1
  • 16
  • 34
  • I think this causes the whole app to exit - i.e including the Android Java calling code? Also, as far as I can see ffmpeg_exit() has been replaced with exit_program() in the latest ffmpeg source. – Mick Feb 23 '15 at 19:32
0

I think that you could finish your activity and restart the application after your video trimming call in the code.

If after the second time the applicaction crashes and in the third works maybe the applications initialize and restart the application after its crash.

Try to load and unload the natives library link

Community
  • 1
  • 1
Álvaro
  • 2,872
  • 4
  • 20
  • 25
-1

Do one Thing

If You have Installed ffmpeg4android_os lib then you just need to comment 1 line of Method StopTranscoding like this

public void stopTranscoding() {
        Log.d(Prefs.TAG, "stopTranscoding called");
        if (_transcodeBackground != null) {
            //_transcodeBackground.forceCancel();
        }
    }

that all....