最近由于項(xiàng)目需要,接觸了一下ffmpeg的編譯和使用。
目前創(chuàng)新互聯(lián)建站已為數(shù)千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計、灣里網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
由于之前的版本ffmpeg編譯的庫比較老,對新設(shè)備,5s及5s以后的設(shè)備支持不太好,重新編譯了ffmpeg靜態(tài)庫。
一,下載并在終端中運(yùn)行腳本編譯ffmpeg
腳本參考git上的:https://github.com/kewlbear/FFmpeg-iOS-build-script;
終端進(jìn)入剛剛下載后的腳本文件夾下,運(yùn)行sh:build-ffmpeg.sh 自動編譯,有缺少yasm的按照提示操作,安裝yasm
編譯的是ffmpeg2.5.3版本,Xcode6下iOS8.1。
按照腳本編譯完后的靜態(tài)庫目錄如下:
其中的.a文件為靜態(tài)庫文件,include文件夾內(nèi)的是頭文件
二,將編譯好的ffmpeg文件拖人工程,并設(shè)置相應(yīng)的路徑
新建工程,將編譯好后包含include和lib文件夾拖進(jìn)工程

我這里先將FFmpeg-iOS文件夾copy了一分放在工程目錄下,并重新命名為ffmpegNew,路徑如下圖:
到這里要修改工程的Header Search Paths ,要不然會報
include“l(fā)ibavformat/avformat.h” file not found 錯誤
根據(jù)Library Search Paths 中的lib的路徑:

復(fù)制路徑,添加一份到Header Search Paths 中,再將lib改為include
改好如下:

三,導(dǎo)入其他庫文件
其中l(wèi)ibz.dylib libbz2.dylib libiconv.dylib 貌似是必須要導(dǎo)入的,其他的按照需求配置
個人配置好后的如下供參考:

四,將第三方代碼導(dǎo)入工程
根據(jù)工程的定制化需求,這里選擇了iFrameExtractor,git代碼參考:https://github.com/lajos/iFrameExtractor 或者 RTSPPlayer https://github.com/SutanKasturi/RTSPPlayer
我這里用的后者的demo里面的代碼,直接將(AudioStreamer RTSPPlayer Utilities)六個文件拖入工程使用

五,實(shí)現(xiàn)播放,實(shí)現(xiàn)方法可以參考demo中的代碼
其中的self.playUrl為視頻流的地址本工程用的是RTSP 數(shù)據(jù)流 示例:
self.playUrl = @"rtsp://xxx.xxx.xxx.xxx/xxx.sdp";
實(shí)現(xiàn)播放的代碼:
self.videoView = [[RTSPPlayer alloc] initWithVideo:self.playUrl usesTcp:YES];
self.videoView.outputHeight = self.playImage.frame.size.height;
self.videoView.outputWidth = self.playImage.frame.size.width;
__weak TestViewController *weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
weakself.playTimer = [NSTimer scheduledTimerWithTimeInterval:1/30.0
target:weakself
selector:@selector(displayNextFrame:)
userInfo:nil
repeats:YES];
});
-(void)displayNextFrame:(NSTimer *)timer {
if (![self.videoView stepFrame]) {
[timer invalidate];
return;
}
if (startframecount < 48) {
startframecount++;
} else {
startframecount++;
[self playVideo];
}
}
-(void)playVideo
{
// NSLog(@"%p,%d",__FUNCTION__,__LINE__);
//主線程更改視圖
//視頻源尺寸為352*288
__weak TestViewController *weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
weakself.playImage.p_w_picpath = weakself.videoView.currentImage;
// NSLog(@"%d,%d",self.videoView.sourceWidth,self.videoView.sourceHeight);
});
}
當(dāng)前文章:ffmpeg的編譯和使用
網(wǎng)站網(wǎng)址:http://www.chinadenli.net/article22/pgdijc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、靜態(tài)網(wǎng)站、企業(yè)網(wǎng)站制作、網(wǎng)站制作、微信公眾號、用戶體驗(yàn)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)