iptables
主機上應如何配置以允許來自透過網路介面發起連線的訪客rtsp://
的流量?KVM
NAT
這看起來並不是一個簡單的映射。我不知道訪客打開與 rtsp 流的連接時使用哪個連接埠。它可能是隨機的。例如,當 kvm guest 嘗試連接到連接埠 30110 上執行的 rtsp 流時,它可能會使用連接埠 48000。似乎沒有達到該客戶機上的48000 或它使用的任何隨機連接埠。不知道哪裡的交通正在消失。
如果我需要允許傳入連接到特定端口,我可以使用/etc/libvirt/hooks/qemu
bash 來執行以下操作:
if [ "${1}" = "name" ]; then # Update the following variables to fit your setup
GUEST_IP=192.168.12.55
GUEST_PORT=55555
HOST_PORT=55555
if [ "${2}" = "stopped" ] || [ "${2}" = "reconnect" ]; then
/sbin/iptables -D FORWARD -o virbr0 -d $GUEST_IP -j ACCEPT
/sbin/iptables -t nat -D PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
fi
if [ "${2}" = "start" ] || [ "${2}" = "reconnect" ]; then
/sbin/iptables -I FORWARD -o virbr0 -d $GUEST_IP -j ACCEPT
/sbin/iptables -t nat -I PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
fi
fi
這是可行的,但由於某種原因,我無法找到一種方法來允許kvm 來賓透過NAT 連接並接收來自rtsp 流的數據,儘管流量據稱是由NAT 介面轉發的,用於源自來賓的流量。
有人知道需要做什麼嗎?
ffmpeg -i rtsp://{STREAM_URL} -acodec copy -vcodec copy temp.mp4
ffmpeg version 4.1.3-0york1~16.04 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.11) 20160609
configuration: --prefix=/usr --extra-version='0york1~16.04' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-nonfree --enable-libfdk-aac --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 22.100 / 56. 22.100
libavcodec 58. 35.100 / 58. 35.100
libavformat 58. 20.100 / 58. 20.100
libavdevice 58. 5.100 / 58. 5.100
libavfilter 7. 40.101 / 7. 40.101
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 3.100 / 5. 3.100
libswresample 3. 3.100 / 3. 3.100
libpostproc 55. 3.100 / 55. 3.100
[rtsp @ 0x557cc99ec240] UDP timeout, retrying with TCP
[rtsp @ 0x557cc99ec240] Could not find codec parameters for stream 0 (Video: h264, none, 1920x1080): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://{STREAM_URL}':
Metadata:
title : 10
Duration: N/A, bitrate: 64 kb/s
Stream #0:0: Video: h264, none, 1920x1080, 90k tbr, 90k tbn, 180k tbc
Stream #0:1: Audio: pcm_alaw, 8000 Hz, mono, s16, 64 kb/s
File 'temp.mp4' already exists. Overwrite ? [y/N] y
[mp4 @ 0x557cc9a00000] Could not find tag for codec pcm_alaw in stream #1, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
相同的 RTSP url 在我的家用電腦上的 VLC 上運作良好。