ffmpeg+easydarwin+httpserver搭建rtsp server

原文链接:https://blog.csdn.net/qq_32439563/article/details/85079183

一、环境准备

1、安装ffmpeg+h264编码器,ffmpeg下载地址:ffmpeg-3.4.4.tar.gz ,版本releases:http://ffmpeg.org/releases/

  • h264编码器安装:libx264下载:git clone git://git.videolan.org/x264.git
  • 进入x264目录,执行 ./configure --enable-shared --enable-static ,然后make && sudo make install
  • 下载ffmpeg,解压,进入ffmpeg目录,执行./configure --enable-gpl --enable-libx264 --prefix=/disk1/guoyiman/rtsp/ffmpeg/3.4.4 ,然后 make && sudo make install 
  • 安装结束进入/disk1/guoyiman/rtsp/ffmpeg/3.4.4 执行./ffmpeg --help,出现问题,./ffmpeg: error while loading shared libraries: libx264.so.157 ...
  • 问题原因:程序运行的时候默认是去/usr/lib下找libxxx.so,但是我们之前安装的确实在/usr/local/lib下,所以造成报错
  • 问题解决:到/etc/ld.so.conf所在文件夹;操作echo "include /usr/local/lib" >> /etc/ld.so.conf,sudo ldconfig   
  • 执行./ffmpeg --help,问题解决

2、安装easydarwin,下载地址:EasyDarwin-linux-8.1.0-1811292237.tar.gz

二、启动rtsp server

1、解压打开EasyDarwin文件夹,在 easydarwin.ini中可修改rtsp推流拉流服务端口,服务界面用户密码和端口号;

sh start.sh 运行EasyDarwin,  sh stop.sh停止EasyDarwin; 也可./easydarwin 运行

[http]
port=10008      #服务界面端口
default_username=admin    #用户名
default_password=admin    #用户密码

[rtsp]
port=9990        #rtsp server端口
timeout=28800
gop_cache_enable=1
save_stream_to_mp4=0


2、使用ffmpeg推流

  • rtsp推流地址: rtsp://hostname:port/testname 注:testname为流名称可更改
  • ffmpeg推流:ffmpeg -re -i "jin_all.mp4" -rtsp_transport tcp -vcodec libx264  -f rtsp rtsp://10.200.20.56:9990/test
  • ffmpeg推流:setsid ./ffmpeg -re -stream_loop -1 -i /root/test.mp4 -rtsp_transport tcp -vcodec copy -f rtsp rtsp://ip:port/test.sdp &

3、vlc拉流:

  • 拉流地址:rtsp://hostname:port/testname , 注:testname与推流一致

二、启动http-server

from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
import time

class S(BaseHTTPRequestHandler):
    def do_HEAD(self):
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        self.end_headers()

    def do_GET(self):
        paths = {
            '/url': {'status': 200},
        }

        if self.path in paths:
            self.respond(paths[self.path])
        else:
            self.respond({'status': 500})
        logging.info("GET request,\nPath: %s\nHeaders:\n%s\n", str(self.path), str(self.headers))

    def do_POST(self):
        content_length = int(self.headers['Content-Length']) # <--- Gets the size of data
        post_data = self.rfile.read(content_length) # <--- Gets the data itself

        logging.info("POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n",
                str(self.path), str(self.headers), post_data.decode('utf-8'))

        self.do_HEAD()

    def respond(self, opts):
        response = self.handle_http(opts['status'], self.path)
        self.wfile.write(response)

    def handle_http(self, status_code, path):
        self.send_response(status_code)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        try:
            id = path.split("?")[1].split("=")[1]
        except:
            id = ""
        print(path)
        time.sleep(30)
        content = '''
           {"url": "rtsp://ip:port/test.sdp", "id": %s}
           ''' % (id)
        return bytes(content, 'UTF-8')

def run(server_class=HTTPServer, handler_class=S, port=10080):
    logging.basicConfig(level=logging.INFO)
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    logging.info('Starting httpd...\n')
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    logging.info('Stopping httpd...\n')

if __name__ == '__main__':
    from sys import argv

    if len(argv) == 2:
        run(port=int(argv[1]))
    else:
        run()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值