-
Notifications
You must be signed in to change notification settings - Fork 246
rawVideoData
xinbaicheng edited this page Sep 8, 2016
·
10 revisions
该功能只在软解时有效
硬解时会将视频数据直接输出至Surface,难以获取视频数据
必须在调用 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
}
}