# 1. Please modify time of Ubuntu OS,Update installing application resource for Linux.

timedatectl set-timezone Asia/Shanghai
apt update
apt upgrade

# 2. install libraries about QT and ffmpeg

apt-get install qt5-default
apt install libavutil55
apt install libavcodec57
apt install libavformat57
apt install libswresample2
apt install libswscale4
apt install libqt5multimedia5
apt install libqt5multimedia5-plugins

# 3. install FFMPEG

1. 上传ffmpeg压缩包到服务器 upload the ffmpeg file to server
把ftp上的ffmpeg.zip(目录:/wjf/ffmpeg.zip)上传到/opt目录下 and upload this file ffmpeg.zip to this directory /opt
unzip ffmpeg.zip

2. 安装依赖 install related dependency
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev

3.汇编库 assembly library
Yasm是一个完全重写的NASM(The Netwide Assembler)汇编;NASM是一个为可移植性与模块化而设计的一个80x86的汇编器。它支持相当多的目标文件格式,包括Linux,*BSD,a.out,ELF,COFF,Mach−O,Microsoft 16−bit OBJ,Win32以及Win64,同时也支持简单的二进制文件生成。它的语法被设计的简单易懂,相较Intel的语法更为简单,支持目前已知的所有x86架构之上的扩展语法,同时也拥有对宏命令的良好支持。

sudo apt-get install yasm
sudo apt-get install nasm

4.视频库 video related library
要支持X264等视频处理,就需要安装相应的库:install libraries for X264 video processing
sudo apt-get install libx264-dev
sudo apt-get install libx265-dev

5.音频库 audio related library
要支持常见的音频处理,需要安装:install libraries for audio processing
sudo apt-get install libfdk-aac-dev
sudo apt-get install libmp3lame-dev
sudo apt-get install libopus-dev
sudo apt install libssl-dev libssl-doc

6.更新openssl版本(此步骤通常用于openssl版本不是1.1.1的情况下) update the version of openssl(if the version number is not 1.1.1)
执行openssl -version 为1.1.1,如果是1.1.0则需要手动下载openssl进行编译安装(check the version number,if version number is 1.1.0 then download openssl and install it)
https://www.cnblogs.com/jsjliyang/p/10606908.html

7.配置ffmpeg并安装 configurate ffmpeg and install it
cd /opt/ffmpeg/ffmpeg-4.3.2
./configure --prefix=/opt/ffmpeg --enable-libx264 --disable-yasm --enable-nonfree --enable-libfdk-aac --enable-shared --enable-gpl --enable-libmp3lame --enable-libopus --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --enable-openssl
make
make install

8.库配置和路径配置libraries configuration and path configuration
配置库所在路径,以便FFmpeg能加载相应库。打开配置文件 config libraries path for using ffmpeg anywhere.
sudo vi /etc/ld.so.conf
在文件末尾加上:attach this command at end of file
/opt/ffmpeg/lib
然后执行sudo ldconfig,重新加载配置以生效。then excute sudo Idconfig,and re-load configuration

9.路径配置 path configuration 
为能随时使用FFmpeg,需要把对应目录添加到路径中。add the directory to path configuration for using ffmpeg anywhere.
vi ~/.bashrc
在文件末尾加上:attach this command at end of file:
FFMPEG_HOME=/opt/ffmpeg
PATH=$FFMPEG_HOME/bin:$PATH
excute source ~/.bashrc

# 4. install MySql

apt-get update
apt-get install mysql-server
#初始化配置(参考下面的选项) inital configuration(please reference to following configuration)
mysql_secure_installation

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (My selection)

#2
Please set the password for root here...
New password: (input password)
Re-enter new password: (re-enter password)

#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (My selection)

#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (My selection)

#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (My selection)

#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (My selection)

#设置mysql登陆时候需要密码 config password of mysql
> use mysql;
> update user set authentication_string=password("your password") where user='root';  #(无password字段的版本,也就是版本<=5.7的 there is no password field when version<=5.7)
> update user set password=password('your password') where user='root'; #(有password字段的版本,版本>5.7的 there is password field when version>5.7)
> update user set plugin="mysql_native_password"; 
> flush privileges;
> exit;

