[FFmpeg-user] When second time to do video processing using FFmpeg in JNI in Android, the app crashes with fatal signal 11

Li codingpotatolinda at gmail.com
Wed Sep 25 18:11:17 CEST 2013

This is an Android application, perform video processing using FFmpeg in
JNI in Android.
When the app is installed in the device, and run the first time to process
one video file, the app runs very well.
After the first video file is processed, I proceed to choose the second
video file to start processing. The app immediately crashes.

Log error is:

09-25 10:53:52.801: I/native-activity(2339): begin: open_input_file .mov .
09-25 10:53:52.801: I/native-activity(2339): open_input_file
09-25 10:53:52.801: I/native-activity(2339): begin: avformat_open_input .
09-25 10:53:52.811: I/native-activity(2339): avformat_open_input ret: 0
09-25 10:53:52.811: I/native-activity(2339): begin:
avformat_find_stream_info .
09-25 10:53:52.811: A/libc(2339): Fatal signal 11 (SIGSEGV) at 0x00000028
(code=1), thread 2569 (IntentService[V)

The app crashes in "ret =
avformat_find_stream_info(inVStruct.inFormatContext, NULL"
See the snippet below:

    LOGI("begin: avformat_find_stream_info .\n");
    if ((ret = avformat_find_stream_info(inVStruct.inFormatContext, NULL))
< 0) {
        LOGI("Cannot find stream information\n");
        av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n");
        return ret;

Following the FFmpeg tutorial, I have done 5 steps to free memory for
related variables in opened input video file and output video file:
// 1: close CodecContext: avcodec_close(AVCodecContext)
// 2: free Frame: avcodec_free_frame(AVFrame *): free frame and dynamically
allocated objects in it, e.g. extended_data; av_free(AVFrame *)
// 3: close the file (either AVFormatContext->pb, or FILE *):
avio_close(AVFormatContext->pb); fclose(FILE *)
// 4: free AVFormatContext and all its streams:
avformat_free_context(AVFormatContext *)
// 5: free data:  av_free( * ): Free a memory block which has been
allocated with av_malloc(z)() or av_realloc(). av_freep recommended. e.g.

All freeings are fine.

One minor point: From demuxing.c, it seems it does not do
avformat_free_context for the input video file.
I tried that in the program, and it shows error; so I remove the two
sentences below.
    LOGI("finish: inVStruct.inFormatContext");
////    09-25 10:49:40.222: A/libc(1915): @@@ ABORTING: LIBC: ARGUMENT IS
INVALID HEAP ADDRESS IN dlfree addr=0x7204a0a8
////    09-25 10:49:40.222: A/libc(1915): Fatal signal 11 (SIGSEGV) at
0xdeadbaad (code=1), thread 2107 (IntentService[V)

I suspect the  the crash when doing processing the 2nd time is because of
something is not freed, so it is out of memory.
But I do free those variables.

Any clue? Thanks!

More information about the ffmpeg-user mailing list