All Projects → hoangdh → ghichep-StreamingVideo

hoangdh / ghichep-StreamingVideo

Licence: other
Ghi chép về Livestream sử dụng Opensource - Xây dựng một máy chủ Livestream theo cách đơn giản nhất - NGINX RTMP Dockerfile

Programming Languages

shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to ghichep-StreamingVideo

Huong-dan-cai-dat-stream-server-va-chuyen-doi-video-sang-streaming
Hướng dẫn cài đặt stream server và chuyển đổi video thường sang dạng TS Streaming
Stars: ✭ 29 (-27.5%)
Mutual labels:  stream, hls, nginx-rtmp
Free Hls Live
Free live streaming with Free-HLS (Free HLS 直播姬)
Stars: ✭ 47 (+17.5%)
Mutual labels:  stream, hls
k8s-openresty-streaming
Full-fledged media streaming server with OpenResty and rtmp module
Stars: ✭ 37 (-7.5%)
Mutual labels:  stream, nginx-rtmp
Hls.js
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Stars: ✭ 10,791 (+26877.5%)
Mutual labels:  stream, hls
wsa
WSA(Websocket Streaming Agent) is a stream server target for mp4/h264 streaming over websocket
Stars: ✭ 35 (-12.5%)
Mutual labels:  stream, hls
livego
直播服务器 hls stream online RTMP AMF HLS HTTP-FLV
Stars: ✭ 30 (-25%)
Mutual labels:  stream, hls
Backoffice Administration
Stars: ✭ 89 (+122.5%)
Mutual labels:  stream, hls
hls-segment-reader
Node.js Readable for retrieving HLS segments.
Stars: ✭ 18 (-55%)
Mutual labels:  stream, hls
Desktoplivestreaming
DesktopLiveStreaming
Stars: ✭ 138 (+245%)
Mutual labels:  stream, hls
Magicalexoplayer
The Easiest Way To Play/Stream Video And Audio Using Google ExoPlayer In Your Android Application
Stars: ✭ 171 (+327.5%)
Mutual labels:  stream, hls
mock-hls-server
Fake a live/event HLS stream from a VOD one. Useful for testing. Supports looping.
Stars: ✭ 61 (+52.5%)
Mutual labels:  stream, hls
vidi
<video> playback simplified
Stars: ✭ 31 (-22.5%)
Mutual labels:  stream, hls
sms
rtmp server and super media server whith golang.
Stars: ✭ 65 (+62.5%)
Mutual labels:  stream, hls
panel
ReCast is a multi platform restreaming tool, you can stream with one servers to multiple services
Stars: ✭ 40 (+0%)
Mutual labels:  stream, nginx-rtmp
comfy-channel
A 24/7 live video broadcast with automatic content selection and overlays using FFMPEG and Python!
Stars: ✭ 37 (-7.5%)
Mutual labels:  stream, nginx-rtmp
Shinobi
☮️ 🇵🇸 Shinobi CE - The Free Open Source CCTV platform written in Node.JS (Camera Recorder - Security Surveillance Software - Restreamer
Stars: ✭ 1,099 (+2647.5%)
Mutual labels:  stream, hls
nott
The New OTT Platform - an excuse to discuss and design a simple edge computing platform
Stars: ✭ 46 (+15%)
Mutual labels:  hls, nginx-rtmp
Nginx Vod Module
NGINX-based MP4 Repackager
Stars: ✭ 1,378 (+3345%)
Mutual labels:  stream, hls
emrah-buster-templates
The templates of the emrah-buster installer.
Stars: ✭ 57 (+42.5%)
Mutual labels:  hls, nginx-rtmp
nginx-audio-track-for-hls-module
🔉 Nginx module that generates audio track for HTTP Live Streaming (HLS) streams on the fly.
Stars: ✭ 122 (+205%)
Mutual labels:  stream, hls

1. Giới thiệu về HTTP Live Streaming (HLS)

HTTP Live Streaming (hay còn được biết đến là HLS) là một cách truyền media dựa trên giao thức HTTP được Apple phát triển. Nó hỗ trợ các luồng trực tuyến, có khả năng thay đổi chất lượng phù hợp với thiết bị và băng thông mạng đang sử dụng. Cụ thể, giao thức làm việc như sau

  • Một tệp tin hay một luồng live sẽ được chia thành các file nhỏ
  • Các file nhỏ bên trên sẽ được lưu trữ trong một máy chủ web và lắng nghe các request từ một trình player.
  • Khi phát, player sẽ phát liên tiếp các file nhỏ một cách liền mạch mà không bị ngắt quãng

Nếu stream được chia thành nhiều chất lượng khác nhau (480p, 720p), thì player sẽ tự động lựa chọn chất lượng video tốt nhất để phát dựa theo tình trạng băng thông mạng. Thuật ngữ này là Adaptive Streaming (Thích nghi với điều kiện).

Tổng quan: https://docs.google.com/document/d/1SQU50h-ybMNwexiOL3QWOSg7t3PxAPg1lNbfTzOVe9k/edit?usp=sharing

Powered by MediTech,. JSC - (C) HoangDH

2. Hướng dẫn tạo server video streaming

Thông tin về server cài đặt

OS: CentOS 6.7
NIC: eth0 - 192.168.100.192
Internet: Có (Bắt buộc)

Cài đặt ffmpeg để chuyển đổi video thường sang dạng Streaming (ts)

Cài đặt các trình biên dịch cần thiết. Lưu ý: Tất cả các lệnh dưới đây phải chạy trên quyền cao nhất của hệ thống (root).

yum update
yum install -y autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel

1. Biên dịch yasm từ source

mkdir ~/ffmpeg_sources
cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make
make install
make distclean

2. Biên dịch gói mã hóa video dạng x264 và x265

cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static
make
make install
make distclean
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off source

3. Biên dịch gói mã hóa âm thanh chuẩn ACC

cd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

4. Biên dịch gói mã hóa âm thanh LAME

cd ~/ffmpeg_sources
curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
make
make install
make distclean

5. Biên dịch code OPUS

cd ~/ffmpeg_sources
git clone http://git.opus-codec.org/opus.git
cd opus
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

6. Biên dịch thư viện âm thanh OGG

cd ~/ffmpeg_sources
curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
tar xzvf libogg-1.3.2.tar.gz
cd libogg-1.3.2
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

7. Biên dịch thư viện mã hóa âm thanh Vorbis

cd ~/ffmpeg_sources
curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
LDFLAGS="-L$HOME/ffmeg_build/lib" CPPFLAGS="-I$HOME/ffmpeg_build/include" ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared
make
make install
make distclean

8. Biên dịch thư viện libvpx của WebM

cd ~/ffmpeg_sources
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make
make install
make clean

9. Biên dịch ffmpeg

cd ~/ffmpeg_sources
git clone --depth 1 https://git.videolan.org/git/ffmpeg.git
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264
make
make install
make distclean

Sau khi biên dịch đủ 9 gói, chúng ta gõ lệnh ffmpeg để kiểm tra

Chuyển đổi video thường sang dạng Streaming (ts)

ffmpeg -y -i input.mp4 -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -b:v 1600k -maxrate 1600k -bufsize 800k -s 640x360 -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list playlist.m3u8 -segment_list_flags +live-cache -segment_time 5 output-%04d.ts
  • input.mp4: Video có định dạng thông thường có thể như AVI, MPG, MKV,...
  • playlist.m3u8: Playlist chứa thông tin các file stream
  • output-%04d: File stream có dạng output-0001.ts, output-000n.ts

Cài đặt Web Server để players chạy stream

Chúng ta cài đặt NGINX

yum install -y nginx
service nginx start
chkconfig nginx on

Tắt SELinux và mở port 80 trên iptables

sed s/"SELINUX=enforcing"/"SELINUX=disabled"/g /etc/sysconfig/selinux
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart

Copy các file stream, playlist vào một thư thục và chuyển chúng tới thư mục public html của bạn.

Mặc định, thư mục public của nginx ở CentOS

/usr/share/nginx/html

Địa chỉ stream của tôi: http://192.168.100.192/bai-hat-abc/playlist.m3u8

Tham khảo xây dựng 1 máy chủ Live streaming tại đây.

Cảm ơn bạn đã đọc tới dòng này!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].