#检查mysql服务状态 check service status of mysql
systemctl status mysql.service
#创建云剪和直播剪数据库 create databse of Meishe-Editor and Meishe-LiveEditor
drop database if EXISTS livebsedit;
create database livebsedit CHARACTER SET utf8 COLLATE utf8_general_ci;

# 5.Install nginx,please conference to this link https://blog.csdn.net/qq_23832313/article/details/83578836 (opens new window)

# 6. Deploy Meishe-LiveEditor services

1.直播剪包livebsedit,配置文件config.yaml,转码器三个文件放到/opt/livebsedit目录下 Meishe-LiveEditor  livebsedit,and configuration file is config.yaml,and put three files of transcoder to this directory /opt/livebsedit
cd /opt/livebsedit
chmod 755 NvTranscoder
chmod 755 livebsedit
nohup ./livebsedit &
查看日志tail -f latest_log    check logs
输出以下两行则表明服务启动成功  the service has start normally when there are result of two lines
router register success
websocket manage start

2.config.yaml字段说明  fields specification
#system conf
system:
addr: 8888
useSSL: false
sslPemFilePath: 
sslKeyFilePath: 
clientType: ""

#task conf
taskConf:
transcodeConf:
#转码器路径 transcoder path
transcoderPath: /opt/localpath/NvTranscoder
#转码器错误缩率图url(为空则不设置错误缩率图) error thumbnail url of transcoder(do not config error thumbnail if it is null)
errThumbnailUrl: ""
#执行转码任务超时时间(到达超时时间后自动杀死任务,单位:s,默认180s) timed-out duration of transcoding task(kill the task when timed-out,in second,and default is 180s)
execTranscodeTimeOut:
#待转缩率图任务队列长度(默认1000,通常不需要修改) task queuing length of To-do thumbnail(default is 1000,do not modify basically)
transThumbnailChan:
#转缩率图的转码任务最大执行数量(默认10) max 
transThumbnailMax:
#转缩率图查询不到任务休眠时间(单位:s,默认30s)
transThumbnailNoJobSleepTime:
#定时查询正在转码m3u8是否有新增缩率图间隔时间(单位:s,默认5s)
checkNewThumbnailsInterval:
compileConf:
#合成器路径 compiler path
compilerPath:
#使用哪种合成方式:FFMPEG-使用ffmpeg命令合成,PROCESS-使用合成器合成 (默认FFMPEG) type of compile mode:FFMPEG-ffmpeg command,PROCESS-compile by compiler and default id FFMPEG
compileMode: "FFMPEG"
#合成完是否需要转码 need to transcoding or not after compiled
needTranscode: true

#liveConfig conf
liveConf:
#直播收录持续时长(正整数则生效,否则无效,单位:s,默认24h)
recruitDuration: 0
#是否启用重定向url(比如阿里云的流需要重定向的地址才会更新m3u8里的内容)
enableRedirectOriginUrl: false
#单次扫描转缩率图的转码任务最大数量(默认10) max transcoding task of single scanning thumbnail
scanM3u8TransThumbnailMax: 5
#m3u8定时任务扫描间隔(单位s,默认5s)  scanning interval of m3u8 timing task
m3u8TaskInterval:
#扫描长时间无更新m3u8中间隔(默认60s)  time interval if m3u8 no update at long time period
scanNoupdateM3u8Interval:
#是否启用语音识别功能(默认false) open speech recognition or not
enableSpeechRecognition:

#websocket conf
websocketConf:
#是否启用websocket心跳机制 open websocket Heartbeat or not
enableHeartbeat: false
#清除直播收录任务的超时时间(单位:s),需要和enableHeartBeat配合使用 delete timed-out time of Live task recording,in second,and should according to enableHeartBeat 
timeout: 90

#zap logger configuration
zap:
#可使用 "debug", "info", "warn", "error", "dpanic", "panic", "fatal", abled selection
level: 'info'
#console: 控制台 console, json: json格式输出  json format output
format: 'console'
prefix: '[NV]'
director: 'log'
linkName: 'latest_log'
showLine: true
#LowercaseLevelEncoder: lowcase, LowercaseColorLevelEncoder:lowcase wiht color,CapitalLevelEncoder:uppercase, CapitalColorLevelEncoder: uppercase with color,
encodeLevel: 'LowercaseColorLevelEncoder'
stacktraceKey: 'stacktrace'
logInConsole: true

