You are on page 1of 8

Unica Streaming Server

Xem thêm: https://docs.google.com/document/d/15Py_vZQUZoUzds9NHloN933w0CcPHdBigaKwcJs_a-0/edit

Encrypted
/Storage/ Get Data Handler stream Player
Get Key .unica.vn

(5) Store: Video + Key

(4)Update: https://unica.vn/api/updatevideo

(3) Scan (2) Store (CMS) (1) Upload


Encoder /input/ Unica.vn
Video.net.vn

(5) STORE (1) ID

/done/
/error/ MySQL#2 MySQL#1

(1) User upload video trên Video.net.vn qua API:

o Upload video mới à Video.net.vn sẽ tạo record mới à trả về Video ID --> lưu vào bài học.
Video.net.vn: sẽ lưu lesson_id để biết video của bài học nào, tên bài học,..

o Lưu ý: Để tránh video bị bỏ rơi thành rác, khi update video bài học à phải submit kèm theo Video ID à
Video.net.vn kiểm tra xem ID có tồn tại? có phải của kênh đó?

è NO à báo lỗi, không cho upload video.

è OK thì lưu video vào file với ID cũ: <VideoID>_<channel>.mp4

(2) Lưu file vào thư mục: /data/video/input/

o Tên file: <ID>_<channel >.mp4

o Ví dụ: 123_unica.mp4, 456_edubit.mp4

(3) Encoder quét các file .mp4 trong folder input ở trên

o Khi bắt đầu encode thì gọi api sang website channel: ví dụ: https://unica.vn/api/updatevideo
?video_id=xxx, video_status=1& status_text=START

o Encode từng file thành các chất lượng khác nhau: 1080p, 720p, 480p, 360p (đã bỏ 240p).

(4) Encoder chủ động cập nhật sau khi encode xong:

o Cập nhật DB về links video, dung lượng files, trạng thái encode,..

o Gọi API sang website tương ứng với channel, ví dụ: https://unica.vn/api/updatevideo
?video_id=xxx, video_status=3& status_text=FINISH (nếu lỗi: video_status=2)

(5) Encoder lưu files đã encode và tạo .key files

o Lưu .mp4 file đã encode tại folder: /storage/video/<channel>/n/<ID>/<quality>.mp4

o Lưu ảnh thumnail tại địa chỉ: /storage/video/<channel>/n/<ID>/<ID>.jpg


o Lưu .key files ứng với từng video: /storage/key/<channel>//n/<ID>/<quality>.key

o Syntax: n = 1 + ID / 100; Ví dụ: ID = 90 à n = 1 è Path: /storage/video/unica/1/90/1080.mp4

o Lưu bản backup video 480p và key trên máy streaming:

§ /server19/backup/video/<channel>

§ /server19/backup/key/<channel>

o Lưu bản gốc tại server streaming: /server19/done/<channel>

XÓA VIDEO:
Khi xóa video trên CMS hoặc trên website dịch vụ (Unica.vn, ...) --> gọi API để xóa video:
https://video.net.vn/api/delete?videoId=nnn&channel=xxx&token=AES128(CallbackKey, <videoId>-<channel>)
==> Đổi trạng thái record trong table Video.status = 4 (chờ xóa)

Trên Encoder sẽ có module mỗi ngày sẽ chạy 1 lần, xóa video, đổi trạng thái: Video.status = -1 (đã xóa)

UPDATE VIDEO:
1. Upload file video mới vào /data/video/input/, tên file giữ nguyên Video ID cũ: <ID>_<Channel>.mp4
2. Encoder sẽ encode video à update đè file cũ.
3. Lưu ý: Đặt đúng Video ID và Channel
LINK FOLDER KHI NHÌN TỪ CÁC SERVER

Nội dung Encoder Streaming Storage

Video upload lưu trên máy /data/video/input/ - -


Encoder
(Dùng chung cho tất cả channel)

Video gốc mới (done) lưu trên /data/video/done/<channel>/ - -


