ijkplayer 參數說明文檔 --個人使用

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:硬解碼);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章