Jelajahi Sumber

code h264 code.

yuchuli 3 tahun lalu
induk
melakukan
ea4903a9eb

+ 13 - 0
src/common/common/nvenc/classes/NvV4l2ElementPlane.cpp

@@ -113,17 +113,25 @@ NvV4l2ElementPlane::getNthBuffer(uint32_t n)
     return buffers[n];
 }
 
+#include <chrono>
+
 int
 NvV4l2ElementPlane::dqBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer ** buffer,
         NvBuffer ** shared_buffer, uint32_t num_retries)
 {
     int ret;
 
+//    std::cout<<"enter dq "<<std::endl;
     v4l2_buf.type = buf_type;
     v4l2_buf.memory = memory_type;
     do
     {
+//        std::cout<<"dqBuffer "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
         ret = v4l2_ioctl(fd, VIDIOC_DQBUF, &v4l2_buf);
+//        std::cout<<"ret "<<ret<<std::endl;
+
+//        std::cout<<"dqBuffer1 "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
 
         if (ret == 0)
         {
@@ -146,11 +154,16 @@ NvV4l2ElementPlane::dqBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer ** buffer,
                 v4l2elem_profiler.finishProcessing(0, false);
             }
 
+//            std::cout<<"dqBuffer2 "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
+
             total_dequeued_buffers++;
             num_queued_buffers--;
             pthread_cond_broadcast(&plane_cond);
             PLANE_DEBUG_MSG("DQed buffer " << v4l2_buf.index);
             pthread_mutex_unlock(&plane_lock);
+//            std::cout<<"dqBuffer3 "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
         }
         else if (errno == EAGAIN)
         {

+ 2 - 0
src/driver/driver_camera_usb/driver_camera_usb.pro

@@ -43,4 +43,6 @@ contains(QMAKE_HOST.arch, aarch64){
 HEADERS += \
     ../../include/msgtype/rawpic.pb.h
 
+LIBS += -lavcodec -lavformat -lavutil
+
 

+ 43 - 0
src/driver/driver_camera_usb/main.cpp

@@ -4,6 +4,14 @@
 #include <opencv2/opencv.hpp>
 #include <opencv2/core.hpp>
 
+extern "C"
+{
+#include <libavcodec/avcodec.h>
+#include <libavutil/opt.h>
+#include <libavutil/imgutils.h>
+#include <libavutil/common.h>
+}
+
 #ifdef USE_OPENCV4
 #include "opencv2/imgcodecs/legacy/constants_c.h"   //OpenCV4 use this line
 #include <opencv2/imgproc/types_c.h>   //OpenCV4 use this line
@@ -46,8 +54,43 @@ std::string gstrdevname = "video0";
 #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;

+ 73 - 0
src/driver/driver_h264_enc/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 40 - 0
src/driver/driver_h264_enc/driver_h264_enc.pro

@@ -0,0 +1,40 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+
+!include(../../../include/ivboost.pri ) {
+    error( "Couldn't find the ivboost.pri file!" )
+}
+
+!include(../../../include/ivopencv.pri ) {
+    error( "Couldn't find the ivopencv.pri file!" )
+}
+
+
+SOURCES += main.cpp \
+    ../../include/msgtype/rawpic.pb.cc
+
+LIBS += -lavcodec -lavformat -lavutil
+
+HEADERS += \
+    ../../include/msgtype/rawpic.pb.h

+ 247 - 0
src/driver/driver_h264_enc/main.cpp

@@ -0,0 +1,247 @@
+#include <QCoreApplication>
+
+extern "C"
+{
+#include <libavcodec/avcodec.h>
+#include <libavutil/opt.h>
+#include <libavutil/imgutils.h>
+#include <libavutil/common.h>
+}
+
+#include <iostream>
+#include <thread>
+
+#include "modulecomm.h"
+
+#include <opencv2/opencv.hpp>
+#include <opencv2/core.hpp>
+
+#include <opencv2/imgproc.hpp>
+
+//#include "opencv2/imgcodecs/legacy/constants_c.h"
+#include <opencv2/imgproc/types_c.h>
+
+#include "rawpic.pb.h"
+
+bool gbNewData = false;
+#include <QWaitCondition>
+#include <QMutex>
+
+QWaitCondition gwc;
+static QMutex gWaitMutex;
+static int gndatasize = 0;
+
+char * gstrbuffer;
+QMutex gMutexLock;
+
+bool gbNewOut = false;
+QWaitCondition gwcout;
+char * gstrout;
+QMutex gWaitMutexout;
+QMutex gMutexout;
+int gnoutsize = 0;
+
+static char * gstrwidth ="1920";
+static char * gstrheight = "1080";
+int gnwidth,gnheight;
+
+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 ThreadEnc()
+{
+    AVCodec *codec;
+    AVCodecContext *c= NULL;
+    AVFrame * frame;
+    AVPacket * pkt;
+
+    char * strbuf = new char[30000000];
+
+    avcodec_register_all();
+     codec = avcodec_find_encoder(AV_CODEC_ID_H264);// avcodec_find_encoder_by_name("h264");
+
+     if(codec == NULL)
+     {
+         std::cout<<" codec NULL"<<std::endl;
+         int a = 1;
+         a++;
+     }
+     else
+     {
+         std::cout<<"codec ok."<<std::endl;
+     }
+
+     c = avcodec_alloc_context3(codec);
+
+     if(c == NULL)std::cout<<"c NULL ."<<std::endl;
+     pkt = av_packet_alloc();
+         if (!pkt)
+             exit(1);
+
+         /* put sample parameters */
+         c->bit_rate = 4000000;
+         /* resolution must be a multiple of two */
+         c->width = 1920;
+         c->height = 1080;
+         /* frames per second */
+
+         c->time_base = (AVRational){1, 30};
+         c->framerate = (AVRational){30, 1};
+
+         /* emit one intra frame every ten frames
+          * check frame pict_type before passing frame
+          * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
+          * then gop_size is ignored and the output of encoder
+          * will always be I frame irrespective to gop_size
+          */
+         c->gop_size = 10;
+         c->max_b_frames = 1;
+         c->pix_fmt = AV_PIX_FMT_YUV420P;
+
+         if (codec->id == AV_CODEC_ID_H264)
+              av_opt_set(c->priv_data, "preset", "slow", 0);
+
+          /* open it */
+          int ret = avcodec_open2(c, codec, NULL);
+          if (ret < 0) {
+              std::cout<<"Could not open codec: "<<std::endl;
+ //             fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
+              exit(1);
+          }
+
+          frame = av_frame_alloc();
+              if (!frame) {
+                  fprintf(stderr, "Could not allocate video frame\n");
+                  exit(1);
+              }
+              frame->format = c->pix_fmt;
+              frame->width  = c->width;
+              frame->height = c->height;
+
+              ret = av_frame_get_buffer(frame, 0);
+              if (ret < 0) {
+                  fprintf(stderr, "Could not allocate the video frame data\n");
+                  exit(1);
+              }
+
+    std::cout<<"start enc."<<std::endl;
+
+    int i = 0;
+    while(1)
+    {
+        if(gbNewData == false)
+        {
+            gWaitMutex.lock();
+            gwc.wait(&gWaitMutex,10);
+            gWaitMutex.unlock();
+        }
+        else
+        {
+            gMutexLock.lock();
+            memcpy(strbuf,gstrbuffer,gnwidth*gnheight*3/2);
+            gbNewData = false;
+            gMutexLock.unlock();
+            ret = av_frame_make_writable(frame);
+            if (ret < 0)
+                exit(1);
+
+            memcpy(frame->data[0],strbuf,gnwidth*gnheight);
+            memcpy(frame->data[1],strbuf + gnwidth*gnheight,gnwidth*gnheight/4);
+            memcpy(frame->data[2],strbuf+gnwidth*gnheight+gnwidth*gnheight/4,gnwidth*gnheight/4);
+
+            frame->pts = i;i++;
+
+            /* encode the image */
+            QTime xTime;
+            xTime.start();
+            encode(c, frame, pkt, NULL);
+            std::cout<<"encode time : "<<xTime.elapsed()<<std::endl;
+
+        }
+    }
+
+}
+
+
+void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    if(nSize<1000)return;
+    iv::vision::rawpic pic;
+    std::cout<<"rec. "<<std::endl;
+    if(false == pic.ParseFromArray(strdata,nSize))
+    {
+        std::cout<<"picview Listenpic fail."<<std::endl;
+        return;
+    }
+
+    cv::Mat mat(pic.height(),pic.width(),pic.mattype());
+
+    if(pic.type() == 1)
+        memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
+    else
+    {
+
+ //       qDebug("jpg");
+        std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data()+pic.picdata().size());
+        mat = cv::imdecode(buff,1);
+    }
+
+    cv::Mat dstYuvImage;
+    QTime xTime;
+    xTime.start();
+    cv::cvtColor(mat, dstYuvImage, CV_BGR2YUV_I420);
+    std::cout<<" cvt time: "<<xTime.elapsed()<<std::endl;
+    gMutexLock.lock();
+    memcpy(gstrbuffer,(char *)dstYuvImage.data,gnwidth*gnheight*3/2);
+    gbNewData = true;
+    gMutexLock.unlock();
+    gwc.wakeAll();
+//    xFileYUV.write((char *)dstYuvImage.data,gwidth*gheight*3/2);
+
+}
+
+
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    gstrbuffer = new char[30000000];
+    gstrout = new char[10000000];
+    gnwidth = atoi(gstrwidth);
+    gnheight = atoi(gstrheight);
+
+    void * pa = iv::modulecomm::RegisterRecv("picfront",Listenpic);
+    std::thread * pthreadenc = new std::thread(ThreadEnc);
+    return a.exec();
+}

