阿里云短視頻SDK for iOS —— (一)集成與基礎(chǔ)拍攝

當前短視頻類APP如潮水一般席卷各大應(yīng)用市場,各類短視頻SDK也層出不窮。由于項目需要,前段時間接觸了阿里云短視頻SDK。我整理了開發(fā)過程中的關(guān)鍵點以及踩過的坑,進行一些分享。

系統(tǒng)版本

支持iOS8.0及以上版本

SDK集成

短視頻SDK依賴四個Framework如下:

  • 動態(tài)庫:

AliyunVideoSDKPro
QuCore-ThirdParty

  • 靜態(tài)庫:

VODUpload
AliyunOSSiOS

手動集成方式

  1. 打開工程,選擇目標”TARGETS”,選擇”General”->”Embededed Binaries”,單擊”+”號,單擊“Add Other…”,導(dǎo)入

AliyunVideoSDKPro.framework
QuCore-ThirdParty.framework

  1. 打開工程,選擇目標TARGETS,選擇”General”->”Linked Frameworks And Libraries”,單擊”+”號,單擊“Add Other…”,導(dǎo)入

AliyunOSSiOS.framework
VODUpload.framework

  1. 打開工程,選擇目標”TARGETS”,選擇”General”->”Linked Frameworks And Libraries”,單擊”+”號,依賴

libz.tbd
ImageIO.framework
CoreMedia.framework
CoreVideo.framework
VideoToolBox.framework
MediaPlayer.framework
OpenAL.framework
libc++.tbd
libsqlite3.tbd
libiconv.tbd

  • 注意:其中,AliyunVideoSDKPro.frameworkQuCore-ThirdParty.framework是動態(tài)庫,需要在”TARGETS” -> ”General” -> ”Embedded Binaries”中導(dǎo)入。

  • 集成結(jié)果如下圖所示


    image.png

    image.png

基礎(chǔ)拍攝

  1. 引用文件
#import <AliyunVideoSDKPro/AliyunVideoSDKPro.h>
  1. 創(chuàng)建 recorder 屬性
@property (nonatomic,strong) AliyunIRecorder *recorder;
  1. 初始化 recorder
_recorder = [[AliyunIRecorder alloc] initWithDelegate:self videoSize:CGSizeMake(720, 1280)];

// 預(yù)覽視圖,必須設(shè)置
_recorder.preview = self.view;

//  攝像頭角度
_recorder.cameraRotate = 270;

/*
視頻的輸出路徑
注意:若上一次錄制的 outputPath 路徑的視頻存在沙盒里沒有刪除,并且與本次錄制的視頻路徑且相同重名的話,錄制將會失敗
*/
_recorder.outputPath = outputPath;

// 視頻的輸出類型
_recorder.outputType = AliyunIRecorderVideoOutputPixelFormatType420f;

/*
文件配置路徑
注意:若上一次錄制的 taskPath  路徑的視頻存在沙盒里沒有刪除,并且與本次錄制的視頻路徑相且同重名的話,錄制將會失敗
*/
_recorder.taskPath = taskPath;

// 美顏狀態(tài)
_recorder.beautifyStatus = YES;

// 設(shè)置美顏度 [0,100]
_recorder.beautifyValue = 0;

// 使用自帶人臉識別,開啟該功能,系統(tǒng)會在檢測到有人臉動圖加入時自動進行追蹤顯示
_recorder.useFaceDetect = YES;

// 后置攝像頭采集分辨率 默認:AVCaptureSessionPreset640x480
_recorder.backCaptureSessionPreset = AVCaptureSessionPreset1280x720;

// 前置攝像頭采集分辨率 默認:AVCaptureSessionPreset640x480
_recorder.frontCaptureSessionPreset = AVCaptureSessionPreset1280x720;

// 設(shè)置識別人臉的個數(shù)  最大是3個 最小是1個  如果不需要檢測人臉 使用:useFaceDetect = NO
_recorder.faceDetectCount = 2;

// 開始預(yù)覽,cameraPosition 攝像頭位置(前置、后置)
[_recorder startPreviewWithPositon:AliyunIRecorderCameraPositionBack];
    
// 設(shè)置視頻最大時長 默認8
_recorder.clipManager.maxDuration = 30;

// 初始化拍攝時的音樂對象,
AliyunEffectMusic *music = [[AliyunEffectMusic alloc] initWithFile:musicUrl];
music.startTime = 0;
music.duration = 30;

// 為拍攝的視頻添加音樂
[_recorder applyMusic:music];
  1. 開始拍攝
[_recorder startRecording];
  1. 停止拍攝
[_recorder stopRecording];
  1. 結(jié)束拍攝(支持斷點拍攝,stopRecording方法為斷點)
[_recorder finishRecording];
  1. AliyunIRecorderDelegate 的代理方法
// 錄制實時時長
- (void)recorderVideoDuration:(CGFloat)duration;

// 開始預(yù)覽回調(diào)
- (void)recorderDidStartPreview;

// 停止錄制回調(diào)
- (void)recorderDidStopRecording;

// 當錄至最大時長時回調(diào)
- (void)recorderDidStopWithMaxDuration;

// 結(jié)束錄制回調(diào)
- (void)recorderDidFinishRecording;

// 錄制異常
- (void)recoderError:(NSError *)error;
  • 當執(zhí)行完 recorderDidFinishRecording 這個代理方法,就代表最基礎(chǔ)的拍攝功能已經(jīng)完成了。阿里云短視頻SDK 還提供了很多強大的短視頻的 拍攝,編輯 功能,我將在以后的文章中進行更多的整理,敬請期待~
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容