Search code examples
androidffmpegrtspfatal-error

android ffmpeg error fatal signal 11


I'm using ffmpeg on Android. and Use RTSP webcam.

I refer here.

I get good video.

But I receive error when I ended the video.

Fatal signal 11 (SIGSEGV) at 0x8a7c0d04 (code=1), thread 2537 (Thread-13225)

So I found the error using the log. But I don't know why the error occurred.

The code below is the location of the error.

void closeMovie(){
  av_read_pause(gFormatCtx);
  if (gVideoBuffer != NULL) {
    free(gVideoBuffer);
    gVideoBuffer = NULL;
  }
  if (gFrame != NULL)
      av_free(gFrame);
  if (gFrameRGB != NULL)
      av_free(gFrameRGB);
  if (gVideoCodecCtx != NULL) {
      avcodec_close(gVideoCodecCtx);
      av_free(gVideoCodecCtx);
      gVideoCodecCtx = NULL;
  }
  if (gFormatCtx != NULL) {
      **av_close_input_file(gFormatCtx);** //here
      gFormatCtx = NULL;
  }
}

and

void av_close_input_file(AVFormatContext *s)
{
  AVIOContext *pb = (s->iformat->flags & AVFMT_NOFILE) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ?
                   NULL : s->pb;
  **av_close_input_stream(s);**// here
  if (pb)
    avio_close(pb);
}

and

void av_close_input_stream(AVFormatContext *s)
{
    flush_packet_queue(s);
    if (s->iformat->read_close)
       **s->iformat->read_close(s);** //here
    avformat_free_context(s);
}

if //s->iformat->read_close(s); not crash

But I can not open the video once more. Again to open the video I have to quit the app.

Sorry, I can't speak English very well. Thanks for reading.

ps1. LogCat

12-10 10:08:02.991: D/TAG(21770): TAG - closeMovie1 - in
12-10 10:08:02.991: D/TAG(21770): TAG - avcodec_close - in
12-10 10:08:02.991: D/TAG(21770): av_opt_free - on
12-10 10:08:02.991: D/TAG(21770): av_opt_free - out
12-10 10:08:02.991: D/TAG(21770): TAG - avcodec_close - out
12-10 10:08:02.991: D/TAG(21770): TAG - av_close_input_file - in
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_close_input - in
12-10 10:08:02.991: D/TAG(21770): TAG - flush_packet_queue - 
12-10 10:08:02.991: D/TAG(21770): flush_packet_queue - on
12-10 10:08:02.991: D/TAG(21770): flush_packet_queue - out
12-10 10:08:02.991: D/TAG(21770): TAG - s->iformat->read_close : 0
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_free_context 
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_free_context - in
12-10 10:08:02.991: D/TAG(21770): av_opt_free - on
12-10 10:08:02.991: D/TAG(21770): av_opt_free - out
12-10 10:08:02.991: D/TAG(21770): av_opt_free - on
12-10 10:08:02.991: D/TAG(21770): av_opt_free - out
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_length s->nb_streams - 3
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_nb_streams - in
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_ nb_streams - out
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_nb_streams - in
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_ nb_streams - out
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_nb_streams - in
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_ nb_streams - out
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_for_length s->nb_programs-1 - -1
12-10 10:08:02.991: D/TAG(21770): TAG - freep 1
12-10 10:08:02.991: D/TAG(21770): TAG - freep 2
12-10 10:08:02.991: D/TAG(21770): TAG - while
12-10 10:08:02.991: D/TAG(21770): TAG - freep 3
12-10 10:08:02.991: D/TAG(21770): TAG - dict_free 1
12-10 10:08:02.991: D/TAG(21770): TAG - freep 4
12-10 10:08:02.991: D/TAG(21770): TAG - freep 3
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_free_context - out
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - in
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - 1
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - 2
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - out
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close(pb) : 0
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - in
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - 1
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - 2
12-10 10:08:02.991: D/TAG(21770): TAG - avio_close - out
12-10 10:08:02.991: D/TAG(21770): TAG - avformat_close_input - out
12-10 10:08:02.991: D/TAG(21770): TAG - av_close_input_file - out
12-10 10:08:02.991: D/TAG(21770): TAG - closeMovie1 - out
12-10 10:08:03.151: D/AbsListView(21770): onVisibilityChanged() is called, visibility : 0
12-10 10:08:03.151: D/AbsListView(21770): unregisterIRListener() is called 
12-10 10:08:03.201: D/AbsListView(21770): unregisterIRListener() is called 
12-10 10:08:03.221: D/AbsListView(21770): unregisterIRListener() is called 
12-10 10:08:03.241: A/libc(21770): Fatal signal 11 (SIGSEGV) at 0x8bb85698 (code=1), thread 21938 (Thread-23561)

ps2.The order of the log.

(BasicPlayer.c) closeMovie in->
(utils.c) avcodec_close ->
(utils.c) av_close_input_file ->
(utils.c) avformat_close_input ->
(utils.c) flush_packet_queue ->
(utils.c) **s->iformat->read_close(s)** ->
(utils.c) avformat_free_context ->
(utils.c) avio_close(pb) ->
(BasicPlayer.c) closeMovie out

Solution

  • Thanks for reading.

    I had to solve.

    add code utils.c

    typedef struct {
        int audio_size;    /**< audio packet size (bytes) */
        int video_size;    /**< video packet size (bytes) */
        int palette_size;  /**< palette size (bytes) */
        int video_type;    /**< per-frame video compression type */
    } JVFrame;
    typedef struct {
         JVFrame *frames;
         enum {
             JV_AUDIO = 0,
             JV_VIDEO,
             JV_PADDING
         } state;
         int64_t pts;
    } JVDemuxContext;
    

    and

    static int read_close(AVFormatContext *s)
    {
    
        JVDemuxContext *jv = s->priv_data;
        av_free(jv->frames);
        return 0;
    }
    

    and modifying the code.

    void av_close_input_stream(AVFormatContext *s)
    {
        flush_packet_queue(s);
        if (s->iformat->read_close)
           //**s->iformat->read_close(s);** //here fixed --> 
           read_close(s);
        avformat_free_context(s);
    }
    

    I don't know .why error is generated.

    But it was resolved by modifying the code.

    If you have any problem, I hope that this helps.

    Sorry, I can't speak English very well. Thanks for reading.