+ 69 - 5
src/driver/driver_h264_nvdec/main.cpp

@@ -1,8 +1,72 @@
 #include <QCoreApplication>
 
-//int main(int argc, char *argv[])
-//{
-//    QCoreApplication a(argc, argv);
+#include "modulecomm.h"
 
-//    return a.exec();
-//}
+extern bool gbNewData ;
+#include <QWaitCondition>
+#include <QMutex>
+
+extern QWaitCondition gwc;
+extern QMutex gWaitMutex;
+extern int gndatasize;
+
+extern char * gstrbuffer;
+extern QMutex gMutexLock;
+
+extern bool gbNewOut ;
+extern QWaitCondition gwcout;
+extern char * gstrout;
+extern QMutex gWaitMutexout;
+extern QMutex gMutexout;
+extern int gnoutsize ;
+
+extern void StartDecode();
+
+#include <iostream>
+
+void ListenFrame(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    static bool bStart = false;
+    if(nSize < 6)return;
+
+    if(bStart == false)
+    {
+        if(strdata[4] == 0x67)
+        {
+            std::cout<<" SPS Size "<<nSize<<std::endl;
+            bStart = true;
+        }
+    }
+//    if(bStart == false)
+//    {
+//        return;
+//    }
+    gMutexLock.lock();
+    memcpy(gstrbuffer,strdata,nSize);
+    gndatasize = nSize;
+    gbNewData = true;
+    gMutexLock.unlock();
+    gwc.wakeAll();
+
+
+
+    char strout[1000];
+    memcpy(strout,strdata,100);
+    char strprint[1000];
+    sprintf(strprint,"%02x %02x %02x %02x %02x %02x %02x %02x",strout[0],strout[1],
+            strout[2],strout[3],strout[4],strout[5],strout[6],strout[7]);
+    std::cout<<strprint<<std::endl;
+
+}
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    gstrbuffer = new char[1000000];
+    gstrout = new char[30000000];
+    iv::modulecomm::RegisterRecv("h264frame",ListenFrame);
+    StartDecode();
+    return a.exec();
+}

