Get rtsp error when connection is corrupted?

2.1k views Asked by At

I using ffmpeg libavformat to record RTSP stream from the Panasonic Camera. I can get both audio and video stream frome that everything is fine until there is a corruption between server and camera.

  • the "av_read_frame" function did not return anything I think it has been waiting to received frame from camera however, it cannot due to corrupted connection. I expected that this function should complete its task and return error (connection failure or something like that) but it did not and stuck forever.
  • the same problem with "avformat_open_input" function when the connection is corrupted. Therefore, the left functions cannot be processed

Anyone can explain to me what the problem's here and what wrong with my code. How can I avoid the deadlock for this case.

(Enviroment: Win 7, VS 2010, FFMPEG: 20130227-git-5d2f2c7, LAN network)

    int main(int argc, char** argv)
{

    AVFormatContext* context = avformat_alloc_context();
    int video_stream_index;

    av_register_all();
    avcodec_register_all();
    avformat_network_init();

    //open rtsp
    if(avformat_open_input(&context, "rtsp://username:12345/192.168.1.253:554/mpeg4/640x480",NULL,NULL) != 0)
    {
        return EXIT_FAILURE;
    }

    if(avformat_find_stream_info(context,NULL) < 0)
    {
        return EXIT_FAILURE;
    } 
    AVPacket packet;
    av_init_packet(&packet);
    //start reading packets from stream and write them to file

    while(av_read_frame(context,&packet))
    {
       //Store packet here
    }
    av_free_packet(&packet);
    return (EXIT_SUCCESS);
}
1

There are 1 answers

1
Mike Versteeg On BEST ANSWER

You use ffmpeg's interrupt callback to add timeouts to those functions, see also this question.