ffmpeg 流媒体 UDP 端口已关闭

ffmpeg 流媒体 UDP 端口已关闭

我正在尝试使用 ffmpeg 将 RTSP 流从 CCTV 转码为 HLS 流,以便可以通过 Web 服务器访问它。

使用 ffmpeg 从 CCTV 流式传输视频,命令如下

$ ffmpeg -i "rtsp://cam-1.loc:554?user=admin&password=admin&channel=1&stream=0" -hls_time 3 -hls_wrap 10 -f mpegts udp://localhost:6601
ffmpeg version 4.2.8 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 8 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[rtsp @ 0x5576c7340600] getaddrinfo(cam-1.loc): Name or service not known
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://cam-1.loc:554?user=admin&password=admin&channel=1&stream=0':
  Metadata:
    title           : RTSP Session
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1920x1080, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mpeg2video (native))
  Stream #0:1 -> #0:1 (pcm_alaw (native) -> mp2 (native))
Press [q] to stop, [?] for help
Output #0, mpegts, to 'udp://localhost:6601':
  Metadata:
    title           : RTSP Session
    encoder         : Lavf58.29.100
    Stream #0:0: Video: mpeg2video (Main), yuv420p, 1920x1080, q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.54.100 mpeg2video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1: Audio: mp2, 16000 Hz, mono, s16, 160 kb/s
    Metadata:
      encoder         : Lavc58.54.100 mp2
[rtsp @ 0x5576c7340600] max delay reached. need to consume packette=5338.9kbits/s dup=0 drop=5 speed=1.12x    
[rtsp @ 0x5576c7340600] RTP: missed 3 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 6 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 6 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 5 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 4 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 5 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 6 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 5 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 6 packets
[h264 @ 0x5576c7993c80] concealing 972 DC, 972 AC, 972 MV errors in I frame
rtsp://cam-1.loc:554?user=admin&password=admin&channel=1&stream=0: corrupt decoded frame in stream 0=1.11x    
[rtsp @ 0x5576c7340600] max delay reached. need to consume packette=5298.4kbits/s dup=0 drop=5 speed=1.02x    
[rtsp @ 0x5576c7340600] RTP: missed 2 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 5 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 4 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 3 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 4 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 5 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 5 packets
[rtsp @ 0x5576c7340600] max delay reached. need to consume packet
[rtsp @ 0x5576c7340600] RTP: missed 2 packets
[h264 @ 0x5576c779b9c0] cabac decode of qscale diff failed at 66 60
[h264 @ 0x5576c779b9c0] error while decoding MB 66 60, bytestream 9825
[h264 @ 0x5576c779b9c0] concealing 943 DC, 943 AC, 943 MV errors in I frame
rtsp://cam-1.loc:554?user=admin&password=admin&channel=1&stream=0: corrupt decoded frame in stream 0=1.02x    
frame= 1315 fps= 25 q=31.0 Lsize=   34249kB time=00:00:53.32 bitrate=5261.8kbits/s dup=0 drop=5 speed=1.02x    
video:30544kB audio:1042kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.431973%

使用 nmap 检查 6601 端口是否开放

$ nmap -Pn localhost -p 6601
Starting Nmap 7.70 ( https://nmap.org ) at 2023-12-26 10:47 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0011s latency).
Other addresses for localhost (not scanned): ::1

PORT     STATE  SERVICE
6601/tcp closed mstmg-sstp

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds

但是,ffplayer 能够播放视频流

ffplay udp://localhost:6601
ffplay version 4.2.8 Copyright (c) 2003-2022 the FFmpeg developers
  built with gcc 8 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mpeg2video @ 0x7f1ad854afc0] Invalid frame dimensions 0x0. f=0/0   
    Last message repeated 7 times
Input #0, mpegts, from 'udp://localhost:6601':0KB sq=    0B f=0/0   
  Duration: N/A, start: 59.288000, bitrate: N/A
  Program 1 
    Metadata:
      service_name    : RTSP Session
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: mp2 ([4][0][0][0] / 0x0004), 16000 Hz, mono, s16p, 160 kb/s

VLC 无法播放视频流:

vlc udp://localhost:6601
VLC media player 3.0.18 Vetinari (revision )
[000055769aa81ba0] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[00007fec64011e90] mjpeg demux error: cannot peek

ffprobe 输出

ffprobe udp://localhost:6601
ffprobe version 4.2.8 Copyright (c) 2007-2022 the FFmpeg developers
  built with gcc 8 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --extra-ldflags='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libaom --enable-libdav1d --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-libjack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librsvg --enable-libsrt --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-version3 --enable-vapoursynth --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[mpeg2video @ 0x55e1be0910c0] Invalid frame dimensions 0x0.
    Last message repeated 9 times
Input #0, mpegts, from 'udp://localhost:6601':
  Duration: N/A, start: 262.760000, bitrate: N/A
  Program 1 
    Metadata:
      service_name    : RTSP Session
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: mp2 ([4][0][0][0] / 0x0004), 16000 Hz, mono, s16p, 160 kb/s

为什么视频流无法在 VLC 中播放?

为什么 nmap 没有看到 UPD 端口是开放的?

答案1

nmap 默认不扫描 UDP 端口,需要指定此选项:—sU

UDP 扫描通过 -sU 选项激活。它可以与 TCP 扫描类型(如 SYN 扫描 (-sS))结合使用,以便在同一次运行中检查两种协议。

因此你的命令是:nmap -Pn -sU 本地主机 -p 6601

对于 VLC 问题,如果您使用基于 Debian 的系统,请在 VLC 论坛帖子中:

请注意,根据 Debian 政策,Debian VLC 版本不支持 RTSP。如果您需要 RTSP,请使用 Flatpak。

尝试通过 FlatPak 存储库安装 VLC。

相关内容