+ 112 - 38
src/driver/driver_h264_nvdec/video_decode_main.cpp

@@ -76,6 +76,43 @@
 
 using namespace std;
 
+
+bool gbNewData = false;
+#include <QWaitCondition>
+#include <QMutex>
+
+QWaitCondition gwc;
+QMutex gWaitMutex;
+int gndatasize = 0;
+
+char * gstrbuffer;
+QMutex gMutexLock;
+
+bool gbNewOut = false;
+QWaitCondition gwcout;
+char * gstrout;
+QMutex gWaitMutexout;
+QMutex gMutexout;
+int gnoutsize = 0;
+
+
+
+void read_grpc_frame(NvBuffer * buffer)
+{
+    while(gbNewData == false)
+    {
+        gWaitMutex.lock();
+        gwc.wait(&gWaitMutex,10);
+        gWaitMutex.unlock();
+    }
+    std::cout<<"grpc data. "<<std::endl;
+    gMutexLock.lock();
+    memcpy((char *) buffer->planes[0].data,gstrbuffer,gndatasize);
+    buffer->planes[0].bytesused = gndatasize;
+    gbNewData = false;
+    gMutexLock.unlock();
+}
+
 /**
   * Read the input NAL unit for h264/H265/Mpeg2/Mpeg4 decoder.
   *
@@ -185,13 +222,17 @@ read_decoder_input_nalu(ifstream * stream, NvBuffer * buffer,
 static int
 read_decoder_input_chunk(ifstream * stream, NvBuffer * buffer)
 {
+    read_grpc_frame(buffer);
+    return 0;
     /* Length is the size of the buffer in bytes */
     streamsize bytes_to_read = MIN(CHUNK_SIZE, buffer->planes[0].length);
 
     stream->read((char *) buffer->planes[0].data, bytes_to_read);
