视频文件自动转rtsp流

栏目: IT技术 · 发布时间: 5年前

内容简介:最近碰到一个项目需要用到 rtsp 视频流做测试, 由于真实环境的 摄像头 并不能满足需求,故尝试了一下用本地视频文件转换成rtsp视频流做测试,记录一下~采用方案: Docker + EasyDarwin + FFmpeg准备工作:

最近碰到一个项目需要用到 rtsp 视频流做测试, 由于真实环境的 摄像头 并不能满足需求,故尝试了一下用本地视频文件转换成rtsp视频流做测试,记录一下~

采用方案: Docker + EasyDarwin + FFmpeg

准备工作:

1. 创建一个文件夹 easydarwin

2. cd easydarwin

3. wget https://github.com/EasyDarwin/EasyDarwin/releases/download/v8.1.0/EasyDarwin-linux-8.1.0-1901141151.tar.gz  (下载EasyDarwin 软件包)

4. 创建: Dockerfile

5. 将easydarwin 的配置文件 也放到此目录下: easydarwin.xml

6. 创建一个自动转换 /root/video 目录下的视频文件成rtsp 流的 shell 脚本: start.sh

编写Dockerfile:

FROM centos:latest
USER root

COPY ./EasyDarwin-linux-8.1.0-1901141151.tar.gz /EasyDarwin-linux-8.1.0-1901141151.tar.gz
COPY ./start.sh /start.sh
RUN mkdir -p /etc/streaming/
COPY ./easydarwin.xml /etc/streaming/easydarwin.xml
RUN yum -y install tar \
        && yum -y install gcc automake autoconf libtool make wget

RUN  gzip -d /EasyDarwin-linux-8.1.0-1901141151.tar.gz \
        && tar -xf /EasyDarwin-linux-8.1.0-1901141151.tar \
        && mv EasyDarwin-linux-8.1.0-1901141151 EasyDarwin \
	&& cd /

RUN wget https://ffmpeg.org/releases/ffmpeg-4.1.5.tar.xz \
                && tar -xf ffmpeg-4.1.5.tar.xz \
        && cd ffmpeg-4.1.5 \
                && curl -O -L http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz \
        && tar -xf yasm-1.3.0.tar.gz \
        && cd yasm-1.3.0 \
        && ./configure \
        && make \
        && make install \
        && cd /

RUN cd /ffmpeg-4.1.5 \
            && ./configure \
        && make \
        && make install \
        && cd /

ENTRYPOINT /start.sh

编写start.sh

#!/bin/sh
cnt=`ps -ef | grep "[e]asydarwin" | wc -l`
if [ $cnt -lt 1 ];then
	nohup /EasyDarwin/easydarwin &
fi
if [[ ! -d /video ]];then
	mkdir -p /video
fi

while true;do
for video in `ls /video`; do
	if [[ "$(ps -ef | grep "$video" | grep -v "grep" | wc -l | tr -d ' ' )" = "1" ]]; then
				echo "Safe $video"
	else
		short_name=`echo $video | cut -d '.' -f 1`
		nohup /ffmpeg-4.1.5/ffmpeg -re -stream_loop -1 -i /video/$video -vcodec copy -rtsp_transport tcp  -f rtsp rtsp://localhost/$short_name &
		echo "Started $video"
	fi
done

sleep 1m
done

用途说明:

Dockerfile将我们需要的环境准备好,包括安装编译安装EasyDarwin以及需要的依赖包, FFmpeg等, 最后运行 start.sh. 注意 Docker 中 ENTRYPOINT 和 CMD 命令的用法区别。

start.sh 用来启动EasyEarwin,并每隔1分钟查看 /root/video 目录下的视频文件,如果有新文件,就会自动使用ffmpeg 转为rtsp流, 地址为 rtsp://localhost/short_name, 其中localhost使用时改成服务器的IP地址,short_name 为 当前食品文件的文件名(去掉扩展名, 如: video.mp4 的 short_name 为 video)

最后打包镜像,然后运行container, 可以在 easydarwin 目录的同级别创建 启动脚本: easydarwin.sh

#!/bin/bash
easy=`ls ./easydarwin/*.gz | wc -l`
if [[ $easy -lt 1 ]];then
        wget https://github.com/EasyDarwin/EasyDarwin/releases/download/v8.1.0/EasyDarwin-linux-8.1.0-1901141151.tar.gz
        mv EasyDarwin-linux-8.1.0-1901141151.tar.gz ./easydarwin
fi
local_img=`docker images | grep "[e]asydarwin" | wc -l`
if [ $local_img -lt 1 ];then
        cd easydarwin
        docker build -t easydarwin_qa . --no-cache
        cd ..
fi

#挂载host 的 /root/video 到 container 的对应路径
docker run -dit --net host --restart=always --name easy_qa -v /root/video:/video easydarwin_qa

所以只需在装了docker的服务器上启动此shell就可以: bash easydarwin.sh


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Iterative Methods for Sparse Linear Systems, Second Edition

Iterative Methods for Sparse Linear Systems, Second Edition

Yousef Saad / Society for Industrial and Applied Mathematics / 2003-04-30 / USD 102.00

Tremendous progress has been made in the scientific and engineering disciplines regarding the use of iterative methods for linear systems. The size and complexity of linear and nonlinear systems arisi......一起来看看 《Iterative Methods for Sparse Linear Systems, Second Edition》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码