Android video trimming via ffmpeg

2019-01-23 19:19发布

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 .

4条回答
来,给爷笑一个
2楼-- · 2019-01-23 19:30

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

查看更多
时光不老,我们不散
3楼-- · 2019-01-23 19:40

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

查看更多
在下西门庆
4楼-- · 2019-01-23 19:44

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.

查看更多
倾城 Initia
5楼-- · 2019-01-23 19:53

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....

查看更多
登录 后发表回答