最近编写ffmpeg推流时,采用到域名进行推流,发现用域名经常会在avio_open 里阻塞很久,而且失败率也很高。而用ip则不会。
失败的话会出现:
[tcp @ 0x7f5d24045000] Failed to resolve hostname xxx.xxx.com: Temporary failure in name resolution
[rtmp @ 0x7f5d24045f40] Cannot open connection tcp://xxx.xxx.com:1935
搜了很多关于解决avio_open 失败的很多方法也无法解决。
最终搜了下Temporary failure in name resolution
然后得出了答案 https://www.mobibrw.com/2017/6092
解决方法就是,编辑域名配置文件
# vim /etc/resolv.conf
添加一个域名解析服务器即可
nameserver 114.114.114.114
现在avio_open打开域名就很快了