視頻直播方面的知識ffmpeg

最近由於項目需要,接觸了一下ffmpeg的編譯和使用。

由於之前的版本ffmpeg編譯的庫比較老,對新設備,5s及5s以後的設備支持不太好,重新編譯了ffmpeg靜態庫。

一,下載並在終端中運行腳本編譯ffmpeg

腳本參考git上的:https://github.com/kewlbear/FFmpeg-iOS-build-script;

終端進入剛剛下載後的腳本文件夾下,運行sh:build-ffmpeg.sh 自動編譯,有缺少yasm的按照提示操作,安裝yasm

編譯的是ffmpeg2.5.3版本,Xcode6下iOS8.1。

按照腳本編譯完後的靜態庫目錄如下:技術分享

其中的.a文件爲靜態庫文件,include文件夾內的是頭文件

二,將編譯好的ffmpeg文件拖人工程,並設置相應的路徑

新建工程,將編譯好後包含include和lib文件夾拖進工程

技術分享

我這裏先將FFmpeg-iOS文件夾copy了一分放在工程目錄下,並重新命名爲ffmpegNew,路徑如下圖:

技術分享

到這裏要修改工程的Header Search Paths ,要不然會報 

include“libavformat/avformat.h” file not found  錯誤

根據Library Search Paths 中的lib的路徑:

技術分享

複製路徑,添加一份到Header Search Paths 中,再將lib改爲include

改好如下:

技術分享

 

三,導入其他庫文件

其中libz.dylib libbz2.dylib libiconv.dylib 貌似是必須要導入的,其他的按照需求配置

個人配置好後的如下供參考:

技術分享

四,將第三方代碼導入工程

根據工程的定製化需求,這裏選擇了iFrameExtractor,git代碼參考:https://github.com/lajos/iFrameExtractor 或者 RTSPPlayer    https://github.com/SutanKasturi/RTSPPlayer

我這裏用的後者的demo裏面的代碼,直接將(AudioStreamer  RTSPPlayer  Utilities)六個文件拖入工程使用

技術分享

 

五,實現播放,實現方法可以參考demo中的代碼

其中的self.playUrl爲視頻流的地址本工程用的是RTSP 數據流  示例:

self.playUrl = @"rtsp://xxx.xxx.xxx.xxx/xxx.sdp";

實現播放的代碼:

 

 

self.videoView = [[RTSPPlayer allocinitWithVideo: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.image =  weakself.videoView.currentImage;

//        NSLog(@"%d,%d",self.videoView.sourceWidth,self.videoView.sourceHeight);

    });

}

下載鏈接點擊打開鏈接

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