一、添加接口
1、在IJKMediaPlayBack.h添加三个方法
image.png
- (CVPixelBufferRef)framePixelbuffer;
- (void)framePixelbufferLock;
- (void)framePixelbufferUnlock;
2、在ff_ffplay_def.h 的 FFPlayer 数据结构中添加如下:
image.png
// 引入头文件
#include <CoreVideo/CoreVideo.h>
CVPixelBufferRef szt_pixelbuffer;
pthread_mutex_t szt_pixelbuffer_mutex;
3、在ijkplayer.h中添加:
image.png
// 引入头文件
#include <CoreVideo/CoreVideo.h>
CVPixelBufferRef ijkmp_get_pixelbuffer(IjkMediaPlayer *mp);
int ijkmp_pixelbuffer_mutex_init(IjkMediaPlayer *mp);
int ijkmp_pixelbuffer_mutex_lock(IjkMediaPlayer *mp);
int ijkmp_pixelbuffer_mutex_unlock(IjkMediaPlayer *mp);
4、在ijkplayer.c添加:
CVPixelBufferRef ijkmp_get_pixelbuffer(IjkMediaPlayer *mp)
{
return mp->ffplayer->szt_pixelbuffer;
}
int ijkmp_pixelbuffer_mutex_init(IjkMediaPlayer *mp)
{
int ret = ffp_pixelbuffer_mutex_init(mp->ffplayer);
return ret;
}
int ijkmp_pixelbuffer_mutex_lock(IjkMediaPlayer *mp)
{
int ret = ffp_pixelbuffer_lock(mp->ffplayer);
return ret;
}
int ijkmp_pixelbuffer_mutex_unlock(IjkMediaPlayer *mp)
{
int ret = ffp_pixelbuffer_unlock(mp->ffplayer);
return ret;
}
5、在ff_ffplay.h添加:
image.png
int ffp_pixelbuffer_mutex_init(FFPlayer *ffp);
int ffp_pixelbuffer_lock(FFPlayer *ffp);
int ffp_pixelbuffer_unlock(FFPlayer *ffp);
6、在ff_ffplay.c添加:
int ffp_pixelbuffer_mutex_init(FFPlayer *ffp)
{
int ret = pthread_mutex_init(&ffp->szt_pixelbuffer_mutex, NULL);
return ret;
}
int ffp_pixelbuffer_lock(FFPlayer *ffp)
{
int ret = pthread_mutex_lock(&ffp->szt_pixelbuffer_mutex);
return ret;
}
int ffp_pixelbuffer_unlock(FFPlayer *ffp)
{
int ret = pthread_mutex_unlock(&ffp->szt_pixelbuffer_mutex);
return ret;
}
7、在IJKFFMoviePlayerController.h添加:
image.png
- (CVPixelBufferRef)framePixelbuffer;
- (void)framePixelbufferLock;
- (void)framePixelbufferUnlock;
8、在IJKFFMoviePlayerController.m添加:
- (CVPixelBufferRef)framePixelbuffer
{
if (_mediaPlayer)
{
return ijkmp_get_pixelbuffer(_mediaPlayer);
}
return NULL;
}
- (void)framePixelbufferLock
{
if (_mediaPlayer)
{
ijkmp_pixelbuffer_mutex_lock(_mediaPlayer);
}
}
- (void)framePixelbufferUnlock
{
if (_mediaPlayer)
{
ijkmp_pixelbuffer_mutex_unlock(_mediaPlayer);
}
}
二、如何使用:
[self.ijkplayer framePixelbufferLock];
CVPixelBufferRef pixelBuffer = [self.ijkplayer framePixelbuffer];
[self.ijkplayer framePixelbufferUnlock];
网友评论