diff --git a/gst-plugins/gst-nvinfer/gstnvinfer.cpp b/gst-plugins/gst-nvinfer/gstnvinfer.cpp
index d73edd2..4a0d091 100644
--- a/gst-plugins/gst-nvinfer/gstnvinfer.cpp
+++ b/gst-plugins/gst-nvinfer/gstnvinfer.cpp
@@ -18,6 +18,8 @@
 #include <mutex>
 #include <list>
 #include <thread>
+#include <iostream>
+#include <fstream>
 
 #include "gst-nvevent.h"
 #include "gstnvdsmeta.h"
@@ -1263,12 +1265,171 @@ convert_batch_and_push_to_input_thread (GstNvInfer *nvinfer,
 
   nvtxDomainRangePushEx(nvinfer->nvtx_domain, &eventAttrib);
 
+  printf("batch->frames.size() = %lu\n", batch->frames.size());
+  if (1) {
+    NvBufSurface *tmp_surf = &(nvinfer->tmp_surf);
+    int p;
+
+    printf("nvinfer->tmp_surf: \n");
+    printf("  batchSize = %d\n", tmp_surf->batchSize);
+    printf("  numFilled = %d\n", tmp_surf->numFilled);
+    printf("  memType = %d\n", tmp_surf->memType);
+    for (int bs = 0; bs < tmp_surf->batchSize; bs++) {
+      NvBufSurfaceParams *sur = &(tmp_surf->surfaceList[bs]);
+      if (sur == NULL)
+        break;
+      printf("  surfaceList[%d]:\n", bs);
+      printf("    width = %d\n", sur->width);
+      printf("    height = %d\n", sur->height);
+      printf("    pitch = %d\n", sur->pitch);
+      printf("    layout = %d\n", sur->layout);
+      printf("    colorFormat = %d\n", sur->colorFormat);
+      printf("    bufferDesc = %lu\n", sur->bufferDesc);
+      printf("    dataSize = %d\n", sur->dataSize);
+      printf("    dataPtr = %p\n", sur->dataPtr);
+
+      // https://docs.nvidia.com/metropolis/deepstream/sdk-api/Api/BufSurface/BufSurface.html?highlight=nvbuf_color_format_nv12#_CPPv423NvBufSurfaceColorFormat
+      if (sur->colorFormat == NVBUF_COLOR_FORMAT_NV12)
+        printf("it's NVBUF_COLOR_FORMAT_NV12!\n");
+      else
+        printf("it's not NVBUF_COLOR_FORMAT_NV12(%d)\n", NVBUF_COLOR_FORMAT_NV12);
+
+      NvBufSurfacePlaneParams *planeParams = &(sur->planeParams);
+      printf("    NvBufSurfaceParams->planeParams:\n");
+      printf("      num_planes = %d\n", planeParams->num_planes);
+      for (p = 0; p < planeParams->num_planes; p++) {
+        printf("      width[%d] = %u\n", p, planeParams->width[p]);
+        printf("      height[%d] = %u\n", p, planeParams->height[p]);
+        printf("      pitch[%d] = %u\n", p, planeParams->pitch[p]);
+        printf("      offset[%d] = %u\n", p, planeParams->offset[p]);
+        printf("      psize[%d] = %u\n", p, planeParams->psize[p]);
+        printf("      bytesPerPix[%d] = %u\n", p, planeParams->bytesPerPix[p]);
+      }
+
+      NvBufSurfaceMappedAddr *mAddr = &(sur->mappedAddr);
+      printf("    NvBufSurfaceParams->mappedAddr:\n");
+      for (p = 0; p < NVBUF_MAX_PLANES; p++) {
+        if (!mAddr->addr) {
+          printf("      mappedAddr->addr[%d] is NULL\n", p);
+          break;
+        }
+        printf("      mappedAddr->addr[%d] = %p\n", p, mAddr->addr[p]);
+      }
+
+      if (mAddr->eglImage == NULL)
+        printf("      mappedAddr->eglImage is NULL\n");
+      else
+        printf("      mappedAddr->eglImage is %p\n", mAddr->eglImage);
+
+      // write_video_frame
+      {
+        /* Map the buffer so that it can be accessed by CPU */
+        // int NvBufSurfaceMap(NvBufSurface *surf, int index, int plane, NvBufSurfaceMemMapFlagstype)
+        for (p = 0; p < planeParams->num_planes; p++) {
+          if (NvBufSurfaceMap (tmp_surf, bs, p, NVBUF_MAP_READ) != 0)
+          printf("NvBufSurfaceMap failed ===============\n");
+          // sync to CPU for the two planes
+          if(tmp_surf->memType == NVBUF_MEM_SURFACE_ARRAY) {
+            /* Cache the mapped data for CPU access */
+            NvBufSurfaceSyncForCpu (tmp_surf, bs, p);
+          }
+        }
+
+        NvBufSurfaceMappedAddr *mAddr = &(sur->mappedAddr);
+        for (p = 0; p < NVBUF_MAX_PLANES; p++) {
+          if (!mAddr->addr) {
+            printf("      mappedAddr->addr[%d] is NULL\n", p);
+            break;
+          }
+          printf("      mappedAddr->addr[%d] = %p\n", p, mAddr->addr[p]);
+        }
+
+        char filename[64];
+        sprintf(filename, "output_%dx%d_bs-%d.nv12",
+            sur->width, sur->height, bs);
+        std::ofstream outputfile(filename);
+
+        for (p = 0; p < planeParams->num_planes; p++)
+        {
+          size_t bytes_to_write =
+            planeParams->bytesPerPix[p] * planeParams->width[p];
+
+          char *data = (char *) mAddr->addr[p];
+          for (int j = 0; j < planeParams->height[p]; j++)
+          {
+            outputfile.write(data, bytes_to_write);
+            if (!outputfile.good())
+              return -1;
+            data += planeParams->pitch[p];
+          }
+        }
+
+        for (p = 0; p < planeParams->num_planes; p++)
+          NvBufSurfaceUnMap (tmp_surf, bs, p);
+      }
+    }
+  }
+
   if (batch->frames.size() > 0) {
     /* Batched tranformation. */
     err = NvBufSurfTransform (&nvinfer->tmp_surf, mem->surf,
               &nvinfer->transform_params);
   }
 
