重播另一个Nginx rtmp流

首先,我将解释我要实现的目标,因为可能会有更好的方法来实现这一目标。 我正在使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。我还向实时流ffmpeg调用中添加了-analyzeduration 2147483647 -probesize 2147483647,以避免以前遇到的编解码器错误。

我使用的完整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

延迟流的工作原理很不错,没有任何问题,但是实时流随更新报头错误而随机停止,我自己无法触发,只是随机发生!

谢谢!

fandly_jw 回答:重播另一个Nginx 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;

       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://www.f2er.com/3144626.html

大家都在问