静看光阴荏苒
不管不顾不问不说也不念

CentOS7部署云转码express-ffmpeg

我在之前推荐过几个做视频站用的程序,大多数都是具备ffmpeg转码功能的,但是在视频防盗链和加密这块,这些程序都很遗憾并没有相关的功能。

众所周知,一个规模庞大的视频站是绝对要把视频资源进行加密的,否则盗链等一系列问题的发生会导致服务器的带宽过度浪费。所以现在很多视频站都使用HLS(HTTP Live Streaming)技术加密自己的视频。简单点说HLS就是将一个完整的视频切分成多个ts格式的视频文件,当用户下载m3u8文件时,HLS通过m3u8文件内的索引地址来播放具体的每个ts格式的小段视频。

我觉得在国内大部分个人需要用到这种技术的,百分之90都是用来做X站的吧。。。所以,貌似没什么开源的方案可供选择,毕竟行业比较敏感,不过仔细找了一下,发现一个仅存的用nodejs开发的简易转码切片平台:express-ffmpeg

express-ffmpeg官网:http://ffmpeg.moejj.com

官方有比较详细的安装教程,不过是基于Ubuntu的,我这里写一个CentOS的教程,反正我最后搭建起来使用的话问题不大,但是这个程序总让我感觉有点“半成品”的味道。。。

先来关闭SELinux:

vi /etc/selinux/config

把SELINUX=后面的值改为disabled。

重启机器:

reboot

再来安装FFMPEG:

yum -y install epel-release
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
yum -y install ffmpeg
ffmpeg -version

再来安装nvm:

yum -y install wget git
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

安装完成之后断开Xshell,重新登录一次,使用nvm安装nodejs:

nvm install v8.7.0

nodejs安装完成之后,使用npm安装express和pm2:

npm install express -gd
npm install -g pm2

接下来安装mongodb数据库,新建一个源文件:

vi /etc/yum.repos.d/mongodb.repo

写入:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

然后yum直接安装:

yum -y install mongodb-org-server mongodb-org

再来安装一个Nginx,用来实现反向代理,还是新建一个源文件:

vi /etc/yum.repos.d/nginx.repo

写入:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

然后yum直接安装:

yum -y install nginx

启动并设置开机启动:

systemctl start nginx
systemctl enable nginx

现在我们来新建数据库存放目录

cd /
mkdir -p data/db
mkdir -p data/log

然后运行mongodb:

mongod --dbpath /data/db --fork --logpath /data/log/mongodb.log

进入命令行模式,添加用户:

mongo
use admin
use ffmpeg
db.createUser({user:"ffmpeg",pwd:"ffmpeg",roles:[{role:"readWrite",db:"ffmpeg"}]})
db.auth("ffmpeg","ffmpeg")

注:其中数据库名/账号/密码都是ffmpeg,各位这里可以自己修改,建议修改下密码即可。

完成之后按键盘组合键Ctrl+D退出来,接着查找mongodb运行的进程ID:

ps -ef | grep mongodb

杀之:

kill -9 对应你当前的进程ID

然后重新运行mongodb:

mongod -auth --bind_ip 127.0.0.1 --port 27017 --dbpath /data/db --fork --logpath /data/log/mongodb.log

接着我们拉取express-ffmpeg的项目文件,因为这个项目托管再gitee上面,国外服务器下载可能非常慢。

cd / && mkdir www
cd www
git clone https://gitee.com/quazero/express-ffmpeg
cd express-ffmpeg

新建配置文件目录:

mkdir config && cd config

新建配置文件:

vi auth.js

写入配置信息:

module.exports = {
    user: "admin",
    password: "设置一个你的管理员密码",
    db: "ffmpeg",
    dbuser: "ffmpeg",
    dbpassword: "ffmpeg"
};

注:其中db/dbuser/dbpassword都要对应我们之前创建的mongodb数据库。

安装程序所需依赖:

cd ..
npm install

现在就可以尝试运行项目了:

pm2 start bin/www -i 0

打开你的服务器公网IP+3000端口/admin,例如:127.0.0.1:3000/admin,能访问到如下图界面就说明基本正常:

现在我们配置Nginx的反向代理,首先进入到nginx的conf.d目录:

cd /etc/nginx/conf.d

新建一个站点配置文件:

vi yunzhuanma.conf

写入:

server {
    listen       80;
    server_name  你的站点域名;
    
location / {
    proxy_pass       http://127.0.0.1:3000;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Upgrade   $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version         1.1;
    proxy_redirect             off;
    }
}

然后重启Nginx:

systemctl restart nginx

现在你就可以直接使用域名来访问了。

如果服务器重启了,如何重新运行express-ffmpeg?

第一步查找mongodb进程ID:

ps -ef | grep mongo

杀掉:

kill -9 进程ID

重新运行:

