首页 > 其他分享 >iOS使用ffmpeg播放rstp实时监控视频数据流

iOS使用ffmpeg播放rstp实时监控视频数据流

时间:2022-12-27 10:33:53浏览次数:55  
标签:播放 rstp stream iOS avformat NULL kxmovie find ffmpeg


一、编译针对iOS平台的ffmpeg库(kxmovie)

近期有一个项目,需要播放各种格式的音频、视频以及网络摄像头实时监控的视频流数据,经过多种折腾之后,最后选择了kxmovie,kxmovie项目已经整合了ffmpeg和简单的播放器,具体可以参考kxmovie主页:​​https://github.com/kolyvan/kxmovie​​ 


编译kxmovie很简单,已经支持iOS 6.1 和 armv7s,一次成功,编译过程没出现什么问题:



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


三、碰到的问题


播放本地视频和网络视频正常,播放网络摄像头实时监控视频流(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) {

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

   goto initError;

}


经过几天的摸索,最终确定是网络的问题(在模拟器播放一直出错,在3G网络下能播放

iOS使用ffmpeg播放rstp实时监控视频数据流_ide

),具体原因估计是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, [moviePathcStringUsingEncoding: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;

  

……

标签:播放,rstp,stream,iOS,avformat,NULL,kxmovie,find,ffmpeg
From: https://blog.51cto.com/u_15923385/5971504

相关文章

  • ffmpeg裁剪视频和openpose生成骨架
    剪视频,剪掉25秒之前的视频ffmpeg-iEverybody.mp4-ss00:00:25-s512x288-c:acopyoutput.mp4每帧25个图片输出ffmpeg-ioutput.mp4-r25%5d.png转换avi......
  • axios、代理(proxy)简单使用
    axios简单使用例子importaxiosfrom'axios'exportdefault{name:'Test',data(){return{msg:"Welcome"}},mounted(){//get......
  • 在iOS中使用NSURLProtocol进行网络代理
    在iOS中使用NSURLProtocol进行网络代理一引言网络能力是互联网应用程序必不可少的功能。随着应用程序的复杂,对网络的依赖性也会逐渐增高。如何统一的处理请求头,统一的处理......
  • Axios + Mockjs
    Mock可以用来模拟服务端响应请求,让前端人员自己测试接口直接上案例:Axios//request.jsimportAxiosfrom'axios'//先创建一个axios实例,无需配置baseURL,只是模......
  • SDL_AudioSpec
    这篇主要讲把视频的声音播放出来audioStream=-1;for(i=0;i<pFormatCtx->nb_streams;i++){if(pFormatCtx->streams[i]->codec->codec_type==......
  • FFmpeg缩放swscale详解
    缩放:      利用ffmpeg进行图像数据格式的转换以及图片的缩放应用中,主要用到了swscale.h文件中的三个函数,分别是:structSwsContext*sws_getContext(int......
  • ffmpeg: ‘UINT64_C’ was not declared in this scope
    ffmpeg默认是用C文件来编译的,如果某个CPP文件想引用ffmpeg中的某些函数或者头文件,有可能出现‘UINT64_C’wasnotdeclaredinthisscope的错误情形大概如下Thesame......
  • vs中ffmpeg release版本崩溃问题
    vs2010win7下开发视频服务器,用到ffmpeg,debug版本运行正常,切换到release时,出现"0x00905a4d处未处理的异常:0xC0000005:读取位置0x00905a4d时发生访问冲突",原以......
  • ffmpeg一揽子
    avformat_alloc_output_context2()。在基于FFmpeg的视音频编码器程序中,该函数通常是第一个调用的函数(除了组件注册函数av_register_all())。avformat_alloc_output_context2......
  • 编译FFmpeg成一个SO库
    编译环境MacOSXCapitan10.11.3NDK-r10e(64-bit)FFmpeg3.0简介在看完了第一篇Android最简单的基于FFmpeg的例子(一)—编译FFmpeg类库的基础上再看这一篇,在......