我正在使用 c# 中的 Xabe/ffmpeg 将流从摄像头 ip 转发到 api 客户端。在本地:一切正常。
在 api 服务器(转换完成的地方)上,针对同一台相机:我收到错误“无效文件”。我调查了一下,发现 xabe/ffmpeg 使用 ffprobe 获取媒体信息,并且在执行此操作时返回错误。
我尝试运行此命令来查看 Xabe/ffmpeg 代码背后发生了什么:
ffprobe -loglevel repeat+48 rtsp://user:password@cameraIp/axis-media/media.amp
当我运行此命令时,结果如下:
ffprobe version 2022-01-13-git-c936c319bd-full_build-www.gyan.dev Copyright (c) 2007-2022 the FFmpeg developers
built with gcc 11.2.0 (Rev5, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
libavutil 57. 18.100 / 57. 18.100
libavcodec 59. 20.100 / 59. 20.100
libavformat 59. 17.100 / 59. 17.100
libavdevice 59. 5.100 / 59. 5.100
libavfilter 8. 25.100 / 8. 25.100
libswscale 6. 5.100 / 6. 5.100
libswresample 4. 4.100 / 4. 4.100
libpostproc 56. 4.100 / 56. 4.100
[tcp @ 00000254c6f9fd80] No default whitelist set
[tcp @ 00000254c6f9fd80] Original list of addresses:
[tcp @ 00000254c6f9fd80] Address 10.XXX.XXX.XXX port 554
[tcp @ 00000254c6f9fd80] Interleaved list of addresses:
[tcp @ 00000254c6f9fd80] Address 10.XXX.XXX.XXX port 554
[tcp @ 00000254c6f9fd80] Starting connection attempt to 10.XXX.XXX.XXX port 554
[tcp @ 00000254c6f9fd80] Successfully connected to 10.XXX.XXX.XXX port 554
[rtsp @ 00000254c53290c0] SDP:
v=0
o=- 4002621882817261199 1 IN IP4 10.XXX.XXX.XXX
s=Session streamed with GStreamer
i=rtsp-server
t=0 0
a=tool:GStreamer
a=type:broadcast
a=range:npt=now-
a=control:rtsp://10.XXX.XXX.XXX:554/axis-media/media.amp
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:50000
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=640029;sprop-parameter-sets=Z2QAKa0AxSAUAKGwFuAgIDSDxIio,aO48sA==
a=control:rtsp://10.XXX.XXX.XXX:554/axis-media/media.amp/stream=0
a=framerate:13.000000
a=transform:1.000000,0.000000,0.000000;0.000000,1.000000,0.000000;0.000000,0.000000,1.000000
[rtsp @ 00000254c53290c0] video codec set to: h264
[rtsp @ 00000254c53290c0] RTP Packetization Mode: 1
[rtsp @ 00000254c53290c0] RTP Profile IDC: 64 Profile IOP: 0 Level: 29
[rtsp @ 00000254c53290c0] Extradata set to 00000254c6fa5080 (size: 33)
[rtp @ 00000254c6fa2780] No default whitelist set
[udp @ 00000254c6fa2840] No default whitelist set
[udp @ 00000254c6fa2840] end receive buffer size reported is 393216
[udp @ 00000254c6fa2940] No default whitelist set
[udp @ 00000254c6fa2940] end receive buffer size reported is 393216
[rtsp @ 00000254c53290c0] setting jitter buffer size to 500
[rtsp @ 00000254c53290c0] hello state=0
[h264 @ 00000254c6fa4b40] nal_unit_type: 7(SPS), nal_ref_idc: 3
[h264 @ 00000254c6fa4b40] nal_unit_type: 8(PPS), nal_ref_idc: 3
这行之后什么都没发生。没有错误,没有提示。我只能用 ctrl+c 取消任务。
我查看了 ffprobe 文档,但没有找到类似情况。这可能是 Xabe/ffmpeg 返回错误的原因。
有人有办法解决、调试、找到一些东西吗?Ffmpeg 在 Windows 服务器上兼容吗?
编辑
我尝试通过指定流的格式来绕过 ffprobe,但同样的事情发生了:ffmpeg 在达到[h264 @ 00000254c6fa4b40] nal_unit_type: 8(PPS), nal_ref_idc: 3
答案1
好吧,经过两天的搜索:问题是服务器上不允许使用 udp 协议。只有 TCP 可用。解决方案:
添加:
-rtsp_传输 tcp
因此命令行如下所示:
ffprobe -loglevel repeat+48 -rtsp_transport tcp rtsp://user:password@cameraIp/axis-media/media.amp