首先,我将解释我想要实现的目标,因为可能还有更好的方法来实现这一目标。我正在考虑让两个流工作,一个是推送到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而不是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延迟流就像一个魔咒,没有任何问题,但直播流随机停止与更新标题错误,我还没有能够自己触发它,它只是随机发生!
提前感谢!
发布于 2019-11-09 07:28:45
我最终只是简单地将流推送到另一个应用程序。出于某种原因,我认为这是不允许的..。所以我的配置现在看起来是这样的:
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
}
}我刚刚使用start.sh在python脚本中运行了延迟流,并使用rtmp://localhost:1935/live/stream_key在vlc中打开了实况流
https://stackoverflow.com/questions/58749459
复制相似问题