+    std::cout<<"read chunk size: "<<bytes_to_read<<std::endl;
     /* NOTE: It is necessary to set bytesused properly, so that decoder knows how
              many bytes in the buffer are valid. */
-    buffer->planes[0].bytesused = stream->gcount();
+    buffer->planes[0].bytesused = stream->gcount();\
+    std::cout<<"read: "<<buffer->planes[0].bytesused<<std::endl;
     if(buffer->planes[0].bytesused == 0)
     {
         stream->clear();
@@ -927,6 +968,7 @@ static void *decoder_pollthread_fcn(void *arg)
     return NULL;
 }
 
+#include <chrono>
 /**
   * Decoder capture thread loop function.
   *
@@ -991,6 +1033,8 @@ dec_capture_loop_fcn(void *arg)
         /* Decoder capture loop */
         while (1)
         {
+//            std::cout<<"start "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
             struct v4l2_buffer v4l2_buf;
             struct v4l2_plane planes[MAX_PLANES];
 
@@ -1103,7 +1147,11 @@ dec_capture_loop_fcn(void *arg)
                 if(ctx->capture_plane_mem_type == V4L2_MEMORY_DMABUF)
                     dec_buffer->planes[0].fd = ctx->dmabuff_fd[v4l2_buf.index];
                 /* Perform Blocklinear to PitchLinear conversion. */
+//                std::cout<<"before "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
                 ret = NvBufferTransform(dec_buffer->planes[0].fd, ctx->dst_dma_fd, &transform_params);
+ //               std::cout<<"after "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
                 if (ret == -1)
                 {
                     cerr << "Transform failed" << endl;
@@ -1122,10 +1170,20 @@ dec_capture_loop_fcn(void *arg)
                     }
                 }
 
+                static int a = 1;
+                if(a > -1)
+                {
                 if (!ctx->stats && !ctx->disable_rendering)
                 {
                     ctx->renderer->render(ctx->dst_dma_fd);
                 }
+                a = 0;
+                }
+
+                a++;
+
+//                std::cout<<"after2 "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<<std::endl;
+
 
                 /* If not writing to file, Queue the buffer back once it has been used. */
                 if(ctx->capture_plane_mem_type == V4L2_MEMORY_DMABUF)
@@ -1551,6 +1609,7 @@ check_capture_buffers:
     return eos;
 }
 
