gpt4 book ai didi

python - 重新流式传输另一个 nginx rtmp 流

转载 作者:行者123 更新时间:2023-12-04 22:50:15 30 4
gpt4 key购买 nike

首先,我将解释我想要实现的目标,因为可能有更好的方法来实现这一目标。
我正在考虑让 2 个流工作,一个正在延迟推送到 twitch.tv 和 youtube,另一个是可以使用 VLC 或其他方式观看的直播(无延迟)。

我能够部分实现这一点,但“实时”流有时会随机中断并出现此错误:

Failed to update header with correct duration.
Failed to update header with correct filesize.

之前,我有“找不到编解码器参数”错误,但我通过将其添加到我的 ffmpeg 命令中解决了它:
-analyzeduration 2147483647 -probesize 2147483647

我已经做的是:

我在我的 nginx.conf 中制作了这些 rtmp 服务器和应用程序
rtmp {
server {
listen 1935;
chunk_size 4096;

application delay_live {
live on;
record off;
push_reconnect 500ms;

push rtmp://live-vie.twitch.tv/app/my_stream_key;
push rtmp://a.rtmp.youtube.com/live2/my_stream_key;

}

application live {
live on;
record off;
}

application delay {
live on;
record all;
record_path /tmp/nginx;

# Work with timestamp to know when to continue streaming
record_suffix .flv;
record_unique on;

# Work with signals to know when to continue streaming
#record_append on;

exec_publish sudo sh /home/start.sh;
}

exec_static mkdir /tmp/nginx; #Working dir. Must be consistend with the delayer.py
}
}

exec_publish我运行这个 .sh 脚本:
sudo screen -dmS delay bash -c "python /usr/local/nginx/sbin/delay/rtmp_stream_delayer.py; sleep 9999";
sleep 0.5;
sudo screen -dmS live bash -c "python /usr/local/nginx/sbin/live/rtmp_stream_live.py; sleep 9999";

这两个 python 脚本是从这个 git 稍微改变的脚本:

https://github.com/sistason/rtmp_stream_delayer
我改变的几件事是我使用 ffmpeg 而不是 avconv 来调用命令,并且在 rtmp_stream_live.py 内部我设置了与 rtmp_stream_delayer.py 相同的目录/文件(所以它基本上使用相同的 .flv 文件进行直播)。 rtmp_stream_live.py延迟设置为 0。我还添加了 -analyzeduration 2147483647 -probesize 2147483647到我的直播 ffmpeg 调用,以避免我以前遇到的编解码器错误。

我使用的完整 ffmpeg 调用:
rtmp_stream_delayer.py
subprocess.check_output('ffmpeg -re -i {0} -codec copy -f flv {1}'.format(filename, "rtmp://my_ip:port/delay_live").split())
rtmp_stream_live.py
subprocess.check_output('ffmpeg -re -analyzeduration 2147483647 -probesize 2147483647 -i /tmp/nginx/{0} -codec copy -f {1}'.format(filename, STREAM_DESTINATION).split())

我尝试添加这个 ffmpeg 标志,但它根本没有帮助(编解码器错误又回来了):
 flv -flvflags no_duration_filesize

延迟流就像一个魅力,没有任何问题,但实时流随机停止更新标题错误,我自己无法触发它,它只是随机发生!

提前致谢!

最佳答案

我最终只是将流推送到另一个应用程序。出于某种原因,我认为这是不允许的......所以我的配置现在看起来像这样:

rtmp {
server {
listen 1935;
chunk_size 4096;

application delay_live {
live on;
record off;
push_reconnect 500ms;

push rtmp://live-vie.twitch.tv/app/my_stream_key;
push rtmp://a.rtmp.youtube.com/live2/my_stream_key;

}

application live {
live on;
record off;
}

application delay {
live on;
record all;
record_path /tmp/nginx;

# Work with timestamp to know when to continue streaming
record_suffix .flv;
record_unique on;

# Work with signals to know when to continue streaming
#record_append on;

push rtmp://localhost:1935/live;
exec_publish sudo sh /home/start.sh;
}

exec_static mkdir /tmp/nginx; #Working dir. Must be consistend with the delayer.py
}
}

我刚刚使用我的 python 脚本运行延迟流 start.sh并使用 rtmp://localhost:1935/live/stream_key 在 vlc 中打开实时流

关于python - 重新流式传输另一个 nginx rtmp 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58749459/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com