máy Encoder

Video gốc cũ (done) lưu trên /server19/done/<channel>/ /data/done/<channel>/ -


máy streaming

Video 480p backup trên máy /server19/backup/video/<channel> /data/backup/video/<channel>/ -


Streaming
/server19/backup/key/<channel> /data/backup/key/<channel>/

Video đã encode lưu trên /storage/video/<channel>/ /storage/video/<channel>/ -


Storage và dùng để streaming

Key tương ứng với từng video /storage/key/<channel>/ /storage/key/<channel>/


lưu trên Storage

Lưu ý: mỗi channel là 1 website, ví dụ: unica, edubit, acabiz,..


ENCODER & HANDLER
o Chạy chung 1 thư viện (Encoder.jar), nhưng ở 2 folder khác nhau
o Kết nối vào DB video.net.vn để cập nhật trạng thái video sau khi encode.
o /home/vdjava/
o encoder/ -
o handler/ - Listen on port 8080
o downloader/ - Download video 240p --> 360p về mobile app
ENCODER:
./encoder/
lib/
Encoder.jar
mysql.jar
conf/
channel.conf - Cấu hình kênh (unica, dodaihoc,..)
encoder.conf - Cấu hình folder lưu trữ video, port to listen
dbpool.conf - Cấu hình kết nối với DB
./go.sh à Chạy ở chế độ background à xem log: tail console -f
./run.sh à Chạy ở chế độ console
./restart.sh à Chạy lại chương trình (~ kill + go.sh)
./key.sh à Build lại file .key của 1 video, 1 folder, or 1 channel
./delete.sh à Xóa 1 video or videos ERROR
HANDLER:
./handler/ à Listen on port 8080
lib/
Encoder.jar
mysql.jar
conf/
handler.conf - Cấu hình url và Handler xửlý
channel.conf - Cấu hình kênh (unica, dodaihoc,..)
encoder.conf - Cấu hình folder lưu trữ video, port to listen
dbpool.conf - Cấu hình kết nối với DB
unica.jks - Java key store à SSL dùng cho https://
./go.sh à Chạy ở chế độ background à xem log: tail console -f
./run.sh à Chạy ở chế độ console
./restart.sh à Chạy lại chương trình (~ kill + go.sh)

Các handler được khai báo trong file ./conf/handler.conf:


https://handler.unica.vn/handler
https://handler.unica.vn/monitor
https://handler.unica.vn/video?id=xxxx



WOWZA SERVER
1. Cài đặt:

Download tại: https://www.wowza.com/pricing/installer


sudo chmod +x WowzaStreamingEngine-4.5.0-linux-x64-installer.run

sudo ./WowzaStreamingEngine-4.5.0-linux-x64-installer.run

2. Start / stop:
sudo service WowzaStreamingEngine start / stop

sudo service WowzaStreamingEngineManager start / stop

3. Cấu hình video & key folder cho từng application (kênh video)

Sửa file /usr/local/WowzaStreamingEngine/conf/<application>/Application.xml


<StorageDir>……………</StorageDir>

<KeyDir>……………</KeyDir>

Ví dụ:
/usr/local/WowzaStreamingEngine/conf/unica/Application.xml
<Streams>
<StreamType>default</StreamType>
<StorageDir>/storage/video</StorageDir>
<KeyDir>/storage/key</KeyDir>
</Stream>
Tạo link cho các video cũ năm 2016:
mkdir: <StorageDir>/output
ln -s unica ../unica/ --> link to: <StorageDir>/unica ==> <StorageDir>/output/unica/2016/.....
mkdir: <KeyDir>/output
ln -s unica ../unica/ --> link to: <KeyDir>/unica ==> <KeyDir>/output/unica/2016/.....

/usr/local/WowzaStreamingEngine/conf/dodaihoc/Application.xml
<Streams>
<StreamType>default</StreamType>
<StorageDir>/storage/video</StorageDir>
<KeyDir>/storage/key</KeyDir>
</Streams>
2. Restart application:
https://stream.unica.vn/enginemanager/login.htm
genkey.sh

