HTTP 媒体流服务器

9

我使用RED5媒体服务器(RTMP)开发了视频流应用程序。现在需要通过HTTP来直播视频。

有任何开源HTTP媒体服务器吗?

是否有支持RTMP和HTTP的开源服务器?

提前致谢。


说句实话,我已经用Node.js写了一个简单的服务器,它使用FFmpeg来实时重新编码视频以进行常规HTTP流媒体传输。它运行得非常好,而且代码不到20行。 - Brad
3个回答

11
首先,HTTP和RTMP是不同的协议。你不能在HTTP中服务RTMP。(虽然你可以使用隧道解决方案来做到这一点)。
有几种方法可以进行HTTP流媒体传输,如HLS、DASH、Smooth和Progressive Download。如果你需要向iOS(iPad、iPhone、Apple TV)提供流媒体服务,则需要使用HLS。
另外,正如arcyqwerty所说,任何HTTP服务器都可以提供HTTP流媒体服务。但你需要在提供服务之前准备好你的媒体文件和清单文件。
以下是一些关于HLS(HTTP Live Streaming)非常重要的链接: "What about open source servers. I know these:
- Flumotion: http://www.flumotion.net/ - Gstreamer Server Streaming: http://cgit.freedesktop.org/gstreamer/gst-streaming-server/ - Nginx HLS Module: http://nginx.org/en/docs/http/ngx_http_hls_module.html (Only Nginx Plus)
Or you can do like me and use GStreamer for segmenting and make manifest. And finaly I use the Nginx only to serve them.
I hope I helped you a little bit."

2
任何可以提供文件服务的HTTP服务器(如apache、nginx、IIS等)都可以通过HTTP“流式传输”媒体。因此,如果您希望,可以保留RED5用于RTMP,并设置一个HTTP服务器来提供相同的文件。
如果您需要单一产品解决方案,您可能需要查看有关协议的信息,例如媒体流基础知识- HTTP vs RTMP
将nginx-rtmp模块添加到nginx中可能是您正在寻找的解决方案。https://github.com/arut/nginx-rtmp-module

RED5是Flash媒体服务器。iPad设备不支持Flash。 - DIVAKAR SRINIVASAN
arcyqwerty@:有没有可用的开源http媒体服务器?如何通过http流式传输rtmp?有示例吗? - DIVAKAR SRINIVASAN
好的,你之前提到了RED5作为你目前的解决方案,所以我认为它符合你的要求。我预期iPad会有一些支持RTMP或HTTP流媒体的媒体播放器。 - arcyqwerty
如果RED5不能满足您的需求,可以考虑使用http://obsproject.com/index作为RTMP服务器。Nginx默认支持HTTP(作为Web服务器),我提到的模块应该可以添加RTMP支持。 - arcyqwerty

1
I use this and it works properly. (Ubuntu 12.04 TLS server)
逐步操作:
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev
wget http://nginx.org/download/nginx-1.6.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
tar -zxvf nginx-1.6.0.tar.gz
unzip master.zip
cd nginx-1.6.0

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master --with-http_flv_module --with-http_mp4_module
make
sudo make install

sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

NGINX配置文件:(/usr/local/nginx/conf/nginx.conf)
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

rtmp {
    server {
    listen 1935;
    chunk_size 4000;
    # video on demand for flv files
    application vod {
        play /var/flvs;
    }

    # video on demand for mp4 files
        application vod2 {
        play /var/mp4s;
        }
    }
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  192.168.52.16;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        # This URL provides RTMP statistics in XML
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            # XML stylesheet to view RTMP stats.
            # Copy stat.xsl wherever you want
            # and put the full directory path here
            root /var/www/;
        }

    location /hls {
        # Serve HLS fragments
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        alias /tmp/app;
        expires -1;
    }

#   location /hds {
#       f4f;    # Use the HDS handler to manage requests
#           # serve content from the following location
#       alias /var/www/video;
#   }

    location /video {
        mp4;
        flv;
        mp4_buffer_size     4M;
        mp4_max_buffer_size 10M;
    }

    location / {
        root   html;
        index  index.html index.htm;
    }

    error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
    }
}

保存配置文件并且:

sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

下一步... 创建两个目录:

mkdir /var/flvs
mkdir /var/mp4s

你需要将一个mp4文件复制到mp4s目录中。例如:sample.mp4
最后
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

尝试:

rtmp://your_server_ip/vod2/sample.mp4

(建议:您可以使用VLC媒体播放器)
或HTML代码
<html>
<head>
    <title>RTMP Video</title>
    <!-- flowplayer javascript component -->
    <script src="http://releases.flowplayer.org/js/flowplayer-3.2.12.min.js"></script>
</head>

<body>
<div id="player" style="width:644px;height:480;margin:0 auto;text-align:center">
    <img src="images/background.jpg" height="480" width="644" /></div>
<script>

$f("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.16.swf", {
    clip: {
        url: 'sample.mp4',
        scaling: 'fit',
        provider: 'hddn'
    },

    plugins: {
        hddn: {
            url: "swf/flowplayer.rtmp-3.2.13.swf",

            // netConnectionUrl defines where the streams are found
            netConnectionUrl: 'rtmp://your_server_ip:1935/vod2/'

        }
    },
    canvas: {
        backgroundGradient: 'none'
    }
});
</script>
</body>
</html>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接