15 fps ,
cpu占用高,卡死
用的是onCaptureVideoFrame获取的yuv数据,随后将数据推送到sdk,cpu占用暴涨,手机性能很好
_videoFrameObserver = VideoFrameObserver(
onCaptureVideoFrame: (sourceType, videoFrame) {
// print(
// 'Captured video frame from $sourceType size: ${videoFrame.width}x${videoFrame.height} y: ${videoFrame.yBuffer?.length} u:${videoFrame.uBuffer?.length} v:${videoFrame.vBuffer?.length}');
if (!isJoined) {
return;
}
if (videoFrame.yBuffer != null &&
videoFrame.uBuffer != null &&
videoFrame.vBuffer != null &&
videoFrame.width != null &&
videoFrame.height != null) {
final int totalLength = videoFrame.yBuffer!.length +
videoFrame.uBuffer!.length +
videoFrame.vBuffer!.length;
final Uint8List yuvBuffer = Uint8List(totalLength);
yuvBuffer.setRange(
0, videoFrame.yBuffer!.length, videoFrame.yBuffer!);
yuvBuffer.setRange(
videoFrame.yBuffer!.length,
videoFrame.yBuffer!.length + videoFrame.uBuffer!.length,
videoFrame.uBuffer!);
yuvBuffer.setRange(
videoFrame.yBuffer!.length + videoFrame.uBuffer!.length,
totalLength,
videoFrame.vBuffer!);
_pushVideoFrame(
yuvBuffer,
videoFrame.width!,
videoFrame.height!,
VideoPixelFormat.videoPixelNv12,
videoFrame.renderTimeMs ?? DateTime.now().millisecondsSinceEpoch);
}
},
);
_engine.getMediaEngine().registerVideoFrameObserver(_videoFrameObserver);
Future<void> _pushVideoFrame(Uint8List frame, int w, int h,
VideoPixelFormat format, int timestamp) async {
await _engine.getMediaEngine().pushVideoFrame(
frame: ExternalVideoFrame(
type: VideoBufferType.videoBufferArray,
// format: VideoPixelFormat.videoPixelNv12,
format: format,
buffer: frame,
stride: w,
height: h,
// timestamp: DateTime.now().millisecondsSinceEpoch,
timestamp: timestamp,
),
);
}
可以参考下Demo的处理: https://github.com/AgoraIO-Extensions/Agora-Flutter-SDK/tree/main