mongod -auth --bind_ip 127.0.0.1 --port 27017 --dbpath /data/db --fork --logpath /data/log/mongodb.log

进入到express-ffmpeg根目录:

cd /www/express-ffmpeg

使用pm2再次运行即可:

pm2 start bin/www -i 0

现在使用我们创建的管理员账号登录到后台,首先点击“转码设置”,按如下图设置:

重要!不管你使不使用这个“域名分发”的功能,都要点一下“提交”按钮,否则之后上传的视频无法正常播放!

设置完成之后,我们就可以尝试上传一部视频来试试功能了:

上传完成之后,点击“电影库”,然后点击“转码并切片”:

转码以及切片完成后,点击分享链接,程序会给你一个视频地址,这个地址就是处理后的视频地址了,你可以把这个地址插入到你的其他站点中供人观看:

然后我就看了下这个骚的一匹的视频:

请开始你们的表演~

赞(2)
未经允许不得转载:荒岛 » CentOS7部署云转码express-ffmpeg
分享到: 更多 (0)

评论 40

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    老哥老哥,这个教程不错。我很欣赏,你把那个视频私我把

    GDS6年前 (2018-08-28) Google Chrome 68.0.3440.106 Google Chrome 68.0.3440.106 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 就一个40s的视频,我自己都还想找找出处是哪里。。。

      LALA6年前 (2018-08-29) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
  2. #2

    有没视频教程

    GML6年前 (2018-08-29) UC Browser 8.7 UC Browser 8.7 Windows 10 x64 Edition Windows 10 x64 Edition回复
  3. #3

    我按照教程搭建好了并且点击了转码并切片,等了几个小时还是waiting状态…….. :cry:

    拉拉肥6年前 (2018-08-29) Google Chrome 68.0.3440.106 Google Chrome 68.0.3440.106 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 叫我拉拉瘦,我告诉你解决办法,哈哈哈

      LALA6年前 (2018-08-30) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 拉拉兽,快点告诉我呗

        拉拉肥6年前 (2018-09-01) Google Chrome 68.0.3440.106 Google Chrome 68.0.3440.106 Windows 10 x64 Edition Windows 10 x64 Edition回复
  4. #4

    :smile: 这些图都哪儿找的啊

    瞎折腾6年前 (2018-08-30) Firefox 61.0 Firefox 61.0 Windows 10 x64 Edition Windows 10 x64 Edition回复
  5. #5

    楼主的服务器配置是什么

    kedyao6年前 (2018-08-30) Google Chrome 68.0.3440.106 Google Chrome 68.0.3440.106 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 我有很多服务器,不知道你说的哪台。。

      LALA6年前 (2018-08-30) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 我在这篇文章留言 就是问你搭建这个的服务器配置嘛 :razz:

        kedyao6年前 (2018-08-31) Google Chrome 68.0.3440.106 Google Chrome 68.0.3440.106 Windows 10 x64 Edition Windows 10 x64 Edition回复
        • 这台是我自己的独服开出来的VPS,忘记什么配置了,已经删了。。
          反正你记住生产环境搞转码切片一定要用独立服务器,并且CPU核心一定要多,最好组个双路U。

          LALA6年前 (2018-09-02) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
  6. #6

    老哥 可以做视频教程

    shb6年前 (2018-08-30) UC Browser 8.7 UC Browser 8.7 Windows 10 x64 Edition Windows 10 x64 Edition回复
  7. #7

    老哥 可不可以做视频教程 :neutral:

    shb6年前 (2018-08-30) UC Browser 8.7 UC Browser 8.7 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 发个红包,我给你录视频。。

      LALA6年前 (2018-08-30) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 怎么发红包,需要教程,大佬

        lalamao6年前 (2018-09-30) Google Chrome 63.0.3239.132 Google Chrome 63.0.3239.132 Windows 7 x64 Edition Windows 7 x64 Edition回复
        • 右下角+我QQ。

          LALA6年前 (2018-09-30) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
  8. #8

    这个杀死进程,这个进程有好几个 带数字的,搞不清楚是哪个!怎么看。lala :grin:

    lala大大6年前 (2018-09-01) QQbrowser 10.2.2243.400 QQbrowser 10.2.2243.400 Windows 8.1 x64 Edition Windows 8.1 x64 Edition回复
    • What?杀什么进程?这程序是直接用pm2管理的啊。。
      要杀掉全部进程直接:pm2 delete all

      LALA6年前 (2018-09-02) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
  9. #9

    lala快出来,给红包,帮我解决下问题!

    lala大大6年前 (2018-09-02) QQbrowser 10.2.2243.400 QQbrowser 10.2.2243.400 Windows 8.1 x64 Edition Windows 8.1 x64 Edition回复
    • 你自己传一部片子上去,点转码,然后终端里面用top命令看看有没有ffmpeg的进程在运行。

      LALA6年前 (2018-09-02) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
  10. #10

    楼主,我是作者,我更新了源码,难得看见有人这教程。 :eek:

    屈阿零6年前 (2018-09-06) UC Browser 12.1.2.992 UC Browser 12.1.2.992 Android 8.1.0 Android 8.1.0回复
    • 越来越强大了,好东西值得写教程嘛。

      LALA6年前 (2018-09-07) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 你好请问你的qq或者微信什么的怎么联系您

        爱啦啦5年前 (2019-01-18) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复
        • 我加你邮箱这个QQ了。

          LALA5年前 (2019-01-18) Google Chrome 70.0.3538.110 Google Chrome 70.0.3538.110 Windows 10 x64 Edition Windows 10 x64 Edition回复
  11. #11

    有成功的老哥吗 !我centos7到端口3000/admin就无法访问了 ,直接IP能看见niginx。

    kedyao6年前 (2018-09-11) Google Chrome 68.0.3440.106 Google Chrome 68.0.3440.106 Windows 10 x64 Edition Windows 10 x64 Edition回复
  12. #12

    其实现在很多站点有意放开盗链的,原因你懂的。

    hello6年前 (2018-09-21) Google Chrome 69.0.3497.100 Google Chrome 69.0.3497.100 Windows 10 x64 Edition Windows 10 x64 Edition回复
  13. #13

    付费求帮忙搭建。谢谢

    lalamao6年前 (2018-09-29) Google Chrome 63.0.3239.132 Google Chrome 63.0.3239.132 Windows 7 x64 Edition Windows 7 x64 Edition回复
  14. #14

    用ubuntu 和centos试了十几遍了,PM2里提示errored,感觉应该是这个版本的源码有问题,以前搭建成功过。日志里一直提示找不到sharp模块。

    拉拉迷6年前 (2018-10-07) Google Chrome 69.0.3497.100 Google Chrome 69.0.3497.100 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 最近这个程序大更了一次,不知道现在是什么情况,我这个文章是之前写的。

      LALA6年前 (2018-10-07) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 能联系您吗拉拉瘦

        爱啦啦5年前 (2019-01-18) Google Chrome 71.0.3578.98 Google Chrome 71.0.3578.98 Windows 10 x64 Edition Windows 10 x64 Edition回复
  15. #15

    根据教程搭建完成之后打开502

    木易酱6年前 (2018-10-07) Google Chrome 69.0.3497.100 Google Chrome 69.0.3497.100 Windows 10 x64 Edition Windows 10 x64 Edition回复
  16. #16

    可以不可以教我搭建这个

    小花6年前 (2018-10-17) UC Browser 8.7 UC Browser 8.7 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 为方便大家安装我做了一个docker镜像,https://hub.docker.com/r/palidin/express-ffmpeg

      palidin6年前 (2018-10-18) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 膜拜

        LALA6年前 (2018-10-18) Google Chrome 67.0.3396.99 Google Chrome 67.0.3396.99 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • 你好,用你的dockker不成功,在github提问了,麻烦看一下

        红领巾6年前 (2018-10-30) Google Chrome 70.0.3538.77 Google Chrome 70.0.3538.77 Windows 10 x64 Edition Windows 10 x64 Edition回复
        • 我借鉴了下他的启动脚本,自己做了个镜像,你试试https://www.moerats.com/archives/782/

          Rat's6年前 (2018-11-02) Google Chrome 70.0.3538.77 Google Chrome 70.0.3538.77 Windows 10 x64 Edition Windows 10 x64 Edition回复
  17. #17

    2018.10.20有人装好的吗

    恨天6年前 (2018-10-20) Google Chrome 69.0.3497.92 Google Chrome 69.0.3497.92 Windows 10 x64 Edition Windows 10 x64 Edition回复
  18. #18

    给lala请安, 云转码已经更新了, 本教程已经不再适用, express-ffmpeg 技术支持群 久37零54二25。感兴趣的话大家可以加一下,求助问题,心得分享,欢迎进群交流, 用宝塔安装很方便. .点击链接加入群聊【expressffmpeg阔步向前2】:https://jq.qq.com/?_wv=1027&k=5jhI4rH
    感谢本软件作者.请大家多多捐赠.

    青空6年前 (2018-10-25) Google Chrome 69.0.3497.92 Google Chrome 69.0.3497.92 Windows 10 x64 Edition Windows 10 x64 Edition回复
  19. #19

    git clone https://gitee.com/quazero/express-ffmpeg{.git}
    少了括号里的.git,无法拉去到服务器。
    :cool:

    落伍者5年前 (2018-12-06) Google Chrome 70.0.3538.102 Google Chrome 70.0.3538.102 Windows 7 x64 Edition Windows 7 x64 Edition回复

分享创造快乐

广告合作资源投稿