![Android TCP 错误无法从静态库解析主机名](https://linux22.com/image/1511694/Android%20TCP%20%E9%94%99%E8%AF%AF%E6%97%A0%E6%B3%95%E4%BB%8E%E9%9D%99%E6%80%81%E5%BA%93%E8%A7%A3%E6%9E%90%E4%B8%BB%E6%9C%BA%E5%90%8D.png)
我在 android 上使用 ffmpeg,遇到了一个错误,但在使用 Linux VM 上的库时不会出现该错误。我使用的是 FFmpeg Static Builds,来自这里。我在模拟器和 Linux VM 上使用稳定的 3.1.5 x86_64 版本。
我使用的模拟器是 genymotion API 22 nexus 6p,linux vm 是 ubuntu 16.04。这个问题也发生在我的实体手机上,即运行 cyanogenmod 6、API 22 的 nexus 5。
Android 日志:
ffmpeg version 3.1.5-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.1 (Debian 5.4.1-2) 20160904
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libebur128 --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
[tcp @ 0x4029cc0] Failed to resolve hostname r8---sn-ivuoxu-ua8l.googlevideo.com: Name or service not known
https://r8---sn-ivuoxu-ua8l.googlevideo.com/videoplayback?mime=video/mp4&ipbits=0&ratebypass=yes&requiressl=yes&dur=338.175&ms=au&mt=1477750809&fexp=9446761&mv=m&itag=22&mm=31&mn=sn-ivuoxu-ua8l&key=yt6&id=o-ANbaVtkKQuOcWMW9UrYRp47rRSKKc-1d3AGaTRwYVS6z&expire=1477772565&pcm2cms=yes&ip=5.29.246.6&lmt=1470910909244041&ei=tbAUWJvkHsjIiwahzIu4AQ&pl=26&source=youtube&sparams=dur,ei,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pcm2cms,pl,ratebypass,requiressl,source,upn,expire&initcwndbps=2532500&upn=jtb8x3K3rqs&signature=D1E8DF4167175F11BE67DE0141B459715047AFDD.69E5499B1345F3A7F2AB4B938F6C05055C3144AB: Input/output error
以下是来自 Linux VM 的日志:
ffmpeg version 3.1.5-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 5.4.1 (Debian 5.4.1-2) 20160904
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libebur128 --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
libavutil 55. 28.100 / 55. 28.100
libavcodec 57. 48.101 / 57. 48.101
libavformat 57. 41.100 / 57. 41.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 47.100 / 6. 47.100
libswscale 4. 1.100 / 4. 1.100
libswresample 2. 1.100 / 2. 1.100
libpostproc 54. 0.100 / 54. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://r8---sn-ivuoxu-ua8l.googlevideo.com/videoplayback?mime=video/mp4&ipbits=0&ratebypass=yes&requiressl=yes&dur=338.175&ms=au&mt=1477750809&fexp=9446761&mv=m&itag=22&mm=31&mn=sn-ivuoxu-ua8l&key=yt6&id=o-ANbaVtkKQuOcWMW9UrYRp47rRSKKc-1d3AGaTRwYVS6z&expire=1477772565&pcm2cms=yes&ip=5.29.246.6&lmt=1470910909244041&ei=tbAUWJvkHsjIiwahzIu4AQ&pl=26&source=youtube&sparams=dur,ei,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pcm2cms,pl,ratebypass,requiressl,source,upn,expire&initcwndbps=2532500&upn=jtb8x3K3rqs&signature=D1E8DF4167175F11BE67DE0141B459715047AFDD.69E5499B1345F3A7F2AB4B938F6C05055C3144AB':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2016-08-11 10:21:33
Duration: 00:05:38.13, start: 0.000000, bitrate: 555 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 426 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
Metadata:
creation_time : 2016-08-11 10:21:33
handler_name : ISO Media file produced by Google Inc.
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)
Metadata:
creation_time : 2016-08-11 10:21:33
handler_name : ISO Media file produced by Google Inc.
[ipod @ 0x5264580] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, ipod, to 'output.m4a':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf57.41.100
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, 125 kb/s (default)
Metadata:
creation_time : 2016-08-11 10:21:33
handler_name : ISO Media file produced by Google Inc.
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Press [q] to stop, [?] for help
size= 5241kB time=00:05:38.12 bitrate= 127.0kbits/s speed=35.4x
video:0kB audio:5184kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.112068%
我使用的命令:
./ffmpeg -i 'https://r8---sn-ivuoxu-ua8l.googlevideo.com/videoplayback?mime=video/mp4&ipbits=0&ratebypass=yes&requiressl=yes&dur=338.175&ms=au&mt=1477750809&fexp=9446761&mv=m&itag=22&mm=31&mn=sn-ivuoxu-ua8l&key=yt6&id=o-ANbaVtkKQuOcWMW9UrYRp47rRSKKc-1d3AGaTRwYVS6z&expire=1477772565&pcm2cms=yes&ip=5.29.246.6&lmt=1470910909244041&ei=tbAUWJvkHsjIiwahzIu4AQ&pl=26&source=youtube&sparams=dur,ei,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pcm2cms,pl,ratebypass,requiressl,source,upn,expire&initcwndbps=2532500&upn=jtb8x3K3rqs&signature=D1E8DF4167175F11BE67DE0141B459715047AFDD.69E5499B1345F3A7F2AB4B938F6C05055C3144AB' -vn -acodec copy output.m4a
我的问题是 Android 是否对静态库做了某种限制?是什么导致了这个问题?我尝试运行命令后立即 ping 主机没有问题,并且它工作正常!
ping -c 4 r8---sn-ivuoxu-ua8l.googlevideo.com
PING r8.sn-ivuoxu-ua8l.googlevideo.com (213.57.23.19) 56(84) bytes of data.
64 bytes from 213.57.23.19: icmp_seq=1 ttl=57 time=12.6 ms
64 bytes from 213.57.23.19: icmp_seq=2 ttl=57 time=22.3 ms
64 bytes from 213.57.23.19: icmp_seq=3 ttl=57 time=23.1 ms
64 bytes from 213.57.23.19: icmp_seq=4 ttl=57 time=27.1 ms
--- r8.sn-ivuoxu-ua8l.googlevideo.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 12.689/21.322/27.103/5.300 ms
我在测试中得出了一些观察:
- 问题不在于互联网,因为我可以立即 ping 主机而没有任何问题。
- 问题不在于网址,我尝试过这个,但还是出现了同样的错误
https://video-cdn.buzzfeed.com/13800/mp4_640x640/1478210253
- 该库在 Linux VM 上运行良好,但在 Android 上却不行,这可能是实现(肯定不是)、打包(可能)或 Android 本身的错误。
主要编辑:
我刚刚重新阅读了该库的自述文件并注意到了这一点:
A limitation of statically linking glibc is the loss of DNS resolution. Installing
nscd through your package manager will fix this or you can use
"ffmpeg -i http://<ip address here>/" instead of "ffmpeg -i http://example.com/"
我从 C# 中找到了此函数,它可能满足我的需要:DNS 查找 msdn