|
一、編譯針對iOS平臺的ffmpeg庫(kxmovie)
近期有一個項目,需要播放各種格式的音頻、視頻以及網絡攝像頭實時監(jiān)控的視頻流數據,經過多種折騰之后,最后選擇了kxmovie,kxmovie項目已經整合了ffmpeg和簡單的播放器,具體可以參考kxmovie主頁:https://github.com/kolyvan/kxmovie
編譯kxmovie很簡單,已經支持iOS
6.1
二、使用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.播放視頻:
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) { } 經過幾天的摸索,最終確定是網絡的問題(在模擬器播放一直出錯,在3G網絡下能播放
),具體原因估計是rstp視頻流,程序默認采用udp傳輸或者組播,導致在私有網絡視頻流不能正常傳輸。解決方法,把視頻流的傳輸模式強制成tcp傳輸:
…… // Open video file
pFormatCtx =
avformat_alloc_context(); //有三種傳輸方式:tcp AVDictionary*
options = av_dict_set(&options, "rtsp_transport", "tcp", 0);
if(avformat_open_input(&pFormatCtx, [moviePath
cStringUsingEncoding:NSASCIIStringEncoding], } // Retrieve stream information if(avformat_find_stream_info(pFormatCtx,NULL) < 0) { ……
問題解決。
![]() |
|
|