使用RTSP判断摄像机设备是否在线以及快照抓取
来源:互联网 发布:mac系统iso镜像下载 编辑:程序博客网 时间:2024/06/03 22:52
是否在线
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.org
WEB:www.EasyDarwin.org
Copyright © EasyDarwin.org 2012-2017
阅读全文
0 0
- 使用RTSP判断摄像机设备是否在线以及快照抓取
- EasyNVR RTSP摄像机HLS直播服务器中使用Onvif协议获取设备快照
- C# 判断设备是否在线
- 判断是否摄像机可以看到
- 判断物体摄像机是否可见
- Android 如何判断设备是否联网以及WIFI 是否开启
- Android 判断设备 是否使用代理上网
- 使用数据库判断在线名单以及在线人数
- 判断计算机是否在线
- 判断用户是否在线
- 判断QQ是否在线
- ngCordova判断是否在线
- js 判断是否在线
- Face++在线接口在Android下的使用,以及简单的Demo实现(判断两张脸是否为同一个人)
- 判断怪物是否出现在摄像机范围内
- 判断物体是否在摄像机视野中
- 判断物体是否在摄像机内
- 判断一个物体是否从摄像机消失
- 开发java web报错:The origin server did not find a current representation for the target resource or is n
- python基础-时间日期处理小结
- poj-青蛙的约会
- 用JTAG将mcs文件烧写到flash中
- 2017/8/13 jq编写插件方法
- 使用RTSP判断摄像机设备是否在线以及快照抓取
- C++笔试题 String类的实现
- JNI调用里面的多线程
- [Codeforces Round #428 DIV2E (CF839E)] Mother of Dragons
- 设计模式之外观模式
- 【原】使用Bmob作为iOS后台开发心得——查询关联关系(BmobRelation)
- UVA 147 Dollars(完全背包)
- 网易2018校招编程题集合7
- 物理CPU,物理CPU核心,逻辑CPU,超线程