c++ - What FFMPEG return when camera is disabled (unplug) -


i use ffmpeg connect ip camera via rtsp stream. try detect if connection lost. create timeout interrupt_callback, , check output of av_read_frame(), sometime work , can reconnect camera. if disable camera (unplug network cable), it's blocked , pause forever. hope has similar issue , can me. here try:

setting interrupt_callback:

ifmt_ctx = avformat_alloc_context(); ifmt_ctx->interrupt_callback.callback = interruptcallback; ifmt_ctx->interrupt_callback.opaque = this;  if ((ret = avformat_open_input(&ifmt_ctx, in_file, 0, &options)) != 0) {     log.error("could not open input stream {}", in_file);     return 1; } 

interrupt_callback function:

int ctffmpeg::interruptcallback(void *ctx) {     ctffmpeg* camera = reinterpret_cast<ctffmpeg*>(ctx);     struct tm *tm;     time_t now;     = time(0);     tm = localtime (&now);     int nowtime_callback = tm->tm_sec;     if ((nowtime_callback - camera->inittime_callback) > 15) { //timeout after 20 seconds         logger log{__func__};         log.error("time out");         return 1;     }      return 0; } 

try restart connection:

ff->ret = av_read_frame(ff->ifmt_ctx, &(ff->tmp_pkt));      if (ff->ret < 0){     // restart here } 


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -