在android中使用ffmpeg录制视频

时间:2017-01-11 08:53:38

标签: android ffmpeg

我正在研究ffmpeg for android库,无法理解代码的一部分。

public void onPreviewFrame(byte[] data, Camera camera)
{ 
    if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING)
    {
         startTime = System.currentTimeMillis();
         return;
    }

    if (RECORD_LENGTH > 0) {
        int i = imagesIndex++ % images.length;
        yuvImage = images[i];
        timestamps[i] = 1000 * (System.currentTimeMillis() - startTime);
    }

//till here i was able to understand but the first statement is for what purpose?

    /* get video data */
    if (yuvImage != null && recording) {
        ((ByteBuffer)yuvImage.image[0].position(0)).put(data);
    }
}

1 个答案:

答案 0 :(得分:1)

onPreviewFrame是一个重写方法,如果你提供了

中的cameraCallbacks
mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() {
    public void onPreviewFrame(byte[] imageData, Camera arg1) {
        <<<Your logic here>>>
  }
  }

请参阅此链接http://www.programcreek.com/java-api-examples/index.php?api=android.hardware.Camera.PreviewCallback