avformat_find_stream_info函数卡住问题

问题:初始化RTSP流时,在android设备上卡住在avformat_find_stream_info函数,然后程序崩溃。

但其他URL没问题,且同样在代码在iOS上没问题,由于jni调试,也没看到ffmepg打印什么异常信息出来,而IOS上可以看到如下打印信息

[objc] view plaincopy
 
  1. avformat_open_input ret= 0  
  2. UDP timeout, retrying with TCP  

看到这个当时竟然没反应过来,知道看到参考链接说明才发现。

代码如下:

[objc] view plaincopy
 
  1. av_register_all();  
  2. av_log_set_level(AV_LOG_DEBUG);  
  3. av_log_set_callback(log_callback);  
  4. avformat_network_init();  
  5. ret = avformat_open_input(&formatCtx, url, NULL, NULL);  
  6. NSLog(@" avformat_open_input ret= %d", ret);  
  7. if (ret < 0) {  
  8.     NSLog(@" avformat_open_input error= %d", ret);  
  9.     return  ret ;  
  10. }  
  11. ret = avformat_find_stream_info(formatCtx,  NULL);//在此卡住了,  
  12. NSLog(@" avformat_find_stream_info ret= %d", ret);  
  13. if (ret < 0) {  
  14.     NSLog(@" avformat_find_stream_info error= %d", ret);  
  15.     return  ret;  
  16. }  

解决方法:

指定为TCP传输。

[objc] view plaincopy
 
  1. AVDictionary* options = NULL;  
  2. av_dict_set(&options, "rtsp_transport", "tcp", 0);  
  3. ret = avformat_open_input(&formatCtx, url, NULL, &options);  




参考链接:

http://www.bkjia.com/IOSjc/874706.html

 转载:http://blog.csdn.net/fb731666148/article/details/44408379

原文地址:https://www.cnblogs.com/canphp/p/4475807.html