我想要完成的是将文本添加到SD卡上的现有视频中,经过一些搜索,我发现我必须捕获视频字节并将文本添加到视频的每个帧。
答案 0 :(得分:1)
这有助于我从预览中获取byte []。
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mCamera == null) {
return;
}
mCamera.setPreviewCallback(new PreviewCallback() {
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
//the parameter 'data' holds the frame information
int width = 0; int height = 0;
Camera.Parameters parameters = camera.getParameters();
height = parameters.getPreviewSize().height;
width = parameters.getPreviewSize().width;
// You can change formats, save the data
// to file etc.
YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21,
width, height, null);
Rect rectangle = new Rect(0, 0, width, height);
yuvImage.compressToJpeg(rectangle, 100, stream);
}
});
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null) {
// preview surface does not exist
return;
}
// stop preview before making changes
try {
mCamera.stopPreview();
} catch (Exception e) {
// ignore: tried to stop a non-existent preview
}
// set preview size and make any resize, rotate or
// reformatting changes here
CameraOrientationHelper.setCameraDisplayOrientation(mActivity, mCameraId, mCamera);
// start preview with new settings
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview(); } catch (Exception e) {
Log.d(TAG, "Error starting camera preview: " + e.getMessage());
}
}
}
来源:https://nidesai.wordpress.com/2013/09/22/android-camera-capturing-raw-video-frames/
我一直在努力寻找与你的问题相似的解决方案。 我需要在录制视频时将文字添加到视频中。因此,当视频保存时,它包含文本。