#mysql connect configuration
mysql:
username: meishesdk
password: 'Meishesdk2019'
path: 'bsedit.mysql.polardb.rds.aliyuncs.com:3306'
dbName: 'z-livebsedit-local'
config: 'charset=utf8mb4&parseTime=True&loc=Local'
maxIdleConns: 10
maxOpenConns: 10
logMode: false

#storage conf
storageConf:
#存储类型选择:aliyun,aws,local  storage type:
defaultStorageType: "aliyun"
#存储文件的总目录,如:/meishe/2020/03/27/   root directory of storage file,for example:/meishe/2020/03/27/
pathDir: "meishe"
#通常只需要配置AliyunXXX,不需要配置AliyunTmpXXX config AliyunXXX and do not config AliyunTemXXX basically
AliyunEndpoint: 
AliyunBucket: 
AliyunOriginHost: 
AliyunHost: 
AliyunAccessKey: 
AliyunSecretKey: 
AliyunAuthKey: 
AliyunTmpEndpoint:
AliyunTmpBucket:
AliyunTmpOriginHost:
AliyunTmpHost:
AliyunTmpAccessKey:
AliyunTmpSecretKey:

AwsS3AccessKey: 
AwsS3SecretKey:
AwsS3Region: 
AwsS3Bucket: 
AwsS3OriginHost: 
AwsS3Host: 

localHost: 'http://localhost:8888/livebsedit'
localBucket: 'livebsedit'
localPath: 'd:/home/tom/localpath/livebsedit'
#使用本地存储附加的路径 added path of local storage
#1.当前日期为2020年03月27日17:38:36,路径为:2020/03/27/ 2020/03/27/  current date is 2020/03/27 17:38:36 path is 2020/03/27/ 
pathPrefix: "1"

projectKey: project
videoKey: video
audioKey: audio
imageKey: image
videoCompiledKey: video-compiled
videoThumbnailKey: video-thumbnail
videoOnlyThumbnailKey: video-only-thumbnail
materialKey: material
recognitionKey: recognition
m3u8TransformKey: m3u8Transform


#cmd conf
cmdConf:
#通过ffmpeg合成命令:1.compileUrl 2.trimIn 3.trimOut 4.outPutPath  ffmpeg compile command
ffmpegCompileCmd: ffmpeg -protocol_whitelist file,http,https,tcp,tls -i %s -ss %f -t %f %s
#只转缩率图命令:1.转码结果输出路径 2.任务id 3.thumbnail-start-time时间,单位微秒 4.待转文件路径
#command of thumbnail transcoding only:1.output path of transcoding result  2.task id 3.thumbnail-start-time,in microsecond 4.To-do transcoding file path
onlyTranscodeThumbnailCmd: /home/tom/localpath/NvTranscoder
-o %s
--only-generate-thumbnails
--thumbnail-size 128
--thumbnail-interval 1000
--task-id %s
--thumbnail-start-time %d
%s
#video转码命令:1.转码结果输出路径 2.美摄m3u8的host 3.美摄m3u8的asset-uuid 4.taskId 5.待转文件路径
# video transcoding command:1.output path of scanning result  2.host of Meishe m3u8   3.asset-uuid of Meishe m3u8  5.To-do transcoding file path
videoTranscodeCmd: /home/tom/localpath/NvTranscoder
-o %s
--slice-duration 5000
--video-size 480
--crf 27
--fps 25
--gop-size 25
--sample-rate 44100
--channel-count 2
--audio-bitrate 64000
--generate-thumbnails
--thumbnail-size 128
--thumbnail-interval 1000
--generate-cover
--cover-size 256
--cover-timestamp 0
--host %s
--asset-uuid %s
--callback-url http://localhost:8888
--task-id %s
--generate-waveform
--waveform-groups-per-second 150
--generate-audio-data
--multiple-audio-streams
--thumbnail-start-time 0
%s

# 7. Open the host 3306 and 8888