首页 > 解决方案 > 在端口 1935 上提供 rtmp

问题描述

我一直在尝试让 ffmpeg 在 rtmp 中流式传输,但始终拒绝连接到端口 1935。我真的不知道我还能做些什么来允许这种连接。

这是我正在运行的规格。

这是我运行的脚本:

ffmpeg -i "test.mp4" -c:v copy -c:a copy -f flv "rtmp://127.0.0.1/stream/test"

我得到的错误是:

[tcp @ 0x55ff05ab8ce0] Connection to tcp://127.0.0.1:1935 failed: Connection refused

我已经进行了一些研究并浏览了许多有关 ffserver.conf 的帖子,并且我已经进行了这些更改,但仍然没有运气。这是我的配置文件。我也曾经使用这个配置运行过 ffserver 。




HTTPPort 8090
HTTPBindAddress 127.0.0.1
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -

<Feed feed1.ffm>

File /tmp/feed1.ffm
FileMaxSize 200K

# Only allow connections from localhost to the feed.
ACL allow 127.0.0.1
ACL allow localhost     
ACL allow 192.168.0.0 192.168.255.255
</Feed>

<Stream test1.mpg>

# coming from live feed 'feed1'
Feed feed1.ffm

Format mpeg
AudioBitRate 32

# Number of audio channels: 1 = mono, 2 = stereo
AudioChannels 2
AudioSampleRate 44100

# Bitrate for the video stream
VideoBitRate 64

# Ratecontrol buffer size
VideoBufferSize 40

# Number of frames per second
VideoFrameRate 3


</Stream>


<Stream test.asf>
Feed feed1.ffm
Format asf
VideoFrameRate 15
VideoSize 352x240
VideoBitRate 256
VideoBufferSize 40
VideoGopSize 30
AudioBitRate 64
StartSendOnKey
</Stream>

# Special streams

# Server status

<Stream stat.html>
Format status

ACL allow localhost
ACL allow 127.0.0.1
ACL allow 192.168.0.0 192.168.255.255

#FaviconURL http://pond1.gladstonefamily.net:8080/favicon.ico
</Stream>

<Redirect index.html>
URL http://www.ffmpeg.org/
</Redirect>

这是我的ufw状态:

--                         ------      ----
22/tcp                     ALLOW       Anywhere
22                         ALLOW       Anywhere
1935/tcp                   ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
22 (v6)                    ALLOW       Anywhere (v6)
1935/tcp (v6)              ALLOW       Anywhere (v6)

但仍然没有,我也在 iptables 中打开了端口,但没有运气。这是如何完成的:

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT

and

iptables -A OUTPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT

仍然一无所获,每次我运行 ffmpeg 我都会被拒绝连接。我之前安装了 nginx 只是为了测试但没有运气。

我在这里做错了什么?这个端口现在不是应该开放的吗?

谢谢

标签: nginxffmpegubuntu-18.04rtmp

解决方案


我想通了,我使用的是 Nginx RTMP 模块 - Nginx RTMP 出于某种原因在 Ubuntu 上运行不佳,但在 Alpine 3.8 上运行良好 - 一旦我启动 nginx rtmp docker 容器并暴露 1935 和 80,一切都开始正常工作。听听学习,永远不要在 ubuntu 上安装 nginx rtmp 模块。


推荐阅读