ijkplayer 参数说明文档
会不定期根据 ijkplayer版本更新,更新对应api
IJKMediaPlayback
#pragma mark - IJKMediaPlayback
#pragma mark 通知
IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification; // 播放状态的改变 代替 MPMoviePlayerContentPreloadDidFinishNotification
IJKMPMoviePlayerScalingModeDidChangeNotification; // 缩放比例的改变
IJKMPMoviePlayerPlaybackDidFinishNotification;
IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey; // NSNumber (IJKMPMovieFinishReason)
当电影播放结束或用户退出播放时调用。
IJKMPMoviePlayerPlaybackStateDidChangeNotification; // 用户改变播放状态改变时调用
IJKMPMoviePlayerLoadStateDidChangeNotification; // 当网络加载状态发生变化时。
IJKMPMoviePlayerIsAirPlayVideoActiveDidChangeNotification; // 当视频通过 AirPlay 开始播放视频或结束时调用
Movie Property Notifications
属性相关的同时声明
IJKMPMovieNaturalSizeAvailableNotification; // 在执行 prepareToPlay 时开始异步确定影片属性,当相关属性变为有效可用时调用该通知
IJKMPMoviePlayerVideoDecoderOpenNotification; // 视频 编译器打开通知
IJKMPMoviePlayerFirstVideoFrameRenderedNotification; // 视频 视频第一帧时通知
IJKMPMoviePlayerFirstAudioFrameRenderedNotification; // 视频 音频第一段时通知
#pragma mark 枚举
typedef NS_OPTIONS(NSUInteger, IJKMPMovieLoadState) {
IJKMPMovieLoadStateUnknown = 0, // 未知状态
IJKMPMovieLoadStatePlayable = 1 << 0, //
IJKMPMovieLoadStatePlaythroughOK = 1 << 1, // 当shouldAutoPlay 为Yes时,将开始在这种状态
IJKMPMovieLoadStateStalled = 1 << 2, // 播放后,自动设定为该方法
};
typedef NS_ENUM(NSInteger, IJKMPMoviePlaybackState) {
IJKMPMoviePlaybackStateStopped, // 播放停止
IJKMPMoviePlaybackStatePlaying, // 开始播放
IJKMPMoviePlaybackStatePaused, // 暂停播放
IJKMPMoviePlaybackStateInterrupted, // 播放间断
IJKMPMoviePlaybackStateSeekingForward, // 播放快进
IJKMPMoviePlaybackStateSeekingBackward // 播放后退
};
typedef NS_ENUM(NSInteger, IJKMPMovieScalingMode) {
IJKMPMovieScalingModeNone, // 没有缩放比例
IJKMPMovieScalingModeAspectFit, //尺寸比例不变填满屏幕为止
IJKMPMovieScalingModeAspectFill, // 尺寸比例不变填满屏幕,可能造成内容缺少
IJKMPMovieScalingModeFill // 尺寸比例变形也会填满屏幕
};
int reason =[[[notification userInfo] valueForKey:IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
用于IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey通知中,判断reason为一枚举
typedef NS_ENUM(NSInteger, IJKMPMovieFinishReason) {
IJKMPMovieFinishReasonPlaybackEnded, // 完成原因:播放结束
IJKMPMovieFinishReasonPlaybackError, // 完成原因:播放出现错误
IJKMPMovieFinishReasonUserExited // 完成原因:出现用户行为退出
};
Thumbnails (缩略图)
获取在指定播放时间的视频缩略图,第一个参数是获取缩略图的时间点数组;第二个参数代表时间点精度,枚举类型
typedef NS_ENUM(NSInteger, IJKMPMovieTimeOption) {
IJKMPMovieTimeOptionNearestKeyFrame, // 时间点附近
IJKMPMovieTimeOptionExact //准确时间
};
#pragma mark Attribute & Method
- (void)prepareToPlay; // 播放准备
- (void)play; // 播放
- (void)pause; // 暂停
- (void)stop; // 停止播放
- (BOOL)isPlaying; // 是否正在播放中
- (void)setPauseInBackground:(BOOL)pause; // 后台暂停
- (void)shutdown; // ******这句要写在viewDidDisappear中,否则可能会造成vc不会被释放******
@property(nonatomic, readonly) UIView *view; // 用于显示视频播放的view,调用次view
@property(nonatomic) NSTimeInterval currentPlaybackTime; // 当前播放的时间点
@property(nonatomic, readonly) NSTimeInterval duration; // 总时长
@property(nonatomic, readonly) NSTimeInterval playableDuration; // 可播放时长
@property(nonatomic, readonly) NSInteger bufferingProgress; // 缓冲进度
@property(nonatomic, readonly) BOOL isPreparedToPlay; // 准备播放
@property(nonatomic, readonly) IJKMPMoviePlaybackState playbackState; // 播放终止状态枚举
@property(nonatomic, readonly) IJKMPMovieLoadState loadState; // 加载状态枚举
@property(nonatomic, readonly) int64_t numberOfBytesTransferred; // 传输字节数
@property(nonatomic, readonly) CGSize naturalSize; // 视频原始显示View size,
@property(nonatomic) IJKMPMovieScalingMode scalingMode; // 视频尺寸模式
@property(nonatomic) BOOL shouldAutoplay; // 需要自动播放
@property (nonatomic) BOOL allowsMediaAirPlay; // 支持AirPlay 媒体
@property (nonatomic) BOOL isDanmakuMediaAirPlay; // 支持弹幕AirPlay媒体
@property (nonatomic, readonly) BOOL airPlayMediaActive; //AirPlay 是否活跃
@property (nonatomic) float playbackRate; // 返回音频/视频的当前播放速度 0-1
- (UIImage *)thumbnailImageAtCurrentTime; //获取当前时间的封面帧图片
IJKMediaUrlOpenDelegate && IJKMediaUrlOpenData
typedef NS_ENUM(NSInteger, IJKMediaUrlOpenType) {
IJKMediaUrlOpenEvent_ConcatResolveSegment = 0x10000,
IJKMediaUrlOpenEvent_TcpOpen = 0x10001,
IJKMediaUrlOpenEvent_HttpOpen = 0x10002,
IJKMediaUrlOpenEvent_LiveOpen = 0x10004,
};
- (id)initWithUrl:(NSString *)url
openType:(IJKMediaUrlOpenType)openType
segmentIndex:(int)segmentIndex
retryCounter:(int)retryCounter;
@property(nonatomic, readonly) IJKMediaUrlOpenType openType;
@property(nonatomic, readonly) int segmentIndex;
@property(nonatomic, readonly) int retryCounter; // 重试次数
@property(nonatomic, retain) NSString *url;
@property(nonatomic) int error; // 错误提示,发生错误该属性为负
@property(nonatomic, getter=isHandled) BOOL handled; // 如果url发生改变,该数值变为Yes
@property(nonatomic, getter=isUrlChanged) BOOL urlChanged; // 通过改变url设置为YES
IJKMediaModule
@property(atomic, getter=isAppIdleTimerDisabled) BOOL appIdleTimerDisabled; // 如果不希望在运行程序时锁屏 ,设置为YES
@property(atomic, getter=isMediaModuleIdleTimerDisabled) BOOL mediaModuleIdleTimerDisabled;
IJKFFOptions
typedef enum IJKFFOptionCategory {
kIJKFFOptionCategoryFormat = 1,
kIJKFFOptionCategoryCodec = 2,
kIJKFFOptionCategorySws = 3,
kIJKFFOptionCategoryPlayer = 4,
} IJKFFOptionCategory;
// 解码器选项 skip_loop_filter & skip_frame
typedef enum IJKAVDiscard {
/* We leave some space between them for extensions (drop some
* keyframes for intra-only or drop just some bidir frames). */
IJK_AVDISCARD_NONE =-16, ///< discard nothing
IJK_AVDISCARD_DEFAULT = 0, ///< 如果包大小为0,责抛弃无效的包
IJK_AVDISCARD_NONREF = 8, ///< 抛弃非参考帧(I帧)
IJK_AVDISCARD_BIDIR = 16, ///< 抛弃B帧
IJK_AVDISCARD_NONKEY = 32, ///< 抛弃除关键帧以外的,比如B,P帧
IJK_AVDISCARD_ALL = 48, ///< 抛弃所有的帧
} IJKAVDiscard;
+(IJKFFOptions *)optionsByDefault; //初始化用
-(void)applyTo:(struct IjkMediaPlayer *)mediaPlayer;
- (void)setOptionValue:(NSString *)value forKey:(NSString *)key ofCategory:(IJKFFOptionCategory)category;
- (void)setOptionIntValue:(int64_t)value forKey:(NSString *)key ofCategory:(IJKFFOptionCategory)category;
-(void)setFormatOptionValue: (NSString *)value forKey:(NSString *)key;
-(void)setCodecOptionValue: (NSString *)value forKey:(NSString *)key;
-(void)setSwsOptionValue: (NSString *)value forKey:(NSString *)key;
-(void)setPlayerOptionValue: (NSString *)value forKey:(NSString *)key;
-(void)setFormatOptionIntValue: (int64_t)value forKey:(NSString *)key;
-(void)setCodecOptionIntValue: (int64_t)value forKey:(NSString *)key;
-(void)setSwsOptionIntValue: (int64_t)value forKey:(NSString *)key;
-(void)setPlayerOptionIntValue: (int64_t)value forKey:(NSString *)key; // value:1 forKey:@"videotoolbox";开启硬件解码
@property(nonatomic) BOOL useRenderQueue; // 使用渲染队列
@property(nonatomic) BOOL showHudView; // 显示加载指示器视图
由Options 中可得知它的所有属性
start-on-prepared (开始准备);
overlay-format、max-fps(最大fps);
framedrop(跳帧开关:当cpu过慢时进行帧降低处理);
videotoolbox-max-frame-width(指定最大宽度);
videotoolbox(解码模式 0:软解、1:硬解码);
video-pictq-size ;
ijkinject-opaque;
user-agent ;
auto_convert(自动转屏开关);
timeout(超时时间);
reconnect (重连次数);
safe ;
skip_frame;
skip_loop_filter;
全部参数查看ijkplayer 中 :
//60行 static const AVOption ffp_context_options[]
https://github.com/Bilibili/ijkplayer/blob/master/ijkmedia/ijkplayer/ff_ffplay_options.h
使用方法如下:
IJKFFOptions * options = [IJKFFOptions optionsByDefault];
[options setPlayerOptionIntValue:29.97 forKey:@"r"]; // 帧速率(fps)可以改,确认非标准帧率会导致音画不同步,所以只能设定为15或者29.97)
[options setPlayerOptionIntValue:512 forKey:@"vol"]; // 设置音量大小,256为标准音量。(要设置成两倍音量时则输入512,依此类推)
[options setPlayerOptionIntValue:0 forKey:@"packet-buffering"]; // 关闭播放器缓冲 (如果频繁卡顿,可以保留缓冲区,不设置默认为1)
[option setPlayerOptionValue:@"1" forKey:@"an"]; //静音设置
[options setPlayerOptionIntValue:30 forKey:@"max-fps"]; // 最大fps
[options setPlayerOptionIntValue:0 forKey:@"framedrop"]; // 跳帧开关
[options setPlayerOptionIntValue:1 forKey:@"videotoolbox"]; // 开启硬编码 (默认是 0 :软解)
[options setPlayerOptionIntValue:960 forKey:@"videotoolbox-max-frame-width"]; // 指定最大宽度
[options setFormatOptionIntValue:0 forKey:@"auto_convert"]; // 自动转屏开关
[options setFormatOptionIntValue:1 forKey:@"reconnect"]; // 重连开启 BOOL
[options setFormatOptionIntValue:30 * 1000 * 1000 forKey:@"timeout"]; // 超时时间,timeout参数只对http设置有效,若果你用rtmp设置timeout,ijkplayer内部会忽略timeout参数。rtmp的timeout参数含义和http的不一样。
[options setFormatOptionValue:@"tcp" forKey:@"rtsp_transport"];// 如果使用rtsp协议,可以优先用tcp(默认udp)
[options setFormatOptionIntValue:1024 * 16 forKey:@"probesize"];//播放前的探测Size,默认是1M, 改小一点会出画面更快
[options setCodecOptionIntValue:IJK_AVDISCARD_DEFAULT forKey:@"skip_loop_filter"];//开启环路滤波(0比48清楚,但解码开销大,48基本没有开启环路滤波,清晰度低,解码开销小)
[options setCodecOptionIntValue:IJK_AVDISCARD_DEFAULT forKey:@"skip_frame"];
// param for living
[options setPlayerOptionIntValue:3000 forKey:@"max_cached_duration"]; // 最大缓存大小是3秒,可以依据自己的需求修改
[options setPlayerOptionIntValue:1 forKey:@"infbuf"]; // 无限读
[options setPlayerOptionIntValue:0 forKey:@"packet-buffering"]; // 关闭播放器缓冲
//param for playback
[options setPlayerOptionIntValue:0 forKey:@"max_cached_duration"];
[options setPlayerOptionIntValue:0 forKey:@"infbuf"];
[options setPlayerOptionIntValue:1 forKey:@"packet-buffering"];
_player = [[IJKFFMoviePlayerController alloc] initWithContentURL:self.url withOptions:options];
IJKFFMoviePlayerController
// LogLevel 日志等级
typedef enum IJKLogLevel {
k_IJK_LOG_UNKNOWN = 0, //未知
k_IJK_LOG_DEFAULT = 1, //默认
k_IJK_LOG_VERBOSE = 2, //详细
k_IJK_LOG_DEBUG = 3, //调试
k_IJK_LOG_INFO = 4, //详情信息
k_IJK_LOG_WARN = 5, //警告
k_IJK_LOG_ERROR = 6, //错误
k_IJK_LOG_FATAL = 7, //致命
k_IJK_LOG_SILENT = 8, //
} IJKLogLevel;
- (id)initWithContentURL:(NSURL *)aUrl
withOptions:(IJKFFOptions *)options;
- (id)initWithContentURLString:(NSString *)aUrlString
withOptions:(IJKFFOptions *)options;
- (void)prepareToPlay; // 播放准备
- (void)play; // 播放
- (void)pause; // 暂停
- (void)stop; // 停止播放
- (BOOL)isPlaying; // 是否正在播放中
- (void)setPauseInBackground:(BOOL)pause; // 后台暂停
- (BOOL)isVideoToolboxOpen; // 视频工具栏是否开启(一般不用这个,太丑)
+ (void)setLogReport:(BOOL)preferLogReport; // 日志报告输出
+ (void)setLogLevel:(IJKLogLevel)logLevel; // 日志报告等级
+ (BOOL)checkIfFFmpegVersionMatch:(BOOL)showAlert; // 检查版本是否匹配
+ (BOOL)checkIfPlayerVersionMatch:(BOOL)showAlert // 检查版本是否匹配
major:(unsigned int)major
minor:(unsigned int)minor
micro:(unsigned int)micro;
@property(nonatomic, readonly) CGFloat fpsInMeta; // fps 率
@property(nonatomic, readonly) CGFloat fpsAtOutput; // fps输出值
- (void)setOptionValue:(NSString *)value forKey:(NSString *)key ofCategory:(IJKFFOptionCategory)category;
- (void)setOptionIntValue:(int64_t)value forKey:(NSString *)key ofCategory:(IJKFFOptionCategory)category;
- (void)setFormatOptionValue: (NSString *)value forKey:(NSString *)key;
- (void)setCodecOptionValue: (NSString *)value forKey:(NSString *)key;
- (void)setSwsOptionValue: (NSString *)value forKey:(NSString *)key;
- (void)setPlayerOptionValue: (NSString *)value forKey:(NSString *)key;
- (void)setFormatOptionIntValue: (int64_t)value forKey:(NSString *)key;
- (void)setCodecOptionIntValue: (int64_t)value forKey:(NSString *)key;
- (void)setSwsOptionIntValue: (int64_t)value forKey:(NSString *)key;
- (void)setPlayerOptionIntValue: (int64_t)value forKey:(NSString *)key;
@property (nonatomic, retain) id segmentOpenDelegate;
@property (nonatomic, retain) id tcpOpenDelegate;
@property (nonatomic, retain) id httpOpenDelegate;
@property (nonatomic, retain) id liveOpenDelegate;
相关使用:
#ifdef DEBUG
[IJKFFMoviePlayerController setLogReport:YES];
[IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG];
#else
[IJKFFMoviePlayerController setLogReport:NO];
[IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_INFO];
#endif
[IJKFFMoviePlayerController checkIfFFmpegVersionMatch:YES];
self.player.shouldAutoplay = NO;
//如果是直播,最好不让他自动播放,如果YES,那么就会自动播放电影,不需要通过[self.player play];就可以播放了,
//但是如果NO,我们需要注册通知,然后到响应比较合适的地方去检测通知,然后必须通过[self.player play];手动播放
相关处理:
丢帧处理:当CPU在处理视频的时候处理过慢,默认音视频处理方案是视频同步音频导致音频播放过快,视频跟不上导致丢帧现象。这是可通过修改 framedrop 进行处理,在视频处理不过来的时候丢弃一些帧达到同步的效果,ijkplayer 中默认为1,可自行进行修改。
[options setPlayerOptionIntValue:0 forKey:@"framedrop"]; // 跳帧开关
// 跳帧开关,如果cpu解码能力不足,可以设置成5,否则会引起音视频不同步,也可以通过设置它来跳帧达到倍速播放
降码率:如果使用硬编码,在网络环境较差的情况下,为了使直播画面更为流程,可以实时改变硬编码率,进行丢帧处理,在丢帧的同时也可降低音频的码率。
[options setOptionIntValue:1 forKey:@"videotoolbox" ofCategory:kIJKFFOptionCategoryPlayer]; // 开启硬编码
videotoolbox(解码模式 0:软解、1:硬解码);
未完待续。。。。