+#include <chrono>
 /**
   * Decode processing function for blocking mode.
   *
@@ -1586,7 +1645,10 @@ static bool decoder_proc_blocking(context_t &ctx, bool eos, uint32_t current_fil
         /* dequeue a buffer for output plane. */
         if(allow_DQ)
         {
+            std::cout<<"dq "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<< std::endl;
             ret = ctx.dec->output_plane.dqBuffer(v4l2_buf, &buffer, NULL, -1);
+            std::cout<<"out dq "<<std::chrono::system_clock::now().time_since_epoch().count()/1000000<< std::endl;
+
             if (ret < 0)
             {
                 cerr << "Error DQing buffer at output plane" << endl;
@@ -2139,48 +2201,60 @@ cleanup:
     return -error;
 }
 
-/**
-  * Start of video Decode application.
-  *
-  * @param argc : Argument Count
-  * @param argv : Argument Vector
-  */
-int
-main(int argc, char *argv[])
+
+void StartDecode()
 {
-    /* create decoder context. */
     context_t ctx;
-    int ret = 0;
-    /* save decode iterator number */
-    int iterator_num = 0;
-
     int targc = 3;
     char * targv[3];
     targv[0] = "videoc_encode";
     targv[1] = "H264";
     targv[2] = "/home/nvidia/testh264.mp4";
-//    targv[2] = strwidth;
-//    targv[3] = strheight;
-
-//    targv[5] = "/home/nvidia/testh264.mp4";
-
-    do
-    {
-        /* Invoke video decode function. */
-        ret = decode_proc(ctx,targc,targv);
- //       ret = decode_proc(ctx, argc, argv);
-        iterator_num++;
-    } while((ctx.stress_test != iterator_num) && ret == 0);
-
-    /* Report application run status on exit. */
-    if (ret)
-    {
-        cout << "App run failed" << endl;
-    }
-    else
-    {
-        cout << "App run was successful" << endl;
-    }
-
-    return ret;
+    int ret = decode_proc(ctx,targc,targv);
 }
+
+/**
+  * Start of video Decode application.
+  *
+  * @param argc : Argument Count
+  * @param argv : Argument Vector
+  */
+//int
+//main(int argc, char *argv[])
+//{
+//    /* create decoder context. */
+//    context_t ctx;
+//    int ret = 0;
+//    /* save decode iterator number */
+//    int iterator_num = 0;
+
+//    int targc = 3;
+//    char * targv[3];
+//    targv[0] = "videoc_encode";
+//    targv[1] = "H264";
+//    targv[2] = "/home/nvidia/testh264.mp4";
+////    targv[2] = strwidth;
+////    targv[3] = strheight;
+
+////    targv[5] = "/home/nvidia/testh264.mp4";
+
+//    do
+//    {
+//        /* Invoke video decode function. */
+//        ret = decode_proc(ctx,targc,targv);
+// //       ret = decode_proc(ctx, argc, argv);
+//        iterator_num++;
+//    } while((ctx.stress_test != iterator_num) && ret == 0);
+
+//    /* Report application run status on exit. */
+//    if (ret)
+//    {
+//        cout << "App run failed" << endl;
+//    }
+//    else
+//    {
+//        cout << "App run was successful" << endl;
+//    }
+
+//    return ret;
+//}

+ 5 - 2
src/driver/driver_h264_nvenc/video_encode_main.cpp

@@ -301,10 +301,13 @@ encoder_capture_plane_dq_callback(struct v4l2_buffer *v4l2_buf, NvBuffer * buffe
     if(ctx->pBitStreamCrc)
         CalculateCrc (ctx->pBitStreamCrc, buffer->planes[0].data, buffer->planes[0].bytesused);
 
+    static int a1 = 0;
     if (!ctx->stats)
     {
         std::cout<<" out a buffer, size: "<<buffer->planes[0].bytesused<<std::endl;
-        write_encoder_output_frame(ctx->out_file, buffer);
+        if(a1 < 30)
+            write_encoder_output_frame(ctx->out_file, buffer);
+        a1++;
         share_encoder_output_frame(buffer);
     }
     /* Accounting for the first frame as it is only sps+pps */
@@ -594,7 +597,7 @@ set_defaults(context_t * ctx)
     ctx->peak_bitrate = 0;
     ctx->profile = V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE;
     ctx->ratecontrol = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;
-    ctx->iframe_interval = 10;
+    ctx->iframe_interval = 30;
     ctx->externalRPS = false;
     ctx->enableGDR = false;
     ctx->enableROI = false;