Browse Source

change h264transjpeg_civetweb, compile on win10.

yuchuli 2 years ago
parent
commit
c7d7b17057

+ 56 - 46
src/driver/driver_h264_dec/ivh264framedecode.cpp

@@ -156,9 +156,60 @@ int ivh264framedecode::GetJpegData(std::shared_ptr<char> & pstr_ptr,int & ndatas
 
 }
 
+void ivh264framedecode::InitJPEGEncode()
+{
+    AVCodec* pCodec;
+    if(mbTransJpeg)
+    {
+ //       pFormatCtx = avformat_alloc_context();   //分配AVFormatCtx
+//        pStream = avformat_new_stream(pFormatCtx, 0);
+//        if (NULL == pStream)
+//        {
+//            std::cout<<" JPEG Create pStream fail."<<std::endl;
+//            return;
+//        }
+
+
+        pCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); //查找编码器
+        if (NULL == pCodec)
+        {
+            printf("can not find  jpeg codec!\n");
+            return;
+        }
+
+        /*设置相关信息*/
+        mpCodecCtxJpeg = avcodec_alloc_context3(pCodec);
+//        mpCodecCtxJpeg = pStream->codec;
+        mpCodecCtxJpeg->codec_id = AV_CODEC_ID_MJPEG;
+        mpCodecCtxJpeg->codec_type = AVMEDIA_TYPE_VIDEO;
+        mpCodecCtxJpeg->pix_fmt = AV_PIX_FMT_YUVJ420P;
+        mpCodecCtxJpeg->width = mframewidth;
+        mpCodecCtxJpeg->height = mframeheight;
+        mpCodecCtxJpeg->time_base.num = 1;
+        mpCodecCtxJpeg->time_base.den = 30;
+        mpCodecCtxJpeg->bit_rate = 40000000;
+
+
+        av_opt_set_int(mpCodecCtxJpeg->priv_data, "qscale",1, 0);
+
+        if (avcodec_open2(mpCodecCtxJpeg, pCodec, NULL) < 0)
+        {
+            printf("con not open jpeg codec!\n");
+            return;
+        }
+    }
+
+
+}
+
 void ivh264framedecode::encodejpeg(AVFrame *frame)
 {
 
+    if(mbInitJpegEncode == false)
+    {
+        InitJPEGEncode();
+        mbInitJpegEncode = true;
+    }
 //    if(mnsamplenow>mnsamplecount)
 //    {
 //        mnsamplenow = 0;
@@ -269,6 +320,11 @@ void ivh264framedecode::decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket
 
         mnyuvcount++;
 
+        if((mframeheight != frame->height)||(mframewidth != frame->width))
+        {
+            mframeheight = frame->height;
+            mframewidth = frame->width;
+        }
         if(mbTransJpeg)
         {
             encodejpeg(frame);
@@ -438,52 +494,6 @@ void ivh264framedecode::threaddecode()
     }
 
 
-//    AVFormatContext* pFormatCtx;
-//    AVStream* pStream;
-    AVCodec* pCodec;
-    if(mbTransJpeg)
-    {
- //       pFormatCtx = avformat_alloc_context();   //分配AVFormatCtx
-//        pStream = avformat_new_stream(pFormatCtx, 0);
-//        if (NULL == pStream)
-//        {
-//            std::cout<<" JPEG Create pStream fail."<<std::endl;
-//            return;
-//        }
-
-
-        pCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG); //查找编码器
-        if (NULL == pCodec)
-        {
-            printf("can not find  jpeg codec!\n");
-            return;
-        }
-
-        /*设置相关信息*/
-        mpCodecCtxJpeg = avcodec_alloc_context3(pCodec);
-//        mpCodecCtxJpeg = pStream->codec;
-        mpCodecCtxJpeg->codec_id = AV_CODEC_ID_MJPEG;
-        mpCodecCtxJpeg->codec_type = AVMEDIA_TYPE_VIDEO;
-        mpCodecCtxJpeg->pix_fmt = AV_PIX_FMT_YUVJ420P;
-        mpCodecCtxJpeg->width = mframewidth;
-        mpCodecCtxJpeg->height = mframeheight;
-        mpCodecCtxJpeg->time_base.num = 1;
-        mpCodecCtxJpeg->time_base.den = 30;
-        mpCodecCtxJpeg->bit_rate = 40000000;
-
-
-        av_opt_set_int(mpCodecCtxJpeg->priv_data, "qscale",1, 0);
-
-        if (avcodec_open2(mpCodecCtxJpeg, pCodec, NULL) < 0)
-        {
-            printf("con not open jpeg codec!\n");
-            return;
-        }
-    }
-
-
-//    char * strbuff = new char[10000000];
-//    int ndatasize = 0;
     while (mbthreadrun) {
 
         iv::rawframedata xraw;

+ 4 - 0
src/driver/driver_h264_dec/ivh264framedecode.h

@@ -90,6 +90,8 @@ private:
     iv::framedecodebuf * LockWriteBuff(int nbufindex);
     void UnlockWriteBuff(int nbufindex);
 
+    void InitJPEGEncode();
+
 private:
     void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt);
     void encodejpeg(AVFrame * frame);
@@ -131,6 +133,8 @@ private:
     int mnsamplenow = 1;
     int mnsamplecount = 3;
 
+    bool mbInitJpegEncode = false;
+
 public:
     //if GetData return 1, else return 0
     int GetJpegData(std::shared_ptr<char> & pstr_ptr,int & ndatasize, int nwaitms = 0);

+ 7 - 2
src/tool/h264transjpeg_civetweb/h264transjpeg_civetweb.pro

@@ -55,10 +55,15 @@ DEFINES += USE_WEBSOCKET
 INCLUDEPATH += $$PWD/../../driver/driver_h264_dec
 INCLUDEPATH += $$PWD/../RemoteCtrl_h264
 
-LIBS += -ldl -lrt
+INCLUDEPATH +=  D:\ffmpegwin\include
+
+unix:LIBS += -ldl -lrt
 
 INCLUDEPATH += /usr/include/x86_64-linux-gnu
-LIBS +=  -lavcodec -lavformat -lavutil
+unix:LIBS +=  -lavcodec -lavformat -lavutil
+win32:LIBS += -LD:\ffmpegwin\bin
+win32:LIBS += -lavcodec-58 -lavformat-58 -lavutil-56  -lwsock32 -lws2_32
+
 
 
 DEFINES += USEJPEG_NOOPENCV