Explorar el Código

change RemoteCtrl.

yuchuli hace 2 años
padre
commit
aff273204c

+ 75 - 5
src/tool/RemoteCtrl_Wide/mainwindowcenter.cpp

@@ -1128,13 +1128,18 @@ void MainWindow::threadframe(int ncamppos)
     AVOutputFormat *ofmt = NULL;
     //创建输入AVFormatContext对象和输出AVFormatContext对象
     AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
-    AVPacket pkt;
+    AVPacket * pkt;
     const char *in_filename;
     int ret, i;
     int stream_index = 0;
     int *stream_mapping = NULL;
     int stream_mapping_size = 0;
 
+    int64_t calc_duration=(double)AV_TIME_BASE/30;
+
+    int64_t pos = 0;
+
+    int64_t frame_index = 1;
 
     while(mbThreadrun)
     {
@@ -1154,7 +1159,8 @@ void MainWindow::threadframe(int ncamppos)
                 bSave = mbSave[ncamppos];
                 if(bSave)
                 {
-                    QString strpath = "./" + QString::number(QDateTime::currentMSecsSinceEpoch())+ "-"+QString::number(ncamppos)+".mp4";
+
+                    QString strpath = "./" + QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss-zzz")+ "-"+QString::number(ncamppos)+".mp4";
                     //输出文件分配空间
                     avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, strpath.toLatin1().data());
                     if (!ofmt_ctx) {
@@ -1165,13 +1171,22 @@ void MainWindow::threadframe(int ncamppos)
                     {
                         AVStream *outStream = avformat_new_stream(ofmt_ctx, NULL);
 
+                        AVCodecContext * c;
+                        c = outStream->codec;
+                        c->bit_rate = 4000000;
+                        c->codec_id = AV_CODEC_ID_H264;
+                        c->codec_type = AVMEDIA_TYPE_VIDEO;
+                        c->width = mnframewidth;
+                        c->height = mnframeheight;
+  //                      c->pix_fmt = 1;
 
-                            outStream->codecpar->codec_id   = AV_CODEC_ID_H264;
+
+                        outStream->codecpar->codec_id   = AV_CODEC_ID_H264;
 
                         outStream->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
                         outStream->codecpar->width      = mnframewidth;
                         outStream->codecpar->height     = mnframeheight;
-                        outStream->id                   = 0;
+                        outStream->id                   = 1;
 
                         ofmt = ofmt_ctx->oformat;
 
@@ -1183,6 +1198,10 @@ void MainWindow::threadframe(int ncamppos)
                                 std::cout<<" open recode fail."<<std::endl;
                             }
                         }
+
+
+ //                       avcodec_parameters_to_context(ofmt_ctx->, outStream->codecpar);
+
                         //开始写入文件头
                         ret = avformat_write_header(ofmt_ctx, NULL);
                         if (ret < 0) {
@@ -1190,12 +1209,18 @@ void MainWindow::threadframe(int ncamppos)
                             std::cout<<"write header fail."<<std::endl;
                         }
 
+                        pos = 0;
+                        frame_index = 1;
+                        bSaving = true;
+
                     }
                 }
                 else
                 {
                     if(bSaving)
                     {
+                        av_write_trailer(ofmt_ctx);
+                        bSaving = false;
 //                        xFile.close();
 //                        bSaving = false;
                     }
@@ -1203,7 +1228,52 @@ void MainWindow::threadframe(int ncamppos)
             }
             if(bSaving)
             {
-                xFile.write(xrawframe.mpstr_ptr.get(),xrawframe.ndatasize);
+
+
+
+                bool bStart = true;
+
+
+                if(frame_index == 1)
+                {
+                    bStart = false;
+                    char * strdata = xrawframe.mpstr_ptr.get();
+                    char strheader[5];
+                    memcpy(strheader,strdata,5);
+                    if(strheader[4] == 0x67)bStart = true;
+                }
+
+                if(bStart)
+                {
+                pkt = av_packet_alloc();
+                pkt->data = (uint8_t *)xrawframe.mpstr_ptr.get();
+                pkt->size = xrawframe.ndatasize;
+
+                pkt->buf = NULL;
+                pkt->duration = 0;
+                pkt->stream_index = 0;
+                pkt->side_data = 0;
+                pkt->side_data_elems = 0;
+                pkt->pos = pos;
+                pkt->pts = AV_NOPTS_VALUE;
+                pkt->dts = AV_NOPTS_VALUE;
+                pos = pos + xrawframe.ndatasize;
+                pkt->flags = 0;
+                pkt->duration = 3*1000;
+                if (pkt->pts == AV_NOPTS_VALUE) {
+                    pkt->dts = pkt->pts = 1000* (1.0/30)*90*frame_index;
+                }
+                frame_index++;
+
+                int ret = av_interleaved_write_frame(ofmt_ctx, pkt);
+                    if (ret < 0) {
+                        std::cout<<"write fail."<<std::endl;
+                    }
+                    av_packet_unref(pkt);
+
+                }
+
+
             }
         }
     }

+ 6 - 0
src/tool/tool_ntripbroadcast/mainwindow.h

@@ -53,6 +53,12 @@ private:
     QString mstrusername = "chinaauto";
     QString mstrpassword = "chinaauto@test";
 
+//    QString mstrserverip = "223.84.137.240";
+//    QString mstrserverport = "19696";
+//    QString mstrservermountpoint = "RTCM32";
+//    QString mstrusername = "srsyc";
+//    QString mstrpassword = "srsyc";
+
     double mfLat = 39.1207274;
     double mfLon = 117.0280033;