Skip to content

rawVideoData

xinbaicheng edited this page Sep 8, 2016 · 10 revisions

获取视频数据

基本设置

视频数据格式

必须在调用 prepareAsync 之前设置

ksyMediaPlayer.setOption(KSYMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", KSYMediaPlayer.SDL_FCC_RV32);

上述代码是将输出的视频数据格式设置为 RGBA8888

缓存管理

开发者需申请相应的缓存,并交予播放器,播放器方可将视频数据交予开发者

ByteBuffer rawBuffer[] = new ByteBuffer[5]; // 5 is just an example.
for(int index=0; index<rawBuffer.length; index++)
{
	rawBuffer[index] = ByteBuffer.allocate(mVideoWidth * mVideoHeight * 4); // make sure buffer Not smaller than video resolution
	ksyMediaPlayer.addVideoRawBuffer(rawBuffer[index].array());
}

使用示例

//[important]make sure it is called before "prepareAsync"
ksyMediaPlayer.setOption(KSYMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", KSYMediaPlayer.SDL_FCC_RV32);

ByteBuffer rawBuffer[] = new ByteBuffer[5];		//5 buffers is just an example
for(int index=0; index<rawBuffer.length; index++)
{
	rawBuffer[index] = ByteBuffer.allocate(mVideoWidth * mVideoHeight * 4);     //make sure it is big enough, not smaller than the maximum video resolution
	ksyMediaPlayer.addVideoRawBuffer(rawBuffer[index].array());
}

ksyMediaPlayer.setVideoRawDataListener(new KSYMediaPlayer.OnVideoRawDataListener() {
	@Override
	public void onVideoRawDataAvailable(IMediaPlayer mp, byte[] buf, int size, int width, int height, int format) {
		//todo: handle RGB raw data. 
		//You can handle it in another thread, but never forget calling addVideoRawBuffer after it is done
		//....
		
		ksyMediaPlayer.addVideoRawBuffer(buf);		//MUST call it after the buf is handled
	}
}
Clone this wiki locally