-
Notifications
You must be signed in to change notification settings - Fork 246
rawVideoData
Franken Zeng edited this page Feb 23, 2017
·
10 revisions
该方式暂时只在软解的情况下生效
必须在调用 prepareAsync 之前设置
ksyMediaPlayer.setOption(KSYMediaPlayer.OPT_CATEGORY_PLAYER, "overlay-format", KSYMediaPlayer.SDL_FCC_RV32);
上述代码是将输出的视频数据格式设置为 RGBA8888
开发者需申请相应的缓存,并交予播放器,播放器方可将视频数据交予开发者。
初始化buffer时,需要根据视频的宽高值计算,视频宽高数据需要在OnPrepared后才是有效数据。
ByteBuffer rawBuffer[] = new ByteBuffer[5]; // 5 is just an example.
for(int index=0; index<rawBuffer.length; index++)
{
//注意请在播放初始化之后(比如OnPrepared)再创建buffer否则mVideoWidth,mVideoHeight为0无法创建成功
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
}
}