提交 b553030b authored 作者: blu's avatar blu

init

上级 c77153b0
...@@ -23,6 +23,8 @@ namespace fs = std::filesystem; ...@@ -23,6 +23,8 @@ namespace fs = std::filesystem;
using namespace std; using namespace std;
#define URLOUT_DEFAULT "frames" #define URLOUT_DEFAULT "frames"
#define NUM_PKT_IGNORE 18*2
#define DEBUG #define DEBUG
#ifdef DEBUG #ifdef DEBUG
...@@ -30,6 +32,8 @@ using namespace std; ...@@ -30,6 +32,8 @@ using namespace std;
cv::Mat matShow1, matShow2, matShow3; cv::Mat matShow1, matShow2, matShow3;
#endif #endif
bool gFirst = true;
class EvMLMotion: public TinyThread { class EvMLMotion: public TinyThread {
private: private:
void *pSubCtx = NULL, *pReqCtx = NULL; // for packets relay void *pSubCtx = NULL, *pReqCtx = NULL; // for packets relay
...@@ -237,7 +241,7 @@ private: ...@@ -237,7 +241,7 @@ private:
return ret; return ret;
} }
int decode_packet(AVPacket *pPacket, AVCodecContext *pCodecContext, AVFrame *pFrame) int decode_packet(bool detect, AVPacket *pPacket, AVCodecContext *pCodecContext, AVFrame *pFrame)
{ {
int response = avcodec_send_packet(pCodecContext, pPacket); int response = avcodec_send_packet(pCodecContext, pPacket);
if (response < 0) { if (response < 0) {
...@@ -269,7 +273,10 @@ private: ...@@ -269,7 +273,10 @@ private:
// save a grayscale frame into a .pgm file // save a grayscale frame into a .pgm file
// string name = urlOut + "/"+ to_string(chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count()) + ".pgm"; // string name = urlOut + "/"+ to_string(chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count()) + ".pgm";
detectMotion(pCodecContext->pix_fmt,pFrame); if(detect) {
detectMotion(pCodecContext->pix_fmt,pFrame);
}
} }
spdlog::debug("ch4"); spdlog::debug("ch4");
} }
...@@ -338,7 +345,7 @@ protected: ...@@ -338,7 +345,7 @@ protected:
bool bStopSig = false; bool bStopSig = false;
int ret = 0; int ret = 0;
int idx = 0; int idx = 0;
int pktCnt = 0; uint64_t pktCnt = 0;
zmq_msg_t msg; zmq_msg_t msg;
AVPacket packet; AVPacket packet;
...@@ -375,11 +382,14 @@ protected: ...@@ -375,11 +382,14 @@ protected:
if (packet.stream_index == streamIdx) { if (packet.stream_index == streamIdx) {
spdlog::debug("AVPacket.pts {}", packet.pts); spdlog::debug("AVPacket.pts {}", packet.pts);
// TODO if(pktCnt < NUM_PKT_IGNORE && gFirst) {
if(pktCnt < 18*5) { ret = decode_packet(false, &packet, pCodecCtx, pFrame);
continue;
} }
ret = decode_packet(&packet, pCodecCtx, pFrame); else {
gFirst = false;
ret = decode_packet(true, &packet, pCodecCtx, pFrame);
}
} }
av_packet_unref(&packet); av_packet_unref(&packet);
...@@ -402,7 +412,7 @@ public: ...@@ -402,7 +412,7 @@ public:
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
spdlog::set_level(spdlog::level::debug); spdlog::set_level(spdlog::level::info);
EvMLMotion es; EvMLMotion es;
#ifdef DEBUG #ifdef DEBUG
...@@ -411,15 +421,17 @@ int main(int argc, const char *argv[]) ...@@ -411,15 +421,17 @@ int main(int argc, const char *argv[])
es.detach(); es.detach();
// TODO: remove me // TODO: remove me
this_thread::sleep_for(chrono::seconds(5));
while(true) { while(true) {
if(gFirst) {
this_thread::sleep_for(chrono::seconds(5));
continue;
}
cv::imshow("evmlmotion1", matShow1); cv::imshow("evmlmotion1", matShow1);
cv::imshow("evmlmotion2", matShow2); cv::imshow("evmlmotion2", matShow2);
cv::imshow("evmlmotion3", matShow3); cv::imshow("evmlmotion3", matShow3);
if(cv::waitKey(200) == 27) { if(cv::waitKey(200) == 27) {
break; break;
} }
} }
#else #else
es.join(); es.join();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论