ffmpeg 强制采用tcp传输

iOS使用ffmpeg播放rstp实时监控视频数据流_千寻_新浪博客

播放本地视频和网络视频正常,播放网络摄像头实时监控视频流(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(NULLAV_LOG_ERROR"Couldn't find stream information\n");

   goto initError;

}

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

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

),具体原因估计是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(NULLAV_LOG_ERROR"Couldn't open file\n");

   goto initError;

}

// Retrieve stream information

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

   av_log(NULLAV_LOG_ERROR"Couldn't find stream information\n");

   goto initError;

   }
……
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值