电竞比分网-中国电竞赛事及体育赛事平台

分享

(2)iOS使用ffmpeg播放rstp實時監(jiān)控視頻數據流

 xuanji00 2013-09-23
一、編譯針對iOS平臺的ffmpeg庫(kxmovie)
近期有一個項目,需要播放各種格式的音頻、視頻以及網絡攝像頭實時監(jiān)控的視頻流數據,經過多種折騰之后,最后選擇了kxmovie,kxmovie項目已經整合了ffmpeg和簡單的播放器,具體可以參考kxmovie主頁:https://github.com/kolyvan/kxmovie 
編譯kxmovie很簡單,已經支持iOS 6.1 和 armv7s,一次成功,編譯過程沒出現(xiàn)什么問題:
git clone git://github.com/kolyvan/kxmovie.git
cd kxmovie
git submodule update --init 
rake
二、使用kxmovie
1.kxmovie/output文件夾下文件添加到工程
2.添加框架:MediaPlayer, CoreAudio, AudioToolbox, Accelerate, QuartzCore, OpenGLES and libz.dylib,libiconv.dylib
3.添加lib庫:libkxmovie.a, libavcodec.a, libavformat.a, libavutil.a, libswscale.a, libswresample.a
4.播放視頻:
ViewController *vc;
    vc = [KxMovieViewController movieViewControllerWithContentPath:path parameters:nil];
    [self presentViewController:vc animated:YES completion:nil]; 
5.具體使用參考demo工程:KxMovieExample
三、碰到的問題
播放本地視頻和網絡視頻正常,播放網絡攝像頭實時監(jiān)控視頻流(h264)的時候出現(xiàn)錯誤:

[rtsp @ 0x906cc00] UDP timeout, retrying with TCP

[rtsp @ 0x906cc00] Nonmatching transport in server reply

[rtsp @ 0x906cc00] Could not find codec parameters for stream 0 (Video: h264): unspecified size

Consider increasing the value for the 'analyzeduration' and 'probesize' options

Couldn't find stream information

跟蹤代碼,錯誤是在avformat_find_stream_info獲取流信息失敗的時候的時候觸發(fā)。

 

if(avformat_find_stream_info(pFormatCtx,NULL) < 0) {

    av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information\n");

    goto initError;

}

經過幾天的摸索,最終確定是網絡的問題(在模擬器播放一直出錯,在3G網絡下能播放iOS使用ffmpeg播放rstp實時監(jiān)控視頻數據流),具體原因估計是rstp視頻流,程序默認采用udp傳輸或者組播,導致在私有網絡視頻流不能正常傳輸。
解決方法,把視頻流的傳輸模式強制成tcp傳輸:

……

// Open video file

pFormatCtx = avformat_alloc_context();  

//有三種傳輸方式:tcp udp_multicast udp,強制采用tcp傳輸

AVDictionary* options = NULL;

av_dict_set(&options, "rtsp_transport", "tcp", 0);

if(avformat_open_input(&pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding],                              NULL, &options) != 0) {

    av_log(NULL, AV_LOG_ERROR, "Couldn't open file\n");

    goto initError;

}

// Retrieve stream information

if(avformat_find_stream_info(pFormatCtx,NULL) < 0) {

    av_log(NULL, AV_LOG_ERROR, "Couldn't find stream information\n");

    goto initError;

    }
……

問題解決。iOS使用ffmpeg播放rstp實時監(jiān)控視頻數據流

    本站是提供個人知識管理的網絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多