需要解决的问题
1、FFmpeg去连接的时候相机不在线导致avformat_open_input等函数一直死等,造成程序卡死
2、av_read_frame的过程中相机断开连接导致读取码流一直死等
解决方法
打开流媒体之前注册FFmpeg回调函数
- int CffmpegUIDlg::interrupt_cb(void *ctx)
- {
- CffmpegUIDlg *pThis = (CffmpegUIDlg *)ctx;
- if((av_gettime() - pThis->dwLastFrameRealtime) > 100 * 1000 * 1000){
- printf("主码流断开");
- return AVERROR_EOF;
- }
- return 0;
- }
- pFormatCtx = avformat_alloc_context();
-
- pFormatCtx->interrupt_callback.opaque = pMainDlg;
- pFormatCtx->interrupt_callback.callback = interrupt_cb;
- AVDictionary* options = nullptr;
- av_dict_set(&options, "rtsp_transport", "tcp", 0);
- av_dict_set(&options, "stimeout", "3000000", 0);
-
-
- int nRet = avformat_open_input(&pFormatCtx, filename, NULL, &options);
- if (nRet != 0)
- {
- printf("av open input file failed!\n");
- exit(1);
- }
- if(options != nullptr){
- av_dict_free(&options);
- }