Thay đổi key mã hóa video: mỗi kênh dùng chung 1 key cho các video.
Lưu ý: nếu update key cho kênh cũ thì phải chạy file: Encoder/key.sh

cd /usr/local/WowzaStreamingEngine/bin/genkey.sh 

./genkey.sh iphone edubit https://handler.unica.vn/handler

ENCODER: CPU + STREAMING: RAM --> Có thể dùng chung 1 server


Video.net.vn
Table: site - quản lý kênh video

NAME TYPE NULL? DESC

ID INT (11) NO KEY

Name varchar(100) NO Tên kênh: unica, dodaihoc, edubit

Intro varchar(100) Y Mô tả them

Callback_Key VARCHAR(100) NO Key để tạo token gắn vào callback_url.


à Tự gen, random 30 ký tự.

Video s INT(10) NO Default 0. Số lượng video

SIZES Double NO Default 0. Tổng dung lượng videos của cả kênh, KB

Handler_url VARCHAR(200) NO Link handler

Callback_url VARCHAR(200) No Link để gọi sang website upload video ngay khi video
encode xong

Video_key VARCHAR(200) NO Key để mã hóa khi stream video


à nhập bằng tay

STATUS INT(2) NO 0 – stop, 1 – running, 2 – pause

CREATED_AT DATETIME NO Default CURRENT_TIME, on update ...

CREATEDà INT(11) NO Người Sửa, default = người tạo


CREATOR

UPDATED_AT DATETIME NO Default CURRENT_TIME, on update ...

UPDATEDà INT(11) NO Người Sửa, default = người tạo


UPDATOR
Table: Video - Quản lý từng video

NAME TYPE NULL? DESC

ID INT (11) NO KEY

lesson_id INT (11) NO Video bài học trên website gốc

Code varchar(64) Y ? Bỏ --> Drop

Site_ID INT(11) Y Website: Unica.vn, Edubit.vn, Acabiz.vn,..

Cat_ID INT(11) Y Category (NULL)

Title varchar(255) Y Tiêu đề video

SubTitle varchar(255) Y ? Bỏ --> Drop

content text Y Nội dung giới thiệu

filename varchar(250) Y Tên file: <ID>_<channelName>.mp4

real_filename varchar(250) Y Tên file gốc mà user upload

Free INT(4) N Default 0. Miễn Phí trên video.net.vn

logo INT(1) Y Yêu cầu đóng dấu logo channel


0: Không (default)
1: Bên trái
2: Bên phải

input_video varchar(255) Y ? Bỏ

created_at timestamp N default CURRENT_TIMESTAMP

updated_at datetime N default CURRENT_TIMESTAMP, on update


CURRENT_TIMESTAMP

created varchar(100) Y

updated varchar(100) Y

NỘI DUNG BÊN DƯỚI DO ENCODER CẬP NHẬT

encode_id INT(11) N ? Bỏ

encode_start datetime Y Thời điểm bắt đầu encode

encode_stop datetime Y Thời điểm kết thúc encode

encode_status varchar(20) Y Trạng thái encode


PENDING, START, FINISH, NONE, ERROR, DELETED

status INT(3) Y Default 1. Trạng thái encode


-1: Xóa
0: Pending
1: Encoding
2: Error
3: Ready to Play
4: Deleting

output_video varchar(255) Y Folder chứa video đã encode


/<channel>/<seq>/<ID>/

output_thumb varchar(255) Y File ảnh thumnail: .jpg 400x222


/<channel>/<seq>/<ID>/<ID>.jpg

infor text Y JSON Các file video để streaming

width INT(11) Y Khung hình video

height INT(11) Y Khung hình video

size INT(11) Y Dung lượng (KB)

duration INT(11) Y Thời lượng

views INT(11) Y Default 0. Số lượt xem

last_view_time datetime Y Lần xem cuối

You might also like