重新分段另一个nginx rtmp流

2024-05-21 04:02:33 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我将解释我想要实现的目标,因为可能还有更好的方法来实现这一目标。 我正在考虑使两个流工作,一个正在推动抽搐电视youtube有延迟,另一个是直播的(没有延迟),可以用VLC或其他什么来观看。在

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

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

以前,我有“找不到编解码器参数”错误,但我通过在ffmpeg命令中添加以下内容来解决它:

^{pr2}$

我已经做的是:

我在我的nginx.conf公司在

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

延迟流的工作方式像一个魅力,没有任何问题,但直播流随机停止与更新头错误,我自己无法触发它,它只是随机发生!在

提前谢谢!在


Tags: topylivestreamon错误编解码器with
1条回答
网友
1楼 · 发布于 2024-05-21 04:02:33

最后我只是简单地将stream推送到另一个应用程序。不知为什么,我以为这是不允许的。。。所以我的配置现在是这样的:

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脚本运行了delay stream并使用start.sh在vlc中打开了live stream

相关问题 更多 >