Browse Source

change h264_enc. fix resolation problem.

yuchuli 6 tháng trước cách đây
mục cha
commit
06fd137f73

+ 9 - 0
src/driver/driver_h264_enc/driver_h264_enc.xml

@@ -0,0 +1,9 @@
+<xml>	
+	<node name="driver_camera_ioctl">
+		<param name="picname" value="picfront" />
+		<param name="h264name" value="h264front" />
+		<param name="width" value = "1920" />
+		<param name="height" value="1080" />
+		<param name="framerate" value="4000000" />
+	</node>
+</xml>

+ 29 - 10
src/driver/driver_h264_enc/main.cpp

@@ -24,6 +24,7 @@ extern "C"
 #include <thread>
 
 #include "modulecomm.h"
+#include "xmlparam.h"
 
 #include <opencv2/opencv.hpp>
 #include <opencv2/core.hpp>
@@ -57,6 +58,7 @@ int gnoutsize = 0;
 static char * gstrwidth ="1280";
 static char * gstrheight = "720";
 int gnwidth,gnheight;
+int gnframerate = 4000000;
 
 void * gpaout;
 
@@ -103,8 +105,8 @@ static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
         std::cout<<"time: "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
         printf("Write packet %3"PRId64" (size=%5d)\n", pkt->pts, pkt->size);
         iv::modulecomm::ModuleSendMsg(gpaout,(char *)pkt->data,pkt->size);
-        gFile.write((char *)pkt->data,pkt->size);
-        gFile.flush();
+//        gFile.write((char *)pkt->data,pkt->size);
+//        gFile.flush();
 //        fwrite(pkt->data, 1, pkt->size, outfile);
         av_packet_unref(pkt);
     }
@@ -182,10 +184,10 @@ void ThreadEnc()
 
 
          /* put sample parameters */
-         c->bit_rate = 4000000;
+         c->bit_rate = gnframerate;
          /* resolution must be a multiple of two */
-         c->width = 1280;
-         c->height = 720;
+         c->width = gnwidth;
+         c->height = gnheight;
          /* frames per second */
 
          c->time_base = (AVRational){1, 30};
@@ -271,7 +273,7 @@ void ThreadEnc()
             if (ret < 0)
                 exit(1);
 
-            yuvI420ToNV12(strbuf,1280,720,strbufnv12);
+            yuvI420ToNV12(strbuf,gnwidth,gnheight,strbufnv12);
             memcpy(frame->data[0],strbufnv12,gnwidth*gnheight);
             memcpy(frame->data[1],strbufnv12 + gnwidth*gnheight,gnwidth*gnheight*1/2);
 //            memcpy(frame->data[2],strbuf+gnwidth*gnheight+gnwidth*gnheight/4,gnwidth*gnheight/4);
@@ -343,16 +345,33 @@ int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
+    QString strpath = QCoreApplication::applicationDirPath();
+//    QString apppath = strpath;
+    if(argc < 2)
+        strpath = strpath + "/driver_h264_enc.xml";
+    else
+        strpath = argv[1];
+    std::cout<<strpath.toStdString()<<std::endl;
+
     gFile.setFileName("/home/yuchuli/test1.mp4");
     gFile.open(QIODevice::ReadWrite);
 
+    iv::xmlparam::Xmlparam xp(strpath.toStdString());
+
+    std::string strpicname = xp.GetParam("picname",std::string("image00"));
+    std::string strh264name = xp.GetParam("h264name",std::string("h264front"));
+
+    std::string strwidth = xp.GetParam("width",std::string("1920"));
+    std::string strheight = xp.GetParam("height",std::string("1080"));
+    gnframerate = xp.GetParam("framerate",4000000);
+
     gstrbuffer = new char[30000000];
     gstrout = new char[10000000];
-    gnwidth = atoi(gstrwidth);
-    gnheight = atoi(gstrheight);
+    gnwidth = atoi(strwidth.data());
+    gnheight = atoi(strheight.data());
 
-    void * pa = iv::modulecomm::RegisterRecv("picfront",Listenpic);
-    gpaout = iv::modulecomm::RegisterSend("h264front",1000000,1);
+    void * pa = iv::modulecomm::RegisterRecv(strpicname.data(),Listenpic);
+    gpaout = iv::modulecomm::RegisterSend(strh264name.data(),1000000,1);
     std::thread * pthreadenc = new std::thread(ThreadEnc);
     return a.exec();
 }

+ 1 - 1
src/tool/picview_usbport/picview_usbport.pro

@@ -8,7 +8,7 @@ QT       += core gui
 
 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
-TARGET = picview
+TARGET = picview_usbport
 TEMPLATE = app
 
 CONFIG += c++17