|
@@ -148,6 +148,7 @@ int ivh264framedecode::GetJpegData(std::shared_ptr<char> & pstr_ptr,int & ndatas
|
|
|
mjpegdata.mmutexdata.lock();
|
|
|
pstr_ptr = mjpegdata.mpstr_ptr;
|
|
|
ndatasize = mjpegdata.ndatasize;
|
|
|
+ mjpegdata.mbupdate = false;
|
|
|
mjpegdata.mmutexdata.unlock();
|
|
|
return 1;
|
|
|
}
|
|
@@ -157,28 +158,25 @@ int ivh264framedecode::GetJpegData(std::shared_ptr<char> & pstr_ptr,int & ndatas
|
|
|
|
|
|
void ivh264framedecode::encodejpeg(AVFrame *frame)
|
|
|
{
|
|
|
- static int nindex = 0;
|
|
|
- int nsample = 3;
|
|
|
-
|
|
|
- if(nindex>nsample)
|
|
|
- {
|
|
|
- nindex = 0;
|
|
|
- }
|
|
|
- nindex++;
|
|
|
- if(nindex != 1)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- av_opt_set(mpCodecCtxJpeg->priv_data, "qscale:v", "95", 0);
|
|
|
-#define DEBUG_ENCODEJPEG
|
|
|
+// if(mnsamplenow>mnsamplecount)
|
|
|
+// {
|
|
|
+// mnsamplenow = 0;
|
|
|
+// }
|
|
|
+// mnsamplenow++;
|
|
|
+// if(mnsamplenow != 1)
|
|
|
+// {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+
|
|
|
+//#define DEBUG_ENCODEJPEG
|
|
|
int ret;
|
|
|
AVCodecContext * enc_ctx = mpCodecCtxJpeg;
|
|
|
AVPacket pkt;
|
|
|
int y_size = enc_ctx->width * enc_ctx->height;
|
|
|
|
|
|
#ifdef DEBUG_ENCODEJPEG
|
|
|
+// std::cout<<"encode jpeg."<<std::endl;
|
|
|
int64_t time1 = std::chrono::system_clock::now().time_since_epoch().count()/1000;
|
|
|
#endif
|
|
|
|
|
@@ -205,6 +203,7 @@ void ivh264framedecode::encodejpeg(AVFrame *frame)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ mnjpegcount++;
|
|
|
std::shared_ptr<char> pstr_data = std::shared_ptr<char>(new char[pkt.size]);
|
|
|
memcpy(pstr_data.get(),pkt.data,pkt.size);
|
|
|
mjpegdata.mmutexdata.lock();
|
|
@@ -229,6 +228,17 @@ void ivh264framedecode::encodejpeg(AVFrame *frame)
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+int ivh264framedecode::Getyuvcount()
|
|
|
+{
|
|
|
+ return mnyuvcount;
|
|
|
+}
|
|
|
+
|
|
|
+int ivh264framedecode::Getjpegcount()
|
|
|
+{
|
|
|
+ return mnjpegcount;
|
|
|
+}
|
|
|
+
|
|
|
void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt)
|
|
|
{
|
|
|
// char buf[1024];
|
|
@@ -257,10 +267,11 @@ void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket
|
|
|
free it */
|
|
|
// snprintf(buf, sizeof(buf), "%s-%d", filename, dec_ctx->frame_number);
|
|
|
|
|
|
+ mnyuvcount++;
|
|
|
|
|
|
if(mbTransJpeg)
|
|
|
{
|
|
|
- // encodejpeg(frame);
|
|
|
+ encodejpeg(frame);
|
|
|
}
|
|
|
// cv::Mat yuvImg;
|
|
|
// cv::Mat rgbImg(cy, cx,CV_8UC3);
|
|
@@ -315,30 +326,30 @@ void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
- if(mbTransJpeg)
|
|
|
- {
|
|
|
- std::vector<int> param = std::vector<int>(2);
|
|
|
- param[0] = CV_IMWRITE_JPEG_QUALITY;
|
|
|
- param[1] = 95; // default(95) 0-100
|
|
|
- std::vector<unsigned char> buff;
|
|
|
-
|
|
|
- cv::Mat mat1;
|
|
|
-
|
|
|
- cv::cvtColor(pbuf->myuvImg,mat1,cv::COLOR_YUV2BGR_I420);
|
|
|
- cv::imencode(".jpg", mat1, buff, param);
|
|
|
-
|
|
|
- std::shared_ptr<char> pstr_data = std::shared_ptr<char>(new char[buff.size()]);
|
|
|
- memcpy(pstr_data.get(),buff.data(),buff.size());
|
|
|
- mjpegdata.mmutexdata.lock();
|
|
|
- mjpegdata.mpstr_ptr = pstr_data;
|
|
|
- mjpegdata.ndatasize =buff.size();
|
|
|
- mjpegdata.mnupdatetime = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
- mjpegdata.mbupdate = true;
|
|
|
- mjpegdata.mmutexdata.unlock();
|
|
|
- mcvjpeg.notify_all();
|
|
|
-
|
|
|
- buff.clear();
|
|
|
- }
|
|
|
+// if(mbTransJpeg)
|
|
|
+// {
|
|
|
+// std::vector<int> param = std::vector<int>(2);
|
|
|
+// param[0] = CV_IMWRITE_JPEG_QUALITY;
|
|
|
+// param[1] = 95; // default(95) 0-100
|
|
|
+// std::vector<unsigned char> buff;
|
|
|
+
|
|
|
+// cv::Mat mat1;
|
|
|
+
|
|
|
+// cv::cvtColor(pbuf->myuvImg,mat1,cv::COLOR_YUV2BGR_I420);
|
|
|
+// cv::imencode(".jpg", mat1, buff, param);
|
|
|
+
|
|
|
+// std::shared_ptr<char> pstr_data = std::shared_ptr<char>(new char[buff.size()]);
|
|
|
+// memcpy(pstr_data.get(),buff.data(),buff.size());
|
|
|
+// mjpegdata.mmutexdata.lock();
|
|
|
+// mjpegdata.mpstr_ptr = pstr_data;
|
|
|
+// mjpegdata.ndatasize =buff.size();
|
|
|
+// mjpegdata.mnupdatetime = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
+// mjpegdata.mbupdate = true;
|
|
|
+// mjpegdata.mmutexdata.unlock();
|
|
|
+// mcvjpeg.notify_all();
|
|
|
+
|
|
|
+// buff.clear();
|
|
|
+// }
|
|
|
UnlockWriteBuff(index);
|
|
|
mcvread.notify_all();
|
|
|
|
|
@@ -457,7 +468,8 @@ void ivh264framedecode::threaddecode()
|
|
|
mpCodecCtxJpeg->width = mframewidth;
|
|
|
mpCodecCtxJpeg->height = mframeheight;
|
|
|
mpCodecCtxJpeg->time_base.num = 1;
|
|
|
- mpCodecCtxJpeg->time_base.den = 25;
|
|
|
+ mpCodecCtxJpeg->time_base.den = 30;
|
|
|
+ mpCodecCtxJpeg->bit_rate = 40000000;
|
|
|
|
|
|
|
|
|
av_opt_set_int(mpCodecCtxJpeg->priv_data, "qscale",1, 0);
|