1. 程式人生 > >錄影的視訊如何在畫面中實時加上時間戳

錄影的視訊如何在畫面中實時加上時間戳

方法一(L之前版本) 可以在下面這個地方同,即MDP輸出這個畫面,但是Encode之前,使用SW的方式來Overlay即可,至於具體如何實現Overlay的話,網上搜索一下,很多示例程式碼的。如下的參考程式碼是在錄影的畫面上畫一條彩色條的測試程式碼,你們可以將新增timestamp的功能的程式碼替換掉memset之後即可實現timestamp的功能。這個Buffer的格式是YUV420 Planer格式,即先放Y,再放U,最後放V。 frameworks/av/media/libstagefright/CameraSource.cpp
 void CameraSource::dataCallbackTimestamp()
 
{
 
    ... ...
 
    CHECK(data != NULL && data->size() > 0);
 
 
 
    // Brand the timestamp start 2014-07-29
 
    {
 
        int _stride = mVideoSize.width;
 
        int height = mVideoSize.height;
 
        uint8_t *_ptr = (uint8_t *)data->pointer();
 
        int offset = 240;
 
        int bar_width = 80;
 
        ALOGE("!!! draw line, ptr: %p, offset: %d, stride: %d, height: %d", _ptr, offset, _stride,height);
 
        if (NULL != _ptr) {
 
            // Overlay the timestamp here.
 
            memset(_ptr + offset*_stride , 0x80, _stride * bar_width); //Clear Y
 
            memset(_ptr + (height*_stride) + offset*_stride/4 , 0x40, _stride*bar_width/4); // Clear U
 
            memset(_ptr + (height*_stride + height*_stride/4) + offset*_stride/4, 0x40, _stride*bar_width/4); // Clear V
 
        }
 
    }
 
    // Brand the timestamp end 2014-07-29
 
 
 
    mFramesReceived.push_back(data);
 
    int64_t timeUs = mStartTimeUs + (timestampUs - mFirstFrameTimeUs);
 
    mFrameTimes.push_back(timeUs);
 
    ... ...
 
}
方法二(適用所有版本,不包括MT6735平臺的M版本):    PreviewCmdQueThread.cpp(/vendor/mediatek/proprietary/platform/mt6735/hardware/mtkcam/D2/v1/hal/adapter/MtkDefault/Preview/PreviewCmdQueThread.cpp) 的
updateOne()方法中修改。
將丟給encoder的yuv資料進行處理,這裡的demo是將部分內容給塗黑,您可以使用這段buffer來處理timestamp,其中buffer地址為vidoNode.getImgBuf()->getVirAddr()。
1)錄影video中顯示時間:
if(flag&eID_Pass2VIDO)
{
 
 //Add timestamp
 
 MUINT8*p=(MUINT8*)vidoNode.getImgBuf()->getVirAddr();  
 
 MUINT8*end_p=(MUINT8*)vidoNode.getImgBuf()->getVirAddr()+ vidoNode.getImgBuf()->getImgWidth()*3*100/2;
 
 while((p<(end_p)))//add the addTimeStamp() function for yourself
 
 {
 
  *p=0;
 
   p++;
 
 }  
 
 //Add timestamp end
 
 vidoNode.getImgBuf()->setTimestamp(pass1LatestTimeStamp);
 
 mspPreviewBufHandler->enqueBuffer(vidoNode);
 
}


2)錄影preview的時候也顯示時間:

if (flag&eID_Pass2DISPO)
 
{
 
 //Add timestamp
 
 MUINT8*p=(MUINT8*)dispNode.getImgBuf()->getVirAddr();    
 
 MUINT8*end_p=(MUINT8*)dispNode.getImgBuf()->getVirAddr()+ dispNode.getImgBuf()->getImgWidth()*3*100/2; 
 
 while((p<(end_p)) )//add the addTimeStamp() function for yourself
 
 {
 
  *p=0; 
 
   p++;
 
 }   
 
 //Add timestamp
 
 dispNode.getImgBuf()->setTimestamp(pass1LatestTimeStamp);  
 
 mspPreviewBufHandler->enqueBuffer(dispNode);
 
}


方法三(適用所有版本,包括MT6735平臺的M版本): ExtImgProcImp.cpp: M版本=>/vendor/mediatek/proprietary/hardware/mtkcam/legacy/v1/common/ExtImgProc/ExtImgProcImp.cpp L版本=>/vendor/mediatek/proprietary/hardware/mtkcam/v1/common/ExtImgProc/ExtImgProcImp.cpp KK版本=>/mediatek/hardware/mtkcam/v1/common/ExtImgProc/ExtImgProcImp.cpp 這裡的demo是對ImageBufferQueue的yuv資料進行處理,將部分內容給塗黑,您可以使用這段buffer來處理timestamp,其中buffer地址為img.virtAddr。 1)設定需要處理的Image buffer type:
ExtImgProcImp::
 
ExtImgProcImp()
 
{
 
 FUNCTION_NAME;
 
 //Set which img buf you want to process.
 
 //For example: mImgMask = BufType_Display|BufType_Record;
 
 mImgMask = BufType_Display|BufType_Record;//錄影Preview和video中都顯示時間
 
 mUser = 0;
 
} 

2)新增時間戳
MBOOL
 
ExtImgProcImp::
 
doImgProc(ImgInfo& img)
 
{
 
...
 
 //Add image process code
 
 switch(img.bufType)
 
 {
 
  case BufType_Display:
 
  {
 
  //[BEGIN]
 
 
 
  //Add timestamp
 
  MUINT8 *p = (MUINT8*)img.virtAddr;
 
  MUINT8 *end_p = (MUINT8*)img.virtAddr + img.width*3*100/2;
 
  while((p<(end_p)))
 
  {
 
   *p=0;
 
   p++;
 
  }
 
  //Add timestamp end
 
 
 
  //[END]
 
  break;
 
  }
 
  ...
 
  case BufType_Record:
 
  {
 
  //[BEGIN]
 
 
 
  //Add timestamp
 
  MUINT8 *p = (MUINT8*)img.virtAddr;
 
  MUINT8 *end_p = (MUINT8*)img.virtAddr + img.width*3*100/2;
 
  while((p<(end_p)))
 
  {
 
   *p=0;
 
   p++;
 
  }
 
  //Add timestamp end
 
 
 
  //[END]
 
  break;
 
  }
 
  ...
 
 }
 
}