使用RTSP判断摄像机设备是否在线以及快照抓取
2017-08-13 23:18
1701 查看
是否在线
EasyNVR可以使用Onvif/RTSP协议接入摄像机在EasyNVR应用中非常重要的一环就是设备的在线状态判断和快照抓取
设备在线状态判断有很多种方法又没有什么方法
说有很多种方法指的是,我们可以使用ICMP协议对设备的进行ping操作,或者可以对设备的特定端口进行连接获取判断连接是否一次,再或者使用RTSP协议流程进行判定,但是都有个问题–不靠谱,禁ping,端口未知,RTSP协议实现不标准,都会导致–不靠谱
所以说,没什么方法
作为EasyNVR来说,肯定需要一个靠谱的,能够准确判定设备是否在线的方法
那就是–走RTSP流程拉流
拉流都成功了,你肯定在线,否则你不在线,不然在线联网又有什么用?我又不能用
快照抓取
快照抓取这件事就很简单了使用我们的大杀器EasyRTSPClient,定时将拉取的I帧转码保存成图片,这很简洁明了
int DecoderHelper::WriteJPEG(const char* out_file) const { // 输出文件路径 if (!out_file) return -1; // 分配AVFormatContext对象 AVFormatContext* avFormatContext = avformat_alloc_context(); // 设置输出文件格式 avFormatContext->oformat = av_guess_format("mjpeg", NULL, NULL); // 创建并初始化一个和该url相关的AVIOContext if (avio_open(&avFormatContext->pb, out_file, AVIO_FLAG_READ_WRITE) < 0) { printf("Couldn't open output file."); return -2; } // 构建一个新stream AVStream* avStream = avformat_new_stream(avFormatContext, NULL); if (!avStream) { return -1; } // Begin Output some information //av_dump_format(pFormatCtx, 0, out_file, 1); // End Output some information AVCodecParameters* codecpar = avStream->codecpar; codecpar->codec_id = avFormatContext->oformat->video_codec; // 查找解码器 AVCodec* codec = avcodec_find_encoder(codecpar->codec_id); if (!codec) { printf("Codec not found."); return -1; } // 设置该stream的信息 AVCodecContext* avCodecContext = avcodec_alloc_context3(codec); avcodec_parameters_to_context(avCodecContext, codecpar); avCodecContext->codec_type = AVMEDIA_TYPE_VIDEO; avCodecContext->pix_fmt = AV_PIX_FMT_YUVJ420P; avCodecContext->width = width_; avCodecContext->height = height_; avCodecContext->time_base.num = 1; avCodecContext->time_base.den = 25; // 设置pCodecCtx的解码器为pCodec int ret = avcodec_open2(avCodecContext, codec, NULL); if (ret < 0) { printf("Could not open codec.ret=%d", ret); return -1; } //Write Header avformat_write_header(avFormatContext, NULL); //Encode // 给AVPacket分配足够大的空间 AVPacketWrapper packetWrapper(width_ * height_ * 3); AVPacket* packet = packetWrapper.getPacket(); ret = avcodec_send_frame(avCodecContext, avFrame_); if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { return -3; } ret = avcodec_receive_packet(avCodecContext, packet); if (ret < 0 && ret != AVERROR_EOF) { return -3; } av_write_frame(avFormatContext, packet); //Write Trailer av_write_trailer(avFormatContext); avio_close(avFormatContext->pb); avcodec_free_context(&avCodecContext); avformat_free_context(avFormatContext); return 0; }
好的配合
我们何不把快照抓取和在线状态判定做到一起呢?是的,抓取到快照我们判断为在线,否则为离线
这样,摄像机的在线状态是“真正的”在线状态
获取更多信息
邮件:support@easydarwin.orgWEB:www.EasyDarwin.org
Copyright © EasyDarwin.org 2012-2017
相关文章推荐
- Face++在线接口在Android下的使用,以及简单的Demo实现(判断两张脸是否为同一个人)
- Face++在线接口在Android下的使用,以及简单的Demo实现(判断两张脸是否为同一个人)
- EasyNVR RTSP摄像机HLS直播服务器中使用Onvif协议获取设备快照
- EasyNVR RTSP摄像机HLS直播服务器中使用Onvif协议获取设备快照
- jfinal使用session判断是否登录以及登录超时
- C# 判断设备是否在线
- 如何使用JavaScript来判断是否为移动设备
- 判断用户是否禁止该App使用设备麦克风
- 使用数据库判断在线名单以及在线人数
- Android 判断设备 是否使用代理上网
- 如何使用JavaScript来判断是否为移动设备
- C++ new与delete使用的位置,以及判断内存是否泄露的简单方式
- 使用File类判断文件是否存在以及创建,拷贝和移动文件
- libphonenumber 使用 以及判断国家代码 号码是否有效运营商等
- C#获取已被使用的网络端点以及判断端口是否已被使用
- 使用JavaScript判断用户是否为手机设备
- 使用js判断访问者是否为移动设备
- C语言判断文件夹或者文件是否存在以及权限等信息access函数和删除文件或目录 remove()函数使用实例
- Android 如何判断设备是否联网以及WIFI 是否开启