#include #include #include #include extern "C" { #include #include #include #include } #ifdef USE_OPENCV4 #include "opencv2/imgcodecs/legacy/constants_c.h" //OpenCV4 use this line #include //OpenCV4 use this line #endif #include #include #include #define TESTYUV 0 #include "modulecomm.h" #include "rawpic.pb.h" #include "xmlparam.h" #include "ivversion.h" void * gpa; int gindex = 0; int gwidth = 1920; int gheight = 1080; int gcamindex = 0; int gcompress = 1; int gcompquality = 95; std::string gmsgname = "image00"; std::string gstrdevname = "video0"; std::string video_path = "/home/nvidia/Videos/video.mp4"; int time_sleep = 0; #ifndef CV_CAP_PROP_FRAME_WIDTH #define CV_CAP_PROP_FRAME_WIDTH cv::CAP_PROP_FRAME_WIDTH #define CV_CAP_PROP_FRAME_HEIGHT cv::CAP_PROP_FRAME_HEIGHT #define CV_CAP_PROP_FPS CAP_PROP_FPS #define CV_CAP_PROP_FOURCC CAP_PROP_FOURCC #define CV_BGR2GRAY cv::COLOR_BGR2GRAY #endif static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile) { int ret; /* send the frame to the encoder */ if (frame) printf("Send frame %3"PRId64"\n", frame->pts); ret = avcodec_send_frame(enc_ctx, frame); if (ret < 0) { fprintf(stderr, "Error sending a frame for encoding\n"); exit(1); } while (ret >= 0) { ret = avcodec_receive_packet(enc_ctx, pkt); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) return; else if (ret < 0) { fprintf(stderr, "Error during encoding\n"); exit(1); } printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size); fwrite(pkt->data, 1, pkt->size, outfile); av_packet_unref(pkt); } } void VideoThread(int n) { QTime xT; xT.start(); int ncount = 0; int nserbufsize = 20000000; char * strser = new char[nserbufsize]; cv::VideoCapture capture; #ifdef TESTYUV QFile xFileYUV; xFileYUV.setFileName("/home/nvidia/testYUV.yuv"); bool bTestYUV = false; if(xFileYUV.open(QIODevice::ReadWrite)) { bTestYUV = true; } else { std::cout<<" Open YUV File Fail."< 2) // { // //gstr_f = "v4l2src device=/dev/"+gstrcamera+" ! video/x-raw, width=(int)"+std::to_string(gwidth)+", height=(int)"+std::to_string(gheight)+" ! videoconvert ! appsink"; // gstr_f = "/home/nvidia/Videos/video.mp4"; // std::cout<>mat; cv::resize(mat, mat1, cv::Size(1280, 720), 0, 0, cv::INTER_LINEAR); cv::imshow("video_replay",mat1); if(!mat1.empty()) { #ifdef TESTYUV if(bTestYUV &&(ncount<61)) { cv::Mat dstYuvImage; QTime xTime; xTime.start(); cv::cvtColor(mat1, dstYuvImage, CV_BGR2YUV_I420); std::cout<<" cvt time: "< param = std::vector(2); param[0] = CV_IMWRITE_JPEG_QUALITY; param[1] = gcompquality; // default(95) 0-100 std::vector buff; if(gcompress == 1) { cv::imencode(".jpg", mat1, buff, param); // cv::imencode(".jpg", matcompress, buff, param); pic.set_picdata(buff.data(),buff.size()); buff.clear(); pic.set_type(2); } else { pic.set_picdata(mat1.data,mat1.rows*mat1.cols*mat1.elemSize()); // pic.set_picdata(matcompress.data,matcompress.rows*matcompress.cols*matcompress.elemSize()); pic.set_type(1); } // qDebug("buff size is %d",buff.size()); int nSize = pic.ByteSize(); // char * strser = new char[nSize]; bool bser = pic.SerializeToArray(strser,nSize); qDebug("time is %ld pac time is %d size is %d",QDateTime::currentMSecsSinceEpoch(),xg.elapsed(),nSize); // iv::modulecomm::ModuleSendMsg(gpa,str.data(),str.length()); if(bser)iv::modulecomm::ModuleSendMsg(gpa,strser,nSize); else { std::cout<<"usbcamera "<< "serialize error. "<mMutex.lock(); // mat1.copyTo(gw->msrcImage); // gw->mMutex.unlock(); // gMutexInput.lock(); // mat1.copyTo(gsrcImage); // g_CapIndex++; // gMutexInput.unlock(); } else { qDebug("no data."); std::this_thread::sleep_for(std::chrono::milliseconds(1)); } std::this_thread::sleep_for(std::chrono::milliseconds(time_sleep)); } } #include void testthread() { void * mpx = iv::modulecomm::RegisterSend("test121",10000000,1); char * str = new char[10000000]; while(1) { iv::modulecomm::ModuleSendMsg(mpx,str,9000000); } } int main(int argc, char *argv[]) { cv::namedWindow("video_replay",cv::WINDOW_NORMAL); showversion("video_replay"); QCoreApplication a(argc, argv); // std::thread * pthread = new std::thread(testthread); // return a.exec(); QString strpath = QCoreApplication::applicationDirPath(); // QString apppath = strpath; if(argc < 2) strpath = strpath + "/video_replay.xml"; else strpath = argv[1]; std::cout<