一、编译针对iOS平台的ffmpeg库(kxmovie)
近期有一个项目,需要播放各种格式的音频、视频以及网络摄像头实时监控的视频流数据,经过多种折腾之后,最后选择了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
三、碰到的问题
播放本地视频和网络视频正常,播放网络摄像头实时监控视频流(h264)的时候出现错误:
[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获取流信息失败的时候的时候触发。 if(avformat_find_stream_info(pFormatCtx,NULL) < 0) { } 经过几天的摸索,最终确定是网络的问题(在模拟器播放一直出错,在3G网络下能播放
![]() 解决方法,把视频流的传输模式强制成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) { ……
问题解决。
![]() |
|