├── Dockerfile ├── README.md ├── README1.md ├── Script ├── backup │ ├── convert-ts.sh │ ├── crossdomain.xml │ ├── h.sh │ ├── hoangdh-stream.tar.gz │ ├── setup-streaming.tar.gz │ ├── setup-streaming │ │ ├── 1.sopcast-ubuntu-amd64-v2.sh │ │ ├── 2.ffmpeg-ubuntu-openssl-v2.sh │ │ ├── 3.nginx-ubuntu.sh │ │ └── token.sh │ └── sopcast-ffmpeg.tar.gz ├── convert-ts.sh ├── ffmpeg-centos-compiler-v1.sh ├── ffmpeg-ubuntu-compiler-v1.1.sh ├── ffmpeg-ubuntu-openssl-v2.sh ├── ffmpeg-ubuntu-ppa.sh ├── multi-quality.sh ├── org-convert-ts.sh ├── post-livesteam.sh ├── sopcast-32bit │ ├── libstdc++5_3.3.6-17~ppa~karmic_i386.deb │ ├── sopcast-player_0.8.5~ppa1_i386.deb │ ├── sp-auth-3.2.6-69.1stella.x86_64.rpm │ └── sp-auth_3.2.6~ppa1_i386.deb ├── sopcast-ubuntu-amd64-v1.sh ├── sopcast-ubuntu-amd64-v2.sh.sh ├── torrent-video.sh └── video.txt ├── Setup-NGINX-RTMP.md ├── ghichep-Wowza └── README.md ├── ghichep-nginx-RTMP ├── LB_RTMP.txt └── README.md ├── hls-vod ├── Dockerfile └── README.MD ├── images ├── 5lcn44htxb_image.png └── README.md └── nginx-rtmp ├── ffmpeg-nginx.conf ├── file-cau-hinh-nhap ├── 1.nginx.conf ├── 2.lam-nginx.conf ├── ffmpeg-nginx.conf ├── hls-native-nginx.conf ├── livesoccer-nginx.conf └── record.sh ├── nginx-auto-change-bitrate-and-record.conf ├── nginx-centos-6.sh ├── nginx-centos-7.sh ├── nginx-ubuntu.sh └── nginx.conf /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:1.16.1-alpine 2 | 3 | LABEL maintainer="HoangDH - " 4 | 5 | ENV NGINX_VER 1.16.1 6 | ENV DEP git build-base 7 | 8 | RUN apk update && \ 9 | apk --no-cache add ${DEP} openssl-dev pcre-dev zlib-dev && \ 10 | mkdir /work && \ 11 | cd /work && \ 12 | git clone git://github.com/arut/nginx-rtmp-module.git && \ 13 | wget http://nginx.org/download/nginx-${NGINX_VER}.tar.gz && \ 14 | tar -xzf nginx-${NGINX_VER}.tar.gz && \ 15 | cd nginx-${NGINX_VER} && \ 16 | ./configure --with-http_ssl_module --add-dynamic-module=../nginx-rtmp-module --with-cc-opt="-Werror=implicit-fallthrough=0" --with-compat && \ 17 | make modules && \ 18 | cp objs/ngx_rtmp_module.so /etc/nginx/modules/ && \ 19 | sed -i '7iload_module modules/ngx_rtmp_module.so;' /etc/nginx/nginx.conf && \ 20 | mkdir -p /var/cache/nginx/client_temp /var/www/hls \ 21 | && chown -R nginx:nginx /var/cache/nginx/ /var/www/hls \ 22 | && apk del ${DEP} \ 23 | && rm -rf /work /var/cache/apk/* 24 | 25 | COPY nginx-rtmp/nginx.conf /etc/nginx/ 26 | 27 | EXPOSE 80 443 1935 28 | 29 | WORKDIR /var/www 30 | 31 | CMD ["/usr/sbin/nginx", "-g", "daemon off;"] 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 1. Giới thiệu về HTTP Live Streaming (HLS) 2 | 3 | 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 4 | 5 | - Một tệp tin hay một luồng live sẽ được chia thành các file nhỏ 6 | - 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. 7 | - 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 8 | 9 | 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). 10 | 11 | 12 | 13 | Tổng quan: https://docs.google.com/document/d/1SQU50h-ybMNwexiOL3QWOSg7t3PxAPg1lNbfTzOVe9k/edit?usp=sharing 14 | 15 | Powered by MediTech,. JSC - (C) HoangDH 16 | 17 | ## 2. Hướng dẫn tạo server video streaming 18 | 19 | ##### Thông tin về server cài đặt 20 | 21 | ``` 22 | 23 | OS: CentOS 6.7 24 | NIC: eth0 - 192.168.100.192 25 | Internet: Có (Bắt buộc) 26 | 27 | ``` 28 | 29 | ### Cài đặt ffmpeg để chuyển đổi video thường sang dạng Streaming (ts) 30 | 31 | Cài đặt các trình biên dịch cần thiết. 32 | **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). 33 | 34 | ``` 35 | yum update 36 | yum install -y autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel 37 | ``` 38 | 39 | #### 1. Biên dịch yasm từ source 40 | 41 | ``` 42 | mkdir ~/ffmpeg_sources 43 | cd ~/ffmpeg_sources 44 | git clone --depth 1 git://github.com/yasm/yasm.git 45 | cd yasm 46 | autoreconf -fiv 47 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 48 | make 49 | make install 50 | make distclean 51 | ``` 52 | 53 | #### 2. Biên dịch gói mã hóa video dạng x264 và x265 54 | 55 | ``` 56 | cd ~/ffmpeg_sources 57 | git clone --depth 1 git://git.videolan.org/x264 58 | cd x264 59 | PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static 60 | make 61 | make install 62 | make distclean 63 | cd ~/ffmpeg_sources 64 | hg clone https://bitbucket.org/multicoreware/x265 65 | cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off source 66 | 67 | ``` 68 | 69 | #### 3. Biên dịch gói mã hóa âm thanh chuẩn ACC 70 | 71 | ``` 72 | cd ~/ffmpeg_sources 73 | git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac 74 | cd fdk-aac 75 | autoreconf -fiv 76 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 77 | make 78 | make install 79 | make distclean 80 | ``` 81 | 82 | #### 4. Biên dịch gói mã hóa âm thanh LAME 83 | 84 | ``` 85 | cd ~/ffmpeg_sources 86 | curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz 87 | tar xzvf lame-3.99.5.tar.gz 88 | cd lame-3.99.5 89 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm 90 | make 91 | make install 92 | make distclean 93 | ``` 94 | 95 | #### 5. Biên dịch code OPUS 96 | 97 | ``` 98 | cd ~/ffmpeg_sources 99 | git clone http://git.opus-codec.org/opus.git 100 | cd opus 101 | autoreconf -fiv 102 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 103 | make 104 | make install 105 | make distclean 106 | ``` 107 | 108 | #### 6. Biên dịch thư viện âm thanh OGG 109 | 110 | ``` 111 | cd ~/ffmpeg_sources 112 | curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz 113 | tar xzvf libogg-1.3.2.tar.gz 114 | cd libogg-1.3.2 115 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 116 | make 117 | make install 118 | make distclean 119 | ``` 120 | 121 | #### 7. Biên dịch thư viện mã hóa âm thanh Vorbis 122 | 123 | ``` 124 | cd ~/ffmpeg_sources 125 | curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz 126 | tar xzvf libvorbis-1.3.4.tar.gz 127 | cd libvorbis-1.3.4 128 | LDFLAGS="-L$HOME/ffmeg_build/lib" CPPFLAGS="-I$HOME/ffmpeg_build/include" ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared 129 | make 130 | make install 131 | make distclean 132 | ``` 133 | 134 | #### 8. Biên dịch thư viện libvpx của WebM 135 | 136 | ``` 137 | cd ~/ffmpeg_sources 138 | git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git 139 | cd libvpx 140 | ./configure --prefix="$HOME/ffmpeg_build" --disable-examples 141 | make 142 | make install 143 | make clean 144 | ``` 145 | 146 | #### 9. Biên dịch ffmpeg 147 | 148 | ``` 149 | cd ~/ffmpeg_sources 150 | git clone --depth 1 https://git.videolan.org/git/ffmpeg.git 151 | cd ffmpeg 152 | 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 153 | make 154 | make install 155 | make distclean 156 | ``` 157 | 158 | #### Sau khi biên dịch đủ 9 gói, chúng ta gõ lệnh `ffmpeg` để kiểm tra 159 | 160 | 161 | 162 | ### Chuyển đổi video thường sang dạng Streaming (ts) 163 | 164 | ``` 165 | 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 166 | ``` 167 | 168 | - `input.mp4`: Video có định dạng thông thường có thể như AVI, MPG, MKV,... 169 | - `playlist.m3u8`: Playlist chứa thông tin các file stream 170 | - `output-%04d`: File stream có dạng output-0001.ts, output-000n.ts 171 | 172 | ### Cài đặt Web Server để players chạy stream 173 | 174 | Chúng ta cài đặt NGINX 175 | 176 | ``` 177 | yum install -y nginx 178 | service nginx start 179 | chkconfig nginx on 180 | ``` 181 | 182 | Tắt SELinux và mở port 80 trên iptables 183 | 184 | ``` 185 | sed s/"SELINUX=enforcing"/"SELINUX=disabled"/g /etc/sysconfig/selinux 186 | iptables -A INPUT -p tcp --dport 80 -j ACCEPT 187 | service iptables save 188 | service iptables restart 189 | ``` 190 | 191 | 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. 192 | 193 | Mặc định, thư mục public của nginx ở CentOS 194 | 195 | ``` 196 | /usr/share/nginx/html 197 | ``` 198 | 199 | 200 | 201 | 202 | Địa chỉ stream của tôi: http://192.168.100.192/bai-hat-abc/playlist.m3u8 203 | 204 | Tham khảo xây dựng 1 máy chủ Live streaming tại [đây](https://github.com/hoangdh/ghichep-StreamingVideo/blob/master/Setup-NGINX-RTMP.md). 205 | 206 | Cảm ơn bạn đã đọc tới dòng này! 207 | -------------------------------------------------------------------------------- /README1.md: -------------------------------------------------------------------------------- 1 | # Giải pháp và kỹ thuật Streaming 2 | 3 | ## Table of Contents 4 | ### 1. Giới thiệu chung 5 | ### 2. Kỹ thuật streaming video 6 | #### 2.1 Streaming video là gì? 7 | #### 2.2 Xu hướng công nghệ 8 | #### 2.3 Các giao thức liên quan 9 | ### 3. Mô hình tổng quan 10 | -------------------------------------------------------------------------------- /Script/backup/convert-ts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | echo -e "(c) MediTech JSC,.. & LongVan IDC\nScript tu dong chuyen doi cac file co cac dinh dang *.mp4, *.mkv, *.flv, *.webm, *.mov, *.avi thanh cac file .ts (Streaming).\nLuu y: Khi chuyen doi xong, file goc se bi xoa.\nBam [Enter] de tiep tuc...\nBam [CTRL] + [C] de huy bo." 4 | # Tim DocumentRoot cua Webserver 5 | if [ -e /etc/httpd/conf/httpd.conf ]; then 6 | DOC_ROOT=`grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf | sed '/^#/ d' | awk {'print $2'} | sed -r 's/"//g'` 7 | echo "Ban dang su dung Apache." 8 | else if [ -e /etc/nginx/nginx.conf ]; then 9 | DOC_ROOT=`grep -v '^$\|^\s*\#' /etc/nginx/conf.d/*.conf |grep root | awk '!a[$0]++' | cut -d' ' -f2-20 | tr ';' ' ' | xargs | awk '{print $2}'` 10 | echo "Ban dang su dung NGINX." 11 | fi 12 | fi 13 | read -e -i $DOC_ROOT -p "Nhap dia chi DocumentRoot cua Webserver: " DOC_ROOT 14 | read -e -i /opt/videos -p "Nhap thu muc video cua ban: " VIDEO 15 | cd $VIDEO 16 | # Doi ten file chua dau " " va dau cham (.) 17 | for fname in *\.*; 18 | do 19 | name="${fname%\.*}" 20 | extension="${fname#$name}" 21 | newname="${name//./_}" 22 | newfname="$newname""$extension" 23 | if [ "$fname" != "$newfname" ]; then 24 | #echo mv "$fname" "$newfname" 25 | mv "$fname" "$newfname" 26 | fi 27 | done 28 | for f in *\ * 29 | do 30 | mv "$f" "${f// /_}" 31 | #echo mv "$f" "${f// /_}" 32 | done 33 | # Lay thu muc DocumentRoot 34 | #grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf|sed '/^#/ d' | awk {'print $2'} | sed -r 's/"//g' 35 | 36 | # Tao thu muc theo thang/nam 37 | year=`date +%Y` 38 | month=`date +%m` 39 | date >> /opt/list-stream.txt 40 | cd $VIDEO 41 | # Liet ke cac file video co trong thu muc hien tai 42 | list=`ls $VIDEO | egrep '*.mp4|*.mkv|*.flv|*.webm|*.mov|*.avi'` 43 | echo -e "Danh sach video co trong tu muc: \n" $list 44 | if [ -z "$list" ]; then 45 | for x in {5..1} 46 | do 47 | clear 48 | echo -e "(c) MediTech JSC,.. & LongVan IDC\nKhong co file trong thu muc, script se tu dong thoat sau $x." 49 | sleep 1 50 | done 51 | clear 52 | exit 53 | else 54 | read -p 'Bam [Enter]...' 55 | for file in $list 56 | do 57 | eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $file) 58 | size=${streams_stream_0_width}x${streams_stream_0_height} 59 | folder=`echo $file | tr '.' ' ' | awk {'print $1'}` 60 | REPO=$DOC_ROOT/upload/$year/$month/$folder 61 | mkdir -p $REPO 62 | ffmpeg -y -i $file -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -s $size -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list $REPO/index.m3u8 -segment_list_flags +live-cache -segment_time 5 $REPO/$file-%04d.ts 63 | ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` 64 | #rm -rf $file 65 | echo "http://$ip/upload/$year/$month/$folder/index.m3u8" >> /opt/list-stream.txt 66 | echo "Danh sach stream duoc luu tai: /opt/list-stream.txt" 67 | done 68 | fi 69 | -------------------------------------------------------------------------------- /Script/backup/crossdomain.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Script/backup/h.sh: -------------------------------------------------------------------------------- 1 | # Trinh bien dich 2 | yum install -y autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel 3 | 4 | mkdir ~/ffmpeg_sources 5 | cd ~/ffmpeg_sources 6 | git clone --depth 1 git://github.com/yasm/yasm.git 7 | cd yasm 8 | autoreconf -fiv 9 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 10 | make 11 | make install 12 | make distclean 13 | cd ~/ffmpeg_sources 14 | git clone --depth 1 git://git.videolan.org/x264 15 | cd x264 16 | PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static 17 | make 18 | make install 19 | make distclean 20 | cd ~/ffmpeg_sources 21 | hg clone https://bitbucket.org/multicoreware/x265 22 | cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off source 23 | cd .. 24 | cd ~/ffmpeg_sources 25 | git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac 26 | cd fdk-aac 27 | autoreconf -fiv 28 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 29 | make 30 | make install 31 | make distclean 32 | cd ~/ffmpeg_sources 33 | ls 34 | curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz 35 | tar xzvf lame-3.99.5.tar.gz 36 | cd lame-3.99.5 37 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm 38 | make 39 | make install 40 | make distclean 41 | cd ~/ffmpeg_sources 42 | git clone http://git.opus-codec.org/opus.git 43 | cd opus 44 | autoreconf -fiv 45 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 46 | make 47 | make install 48 | make distclean 49 | cd ~/ffmpeg_sources 50 | curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz 51 | tar xzvf libogg-1.3.2.tar.gz 52 | cd libogg-1.3.2 53 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 54 | make 55 | make install 56 | make distclean 57 | cd ~/ffmpeg_sources 58 | curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz 59 | tar xzvf libvorbis-1.3.4.tar.gz 60 | cd libvorbis-1.3.4 61 | LDFLAGS="-L$HOME/ffmeg_build/lib" CPPFLAGS="-I$HOME/ffmpeg_build/include" ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared 62 | make 63 | make install 64 | make distclean 65 | cd ~/ffmpeg_sources 66 | git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git 67 | cd libvpx 68 | ./configure --prefix="$HOME/ffmpeg_build" --disable-examples 69 | make 70 | make install 71 | make clean 72 | cd ~/ffmpeg_sources 73 | git clone --depth 1 https://git.videolan.org/git/ffmpeg.git 74 | cd ffmpeg 75 | 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 76 | make 77 | make install 78 | make distclean -------------------------------------------------------------------------------- /Script/backup/hoangdh-stream.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/backup/hoangdh-stream.tar.gz -------------------------------------------------------------------------------- /Script/backup/setup-streaming.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/backup/setup-streaming.tar.gz -------------------------------------------------------------------------------- /Script/backup/setup-streaming/1.sopcast-ubuntu-amd64-v2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # yum group install "Development Tools" -yum 4 | # yum install -y wget tar zip 5 | # yum install libgcc_s.so.1 -y 6 | # mkdir -p /opt/sopcast 7 | # cd /opt/sopcast 8 | # wget http://download.sopcast.com/download/sp-auth.tgz 9 | # wget http://www.sopcast.com/download/libstdcpp5.tgz 10 | # cd /opt/sopcast 11 | # tar xzf sp-auth.tgz 12 | # tar xzf libstdcpp5.tgz 13 | # cd /opt/sopcast/usr/lib 14 | # cp -a libstdc++.so.5* /usr/lib 15 | # cp /opt/sopcast/sp-auth/sp-sc-auth /usr/bin/ 16 | 17 | apt-get update -y 18 | apt-get install gcc vlc wget -y 19 | wget http://ppa.launchpad.net/lyc256/sopcast-player/ubuntu/pool/main/s/sp-auth/sp-auth_3.2.6~ppa1_amd64.deb 20 | wget http://ppa.launchpad.net/lyc256/sopcast-player/ubuntu/pool/main/s/sopcast-player/sopcast-player_0.8.5~ppa1_amd64.deb 21 | dpkg -i sp-auth_3.2.6~ppa1_amd64.deb 22 | dpkg -i sopcast-player_0.8.5~ppa1_amd64.deb 23 | apt-get install -y python 24 | apt-get install -f -y 25 | echo "Test: sp-sc sop://broker.sopcast.com:3912/128789 2222 80" 26 | -------------------------------------------------------------------------------- /Script/backup/setup-streaming/2.ffmpeg-ubuntu-openssl-v2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p ~/ffmpeg_sources 4 | mkdir -p ~/ffmpeg_build 5 | mkdir -p ~/bin 6 | 7 | apt-get update -y 8 | apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev libssl-dev 9 | 10 | # yasm 11 | cd ~/ffmpeg_sources 12 | wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz 13 | tar xzvf yasm-1.3.0.tar.gz 14 | cd yasm-1.3.0 15 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 16 | make 17 | make install 18 | make distclean 19 | 20 | #libx264 21 | cd ~/ffmpeg_sources 22 | wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 23 | tar xjvf last_x264.tar.bz2 24 | cd x264-snapshot* 25 | PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --disable-opencl 26 | PATH="$HOME/bin:$PATH" make 27 | make install 28 | make distclean 29 | 30 | #libx265 31 | sudo apt-get install cmake mercurial -y 32 | cd ~/ffmpeg_sources 33 | hg clone https://bitbucket.org/multicoreware/x265 34 | cd ~/ffmpeg_sources/x265/build/linux 35 | PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source 36 | make 37 | make install 38 | make distclean 39 | 40 | #acc 41 | cd ~/ffmpeg_sources 42 | wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master 43 | tar xzvf fdk-aac.tar.gz 44 | cd mstorsjo-fdk-aac* 45 | autoreconf -fiv 46 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 47 | make 48 | make install 49 | make distclean 50 | 51 | #lame 52 | sudo apt-get install nasm -y 53 | cd ~/ffmpeg_sources 54 | wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz 55 | tar xzvf lame-3.99.5.tar.gz 56 | cd lame-3.99.5 57 | ./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared 58 | make 59 | make install 60 | make distclean 61 | 62 | #opus 63 | cd ~/ffmpeg_sources 64 | wget http://downloads.xiph.org/releases/opus/opus-1.1.3.tar.gz 65 | tar xzvf opus-1.1.3.tar.gz 66 | cd opus-1.1.3 67 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 68 | make 69 | make install 70 | make clean 71 | 72 | #vpx 73 | cd ~/ffmpeg_sources 74 | wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.0.tar.bz2 75 | tar xjvf libvpx-1.6.0.tar.bz2 76 | cd libvpx-1.6.0 77 | PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests 78 | PATH="$HOME/bin:$PATH" make 79 | make install 80 | make clean 81 | 82 | ## openssl 83 | cd ~/ffmpeg_sources 84 | # wget https://www.openssl.org/source/openssl-fips-2.0.14.tar.gz 85 | # tar -xvzf openssl-fips-2.0.14.tar.gz 86 | # cd openssl-fips-2.0.14/ 87 | 88 | wget wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz 89 | tar -xvzf openssl-1.1.0e.tar.gz 90 | cd openssl-*/ 91 | ./config --prefix=/usr 92 | sudo make 93 | sudo checkinstall 94 | 95 | ##ffmpeg 96 | cd ~/ffmpeg_sources 97 | wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 98 | tar xjvf ffmpeg-snapshot.tar.bz2 99 | cd ffmpeg 100 | PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ 101 | --prefix="$HOME/ffmpeg_build" \ 102 | --pkg-config-flags="--static" \ 103 | --extra-cflags="-I$HOME/ffmpeg_build/include" \ 104 | --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ 105 | --bindir="$HOME/bin" \ 106 | --enable-gpl \ 107 | --enable-libass \ 108 | --enable-libfdk-aac \ 109 | --enable-libfreetype \ 110 | --enable-libmp3lame \ 111 | --enable-libopus \ 112 | --enable-libtheora \ 113 | --enable-libvorbis \ 114 | --enable-libvpx \ 115 | --enable-libx264 \ 116 | --enable-libx265 \ 117 | --enable-openssl \ 118 | --enable-nonfree 119 | PATH="$HOME/bin:$PATH" make 120 | make install 121 | make distclean 122 | hash -r 123 | 124 | cp ~/bin/* /bin/ 125 | -------------------------------------------------------------------------------- /Script/backup/setup-streaming/3.nginx-ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update -y 4 | apt-get install build-essential libpcre3 libpcre3-dev libssl-dev git wget dpkg-dev zlib1g-dev unzip -y 5 | 6 | git clone https://github.com/arut/nginx-rtmp-module.git 7 | wget http://nginx.org/download/nginx-1.10.1.tar.gz 8 | tar -xf nginx-1.10.1.tar.gz 9 | cd nginx-1.10.1 10 | 11 | # apt-get update -y 12 | # apt-get install build-essential libpcre3 libpcre3-dev libssl-dev git wget dpkg-dev zlib1g-dev unzip -y 13 | 14 | # git clone https://github.com/arut/nginx-rtmp-module.git 15 | # wget http://nginx.org/download/nginx-1.8.1.tar.gz 16 | # tar -xf nginx-1.8.1.tar.gz 17 | # cd nginx-1.8.1 18 | 19 | ./configure --user=nginx --group=nginx --add-module=../nginx-rtmp-module/ --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 20 | 21 | make 22 | make install 23 | useradd -r nginx 24 | mkdir -p /var/cache/nginx/client_temp/ 25 | mkdir -p /etc/nginx/html/vod/ 26 | mkdir -p /etc/nginx/html/live/ 27 | chown nginx. /etc/nginx/html/live/ 28 | chown nginx. /etc/nginx/html/vod/ 29 | chown nginx. /var/cache/nginx/client_temp/ 30 | 31 | cat > /etc/nginx/html/crossdomain.xml << H2 32 | 33 | 34 | 35 | 36 | H2 37 | 38 | cat > /lib/systemd/system/nginx.service <

/etc/nginx/nginx.conf << H2 57 | #user nobody; 58 | worker_processes auto; 59 | 60 | #error_log logs/error.log; 61 | #error_log logs/error.log notice; 62 | #error_log logs/error.log info; 63 | 64 | pid /var/run/nginx.pid; 65 | 66 | events { 67 | worker_connections 1024; 68 | } 69 | 70 | rtmp { 71 | server { 72 | listen 1935; 73 | chunk_size 4096; 74 | notify_method get; 75 | 76 | application vod { 77 | play /etc/nginx/html/vod; 78 | } 79 | 80 | application live { 81 | live on; 82 | record off; 83 | # on_publish http://localhost/on_publish; 84 | # # Turn on HLS 85 | hls on; 86 | hls_path /etc/nginx/html/live; 87 | hls_fragment 3; 88 | hls_playlist_length 5; 89 | hls_nested on; 90 | ## disable consuming the stream from nginx as rtmp 91 | # deny play all; 92 | # allow publish 127.0.0.1; 93 | # allow publish 0.0.0.0; 94 | # deny publish all; 95 | } 96 | # # Record stream 97 | # record all; 98 | # record_path /etc/nginx/html/vod/; 99 | # record_suffix -%d-%b-%y-%T.flv; 100 | # record_notify on; 101 | 102 | } 103 | } 104 | 105 | http { 106 | include mime.types; 107 | default_type application/octet-stream; 108 | 109 | #log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" ' 110 | # '$status \$body_bytes_sent "\$http_referer" ' 111 | # '"\$http_user_agent" "\$http_x_forwarded_for"'; 112 | 113 | #access_log logs/access.log main; 114 | 115 | sendfile on; 116 | #tcp_nopush on; 117 | 118 | #keepalive_timeout 0; 119 | keepalive_timeout 65; 120 | 121 | gzip on; 122 | 123 | server { 124 | listen 80; 125 | server_name localhost; 126 | server_tokens off; 127 | #charset koi8-r; 128 | 129 | access_log /var/log/nginx/access_log combined; 130 | error_log /var/log/nginx/error_log; 131 | location / { 132 | root html; 133 | index index.html index.htm; 134 | } 135 | location /live { 136 | # Disable cache 137 | add_header 'Cache-Control' 'no-cache'; 138 | 139 | # CORS setup 140 | add_header 'Access-Control-Allow-Origin' '*' always; 141 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 142 | add_header 'Access-Control-Allow-Headers' 'Range'; 143 | 144 | # allow CORS preflight requests 145 | if (\$request_method = 'OPTIONS') { 146 | add_header 'Access-Control-Allow-Origin' '*'; 147 | add_header 'Access-Control-Allow-Headers' 'Range'; 148 | add_header 'Access-Control-Max-Age' 1728000; 149 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 150 | add_header 'Content-Length' 0; 151 | return 204; 152 | } 153 | 154 | types { 155 | application/dash+xml mpd; 156 | application/vnd.apple.mpegurl m3u8; 157 | video/mp2t ts; 158 | } 159 | root html; 160 | } 161 | # # Secure VOD 162 | # location /videos { 163 | # secure_link_secret livestream; 164 | # if ($secure_link = "") { return 403; } 165 | 166 | # rewrite ^ /vod/$secure_link; 167 | # } 168 | 169 | # location /vod { 170 | # internal; 171 | # root /etc/nginx/html; 172 | # } 173 | # Secure RTMP on publish. (on_play,...) 174 | location /on_publish { 175 | 176 | # set connection secure link 177 | secure_link \$arg_st,\$arg_e; 178 | secure_link_md5 ByHoangDH\$arg_app/\$arg_name\$arg_e; 179 | 180 | # bad hash 181 | if (\$secure_link = "") { 182 | return 501; 183 | } 184 | 185 | # link expired 186 | if (\$secure_link = "0") { 187 | return 502; 188 | } 189 | 190 | return 200; 191 | } 192 | #error_page 404 /404.html; 193 | 194 | # redirect server error pages to the static page /50x.html 195 | # 196 | error_page 500 502 503 504 /50x.html; 197 | location = /50x.html { 198 | root html; 199 | } 200 | } 201 | } 202 | H2 203 | 204 | systemctl enable nginx 205 | systemctl start nginx -------------------------------------------------------------------------------- /Script/backup/setup-streaming/token.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | timestamp=`date +%s` 4 | expire=$(($timestamp+300)) # Exprire 5' 5 | key=`echo -n "ByHoangDH/$1$expire" | openssl dgst -md5 -binary | openssl enc -base64 | tr '+/' '-_' | tr -d '='` 6 | echo "$1?e=$expire&st=$key" -------------------------------------------------------------------------------- /Script/backup/sopcast-ffmpeg.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/backup/sopcast-ffmpeg.tar.gz -------------------------------------------------------------------------------- /Script/convert-ts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | # Mau chu 4 | RED='\033[0;31m' 5 | GREEN='\033[0;32m' 6 | NC='\033[0m' # No Color 7 | echo -e "${GREEN}Powered by MediTech JSC,.. & LongVan IDC\n${NC}Script tu dong chuyen doi cac file co cac dinh dang *.mp4, *.mkv, *.flv, *.webm, *.mov, *.avi thanh cac file .ts (Streaming).\n${RED}Luu y: Khi chuyen doi xong, file goc se bi xoa.${NC}\nBam [Enter] de tiep tuc...\nBam [CTRL] + [C] de huy bo." 8 | 9 | # Tim DocumentRoot cua Webserver 10 | if [ -e /etc/httpd/conf/httpd.conf ]; then 11 | DOC_ROOT=`grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf | sed '/^#/ d' | awk {'print $2'} | sed -r 's/"//g'` 12 | echo -e "${GREEN}Ban dang su dung Apache. ${NC}" 13 | if [ -z $DOC_ROOT ]; then 14 | echo "Khong tim duoc thu muc DocumentRoot trong file cau hinh." 15 | return DOC_ROOT=/opt/videos 16 | fi 17 | elif [ -e /etc/nginx/nginx.conf ]; then 18 | DOC_ROOT=`grep -v '^$\|^\s*\#' /etc/nginx/conf.d/*.conf |grep root | awk '!a[$0]++' | cut -d' ' -f2-20 | tr ';' ' ' | xargs | awk '{print $2}'` 19 | if [ -z $DOC_ROOT ]; then 20 | echo "Khong tim duoc thu muc DocumentRoot trong file cau hinh." 21 | DOC_ROOT=/opt/videos 22 | fi 23 | echo -e "${GREEN}Ban dang su dung NGINX. ${NC}" 24 | else 25 | echo -e "${RED}Ban chua cai Webserver. ${NC}" 26 | DOC_ROOT=/opt/videos 27 | fi 28 | 29 | read -e -i $DOC_ROOT -p "Nhap dia chi DocumentRoot cua Webserver: " DOC_ROOT 30 | read -e -i /opt/videos -p "Nhap thu muc video cua ban: " VIDEO 31 | cd $VIDEO 32 | # Doi ten file chua dau " " va dau cham (.) 33 | for fname in *\.*; 34 | do 35 | name="${fname%\.*}" 36 | extension="${fname#$name}" 37 | newname="${name//./_}" 38 | newfname="$newname""$extension" 39 | if [ "$fname" != "$newfname" ]; then 40 | mv "$fname" "$newfname" 41 | fi 42 | done 43 | for f in *\ * 44 | do 45 | mv "$f" "${f// /_}" 46 | done 47 | 48 | # Tao thu muc theo thang/nam 49 | year=`date +%Y` 50 | month=`date +%m` 51 | cd $VIDEO 52 | # Liet ke cac file video co trong thu muc hien tai 53 | list=`ls $VIDEO | egrep '*.mp4|*.mkv|*.flv|*.webm|*.mov|*.avi'` 54 | echo -e "Danh sach video co trong tu muc: \n" $list 55 | if [ -z "$list" ]; then 56 | for x in {5..1} 57 | do 58 | clear 59 | echo -e "Powered by MediTech JSC,.. & LongVan IDC\n${RED}Khong co file trong thu muc, script se tu dong thoat sau $x.${NC}\n" 60 | sleep 1 61 | done 62 | clear 63 | exit 64 | else 65 | read -p 'Bam [Enter]...' 66 | date >> /opt/list-stream.txt 67 | for file in $list 68 | do 69 | eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $file) 70 | size=${streams_stream_0_width}x${streams_stream_0_height} 71 | folder=`echo $file | tr '.' ' ' | awk {'print $1'}` 72 | REPO=$DOC_ROOT/upload/$year/$month/$folder 73 | mkdir -p $REPO 74 | ffmpeg -y -i $file -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -s $size -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list $REPO/index.m3u8 -segment_list_flags +live-cache -segment_time 5 $REPO/$file-%04d.ts 75 | ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` 76 | #rm -rf $file 77 | echo "http://$ip/upload/$year/$month/$folder/index.m3u8" >> /opt/list-stream.txt 78 | echo -e "${GREEN}Danh sach stream duoc luu tai:${NC} /opt/list-stream.txt" 79 | done 80 | fi 81 | -------------------------------------------------------------------------------- /Script/ffmpeg-centos-compiler-v1.sh: -------------------------------------------------------------------------------- 1 | # rpm -Uhv http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm 2 | # yum -y update 3 | # yum install glibc gcc gcc-c++ autoconf automake libtool git make nasm pkgconfig -y 4 | # yum install SDL-devel a52dec a52dec-devel alsa-lib-devel faac faac-devel faad2 faad2-devel -y 5 | # yum install freetype-devel giflib gsm gsm-devel imlib2 imlib2-devel lame lame-devel libICE-devel libSM-devel libX11-devel -y 6 | # yum install libXau-devel libXdmcp-devel libXext-devel libXrandr-devel libXrender-devel libXt-devel -y 7 | # yum install libogg libvorbis vorbis-tools mesa-libGL-devel mesa-libGLU-devel xorg-x11-proto-devel zlib-devel -y 8 | # yum install libtheora theora-tools -y 9 | # yum install ncurses-devel -y 10 | # yum install libdc1394 libdc1394-devel -y 11 | # yum install amrnb-devel amrwb-devel opencore-amr-devel -y 12 | 13 | # # xvid 14 | # cd /opt 15 | # wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz 16 | # tar xzvf xvidcore-1.3.2.tar.gz 17 | # cd xvidcore/build/generic 18 | # ./configure --prefix="$HOME/ffmpeg_build" 19 | # make 20 | # make install 21 | 22 | # #libOgg 23 | # cd /opt 24 | # wget http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz 25 | # tar xzvf libogg-1.3.1.tar.gz 26 | # cd libogg-1.3.1 27 | # ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 28 | # make 29 | # make install 30 | 31 | # #libvorbis 32 | # cd /opt 33 | # wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz 34 | # tar xzvf libvorbis-1.3.4.tar.gz 35 | # cd libvorbis-1.3.4 36 | # ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared 37 | # make 38 | # make install 39 | 40 | # #libtheora 41 | # cd /opt 42 | # wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz 43 | # tar xzvf libtheora-1.1.1.tar.gz 44 | # cd libtheora-1.1.1 45 | # ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --disable-shared --disable-sdltest --disable-vorbistest 46 | # make 47 | # make install 48 | 49 | # #accenc 50 | # cd /opt 51 | # wget http://downloads.sourceforge.net/opencore-amr/vo-aacenc-0.1.2.tar.gz 52 | # tar xzvf vo-aacenc-0.1.2.tar.gz 53 | # cd vo-aacenc-0.1.2 54 | # ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 55 | # make 56 | # make install 57 | 58 | # #yasm 59 | # yum remove yasm 60 | # cd /opt 61 | # wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz 62 | # tar xzfv yasm-1.2.0.tar.gz 63 | # cd yasm-1.2.0 64 | # ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 65 | # make 66 | # make install 67 | # export "PATH=$PATH:$HOME/bin" 68 | 69 | # #libvpx 70 | # cd /opt 71 | # git clone https://chromium.googlesource.com/webm/libvpx.git 72 | # cd libvpx 73 | # git checkout tags/v.1.3.0 74 | # ./configure --prefix="$HOME/ffmpeg_build" --disable-examples 75 | # make 76 | # make install 77 | 78 | # #x264 79 | # cd /opt 80 | # git clone git://git.videolan.org/x264.git 81 | # cd x264 82 | # ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static 83 | # make 84 | # make install 85 | 86 | # #Configure libraries 87 | # export LD_LIBRARY_PATH=/usr/local/lib/ 88 | # echo /usr/local/lib >> /etc/ld.so.conf.d/custom-libs.conf 89 | # ldconfig 90 | 91 | # #Compile FFmpeg 92 | # cd /opt 93 | # git clone git://source.ffmpeg.org/ffmpeg.git 94 | # cd ffmpeg 95 | # git checkout release/2.5 96 | # PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" 97 | # export PKG_CONFIG_PATH 98 | # ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" \ 99 | # --extra-libs=-ldl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac \ 100 | # --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libvo-aacenc --enable-libxvid --disable-ffplay \ 101 | # --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads 102 | # make 103 | # make install 104 | 105 | #!/bin/bash 106 | #Install FFmpeg 107 | 108 | yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel -y 109 | mkdir ~/ffmpeg_sources 110 | 111 | 112 | 113 | #Yasm 114 | cd ~/ffmpeg_sources 115 | curl -O http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz 116 | tar xzvf yasm-1.2.0.tar.gz 117 | cd yasm-1.2.0 118 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 119 | make 120 | make install 121 | make distclean 122 | export "PATH=$PATH:$HOME/bin" 123 | 124 | 125 | 126 | #libx264 127 | cd ~/ffmpeg_sources 128 | git clone --depth 1 git://git.videolan.org/x264 129 | cd x264 130 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared 131 | make 132 | make install 133 | make distclean 134 | 135 | 136 | 137 | #libfdk_aac 138 | cd ~/ffmpeg_sources 139 | git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac 140 | cd fdk-aac 141 | autoreconf -fiv 142 | ./configure --prefix="$HOME/ffmpeg_build" --enable-shared 143 | make 144 | make install 145 | make distclean 146 | 147 | 148 | 149 | #libmp3lame 150 | cd ~/ffmpeg_sources 151 | curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz 152 | tar xzvf lame-3.99.5.tar.gz 153 | cd lame-3.99.5 154 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared --enable-nasm 155 | make 156 | make install 157 | make distclean 158 | 159 | 160 | 161 | #libopus 162 | cd ~/ffmpeg_sources 163 | curl -O http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz 164 | tar xzvf opus-1.1.tar.gz 165 | cd opus-1.1 166 | ./configure --prefix="$HOME/ffmpeg_build" --enable-shared 167 | make 168 | make install 169 | make distclean 170 | 171 | 172 | 173 | #libogg 174 | cd ~/ffmpeg_sources 175 | curl -O http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz 176 | tar xzvf libogg-1.3.1.tar.gz 177 | cd libogg-1.3.1 178 | ./configure --prefix="$HOME/ffmpeg_build" --enable-shared 179 | make 180 | make install 181 | make distclean 182 | 183 | 184 | 185 | #libvorbis 186 | echo "/root/ffmpeg_build/lib" >> /etc/ld.so.conf 187 | ldconfig 188 | cd ~/ffmpeg_sources 189 | curl -O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz 190 | tar xzvf libvorbis-1.3.4.tar.gz 191 | cd libvorbis-1.3.4 192 | ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --enable-shared 193 | make 194 | make install 195 | make distclean 196 | 197 | #libvpx 198 | cd ~/ffmpeg_sources 199 | git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git 200 | cd libvpx 201 | ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests 202 | make 203 | make install 204 | make clean 205 | 206 | #freetype-devel, libspeex 207 | yum install freetype-devel speex-devel -y 208 | 209 | 210 | #libtheora 211 | cd ~/ffmpeg_sources 212 | curl -O http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz 213 | tar xzvf libtheora-1.1.1.tar.gz 214 | cd libtheora-1.1.1 215 | ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --enable-shared --disable-sdltest --disable-vorbistest 216 | make 217 | make install 218 | make distclean 219 | 220 | #FFmpeg 221 | cd ~/ffmpeg_sources 222 | wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 223 | tar xjvf ffmpeg-snapshot.tar.bz2 224 | cd ffmpeg 225 | PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ 226 | --prefix="$HOME/ffmpeg_build" \ 227 | --pkg-config-flags="--static" \ 228 | --extra-cflags="-I$HOME/ffmpeg_build/include" \ 229 | --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ 230 | --bindir="$HOME/bin" \ 231 | --enable-gpl \ 232 | --enable-libass \ 233 | --enable-libfdk-aac \ 234 | --enable-libfreetype \ 235 | --enable-libmp3lame \ 236 | --enable-libopus \ 237 | --enable-libtheora \ 238 | --enable-libvorbis \ 239 | --enable-libvpx \ 240 | --enable-libx264 \ 241 | --enable-libx265 \ 242 | --enable-nonfree 243 | PATH="$HOME/bin:$PATH" make 244 | make install 245 | make distclean 246 | hash -r 247 | -------------------------------------------------------------------------------- /Script/ffmpeg-ubuntu-compiler-v1.1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p ~/ffmpeg_sources 4 | mkdir -p ~/ffmpeg_build 5 | mkdir -p ~/bin 6 | 7 | sudo apt-get update 8 | sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev 9 | 10 | # yasm 11 | cd ~/ffmpeg_sources 12 | wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz 13 | tar xzvf yasm-1.3.0.tar.gz 14 | cd yasm-1.3.0 15 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 16 | make 17 | make install 18 | make distclean 19 | 20 | #libx264 21 | cd ~/ffmpeg_sources 22 | wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 23 | tar xjvf last_x264.tar.bz2 24 | cd x264-snapshot* 25 | PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --disable-opencl 26 | PATH="$HOME/bin:$PATH" make 27 | make install 28 | make distclean 29 | 30 | #libx265 31 | sudo apt-get install cmake mercurial -y 32 | cd ~/ffmpeg_sources 33 | hg clone https://bitbucket.org/multicoreware/x265 34 | cd ~/ffmpeg_sources/x265/build/linux 35 | PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source 36 | make 37 | make install 38 | make distclean 39 | 40 | #acc 41 | cd ~/ffmpeg_sources 42 | wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master 43 | tar xzvf fdk-aac.tar.gz 44 | cd mstorsjo-fdk-aac* 45 | autoreconf -fiv 46 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 47 | make 48 | make install 49 | make distclean 50 | 51 | #lame 52 | sudo apt-get install nasm -y 53 | cd ~/ffmpeg_sources 54 | wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz 55 | tar xzvf lame-3.99.5.tar.gz 56 | cd lame-3.99.5 57 | ./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared 58 | make 59 | make install 60 | make distclean 61 | 62 | #opus 63 | cd ~/ffmpeg_sources 64 | wget http://downloads.xiph.org/releases/opus/opus-1.1.3.tar.gz 65 | tar xzvf opus-1.1.3.tar.gz 66 | cd opus-1.1.3 67 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 68 | make 69 | make install 70 | make clean 71 | 72 | #vpx 73 | cd ~/ffmpeg_sources 74 | wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.0.tar.bz2 75 | tar xjvf libvpx-1.6.0.tar.bz2 76 | cd libvpx-1.6.0 77 | PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests 78 | PATH="$HOME/bin:$PATH" make 79 | make install 80 | make clean 81 | 82 | ##ffmpeg 83 | 84 | cd ~/ffmpeg_sources 85 | wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 86 | tar xjvf ffmpeg-snapshot.tar.bz2 87 | cd ffmpeg 88 | PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ 89 | --prefix="$HOME/ffmpeg_build" \ 90 | --pkg-config-flags="--static" \ 91 | --extra-cflags="-I$HOME/ffmpeg_build/include" \ 92 | --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ 93 | --bindir="$HOME/bin" \ 94 | --enable-gpl \ 95 | --enable-libass \ 96 | --enable-libfdk-aac \ 97 | --enable-libfreetype \ 98 | --enable-libmp3lame \ 99 | --enable-libopus \ 100 | --enable-libtheora \ 101 | --enable-libvorbis \ 102 | --enable-libvpx \ 103 | --enable-libx264 \ 104 | --enable-libx265 \ 105 | --enable-nonfree 106 | PATH="$HOME/bin:$PATH" make 107 | make install 108 | make distclean 109 | hash -r 110 | 111 | cp ~/bin/* /bin/ -------------------------------------------------------------------------------- /Script/ffmpeg-ubuntu-openssl-v2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir -p ~/ffmpeg_sources 4 | mkdir -p ~/ffmpeg_build 5 | mkdir -p ~/bin 6 | 7 | sudo apt-get update 8 | sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev libssl-dev 9 | 10 | # yasm 11 | cd ~/ffmpeg_sources 12 | wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz 13 | tar xzvf yasm-1.3.0.tar.gz 14 | cd yasm-1.3.0 15 | ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 16 | make 17 | make install 18 | make distclean 19 | 20 | #libx264 21 | cd ~/ffmpeg_sources 22 | wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 23 | tar xjvf last_x264.tar.bz2 24 | cd x264-snapshot* 25 | PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --disable-opencl 26 | PATH="$HOME/bin:$PATH" make 27 | make install 28 | make distclean 29 | 30 | #libx265 31 | sudo apt-get install cmake mercurial -y 32 | cd ~/ffmpeg_sources 33 | hg clone https://bitbucket.org/multicoreware/x265 34 | cd ~/ffmpeg_sources/x265/build/linux 35 | PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source 36 | make 37 | make install 38 | make distclean 39 | 40 | #acc 41 | cd ~/ffmpeg_sources 42 | wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master 43 | tar xzvf fdk-aac.tar.gz 44 | cd mstorsjo-fdk-aac* 45 | autoreconf -fiv 46 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 47 | make 48 | make install 49 | make distclean 50 | 51 | #lame 52 | sudo apt-get install nasm -y 53 | cd ~/ffmpeg_sources 54 | wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz 55 | tar xzvf lame-3.99.5.tar.gz 56 | cd lame-3.99.5 57 | ./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared 58 | make 59 | make install 60 | make distclean 61 | 62 | #opus 63 | cd ~/ffmpeg_sources 64 | wget http://downloads.xiph.org/releases/opus/opus-1.1.3.tar.gz 65 | tar xzvf opus-1.1.3.tar.gz 66 | cd opus-1.1.3 67 | ./configure --prefix="$HOME/ffmpeg_build" --disable-shared 68 | make 69 | make install 70 | make clean 71 | 72 | #vpx 73 | cd ~/ffmpeg_sources 74 | wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.0.tar.bz2 75 | tar xjvf libvpx-1.6.0.tar.bz2 76 | cd libvpx-1.6.0 77 | PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests 78 | PATH="$HOME/bin:$PATH" make 79 | make install 80 | make clean 81 | 82 | ## openssl 83 | cd ~/ffmpeg_sources 84 | wget https://www.openssl.org/source/openssl-fips-2.0.14.tar.gz 85 | tar -xvzf openssl-fips-2.0.14.tar.gz 86 | cd openssl-fips-2.0.14/ 87 | ./config --prefix=/usr 88 | sudo make 89 | sudo checkinstall 90 | 91 | ##ffmpeg 92 | cd ~/ffmpeg_sources 93 | wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 94 | tar xjvf ffmpeg-snapshot.tar.bz2 95 | cd ffmpeg 96 | PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \ 97 | --prefix="$HOME/ffmpeg_build" \ 98 | --pkg-config-flags="--static" \ 99 | --extra-cflags="-I$HOME/ffmpeg_build/include" \ 100 | --extra-ldflags="-L$HOME/ffmpeg_build/lib" \ 101 | --bindir="$HOME/bin" \ 102 | --enable-gpl \ 103 | --enable-libass \ 104 | --enable-libfdk-aac \ 105 | --enable-libfreetype \ 106 | --enable-libmp3lame \ 107 | --enable-libopus \ 108 | --enable-libtheora \ 109 | --enable-libvorbis \ 110 | --enable-libvpx \ 111 | --enable-libx264 \ 112 | --enable-libx265 \ 113 | --enable-openssl \ 114 | --enable-nonfree 115 | PATH="$HOME/bin:$PATH" make 116 | make install 117 | make distclean 118 | hash -r 119 | 120 | cp ~/bin/* /bin/ 121 | -------------------------------------------------------------------------------- /Script/ffmpeg-ubuntu-ppa.sh: -------------------------------------------------------------------------------- 1 | sudo add-apt-repository ppa:mc3man/trusty-media 2 | sudo apt-get update 3 | apt-get install -y ffmpeg -------------------------------------------------------------------------------- /Script/multi-quality.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | VIDSOURCE="$1" 3 | RESOLUTION1="1280x720" 4 | RESOLUTION2="720x480" 5 | RESOLUTION3="480x360" 6 | 7 | AUDIO_OPTS="-c:a libfdk_aac -b:a 128k -ac 2" 8 | 9 | VIDEO_OPTS1="-s $RESOLUTION1 -c:v libx264 -vprofile baseline -preset medium -x264opts level=41" 10 | VIDEO_OPTS2="-s $RESOLUTION2 -c:v libx264 -vprofile baseline -preset medium -x264opts level=41" 11 | VIDEO_OPTS3="-s $RESOLUTION3 -c:v libx264 -vprofile baseline -preset medium -x264opts level=41" 12 | OUTPUT_HLS="-start_number 0 -hls_time 10 -hls_list_size 0 -f hls" 13 | 14 | ffmpeg -i "$VIDSOURCE" -y -threads 4 $AUDIO_OPTS $VIDEO_OPTS1 $OUTPUT_HLS stream_hi.m3u8 $AUDIO_OPTS $VIDEO_OPTS2 $OUTPUT_HLS stream_med.m3u8 $AUDIO_OPTS $VIDEO_OPTS3 $OUTPUT_HLS stream_low.m3u8 15 | 16 | 17 | #Playlist 18 | cat > index.m3u8 << 123 19 | #EXTM3U 20 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=500000, RESOLUTION=480x360 21 | stream_low.m3u8 22 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=700000, RESOLUTION=720x480 23 | stream_med.m3u8 24 | #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=900000, RESOLUTION=1280x720 25 | stream_hi.m3u8 26 | 123 -------------------------------------------------------------------------------- /Script/org-convert-ts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | clear 3 | echo -e "Powered by MediTech JSC,.. & LongVan IDC\nScript tu dong chuyen doi cac file co cac dinh dang *.mp4, *.mkv, *.flv, *.webm, *.mov, *.avi thanh cac file .ts (Streaming).\nLuu y: Khi chuyen doi xong, file goc se bi xoa.\nBam [Enter] de tiep tuc...\nBam [CTRL] + [C] de huy bo." 4 | # Tim DocumentRoot cua Webserver 5 | if [ -e /etc/httpd/conf/httpd.conf ]; then 6 | DOC_ROOT=`grep -i 'DocumentRoot' /etc/httpd/conf/httpd.conf | sed '/^#/ d' | awk {'print $2'} | sed -r 's/"//g'` 7 | echo "Ban dang su dung Apache." 8 | else if [ -e /etc/nginx/nginx.conf ]; then 9 | DOC_ROOT=`grep -v '^$\|^\s*\#' /etc/nginx/conf.d/*.conf |grep root | awk '!a[$0]++' | cut -d' ' -f2-20 | tr ';' ' ' | xargs | awk '{print $2}'` 10 | echo "Ban dang su dung NGINX." 11 | fi 12 | fi 13 | read -e -i $DOC_ROOT -p "Nhap dia chi DocumentRoot cua Webserver: " DOC_ROOT 14 | read -e -i /opt/videos -p "Nhap thu muc video cua ban: " VIDEO 15 | cd $VIDEO 16 | # Doi ten file chua dau " " va dau cham (.) 17 | for fname in *\.*; 18 | do 19 | name="${fname%\.*}" 20 | extension="${fname#$name}" 21 | newname="${name//./_}" 22 | newfname="$newname""$extension" 23 | if [ "$fname" != "$newfname" ]; then 24 | mv "$fname" "$newfname" 25 | fi 26 | done 27 | for f in *\ * 28 | do 29 | mv "$f" "${f// /_}" 30 | done 31 | 32 | # Tao thu muc theo thang/nam 33 | year=`date +%Y` 34 | month=`date +%m` 35 | cd $VIDEO 36 | # Liet ke cac file video co trong thu muc hien tai 37 | list=`ls $VIDEO | egrep '*.mp4|*.mkv|*.flv|*.webm|*.mov|*.avi'` 38 | echo -e "Danh sach video co trong tu muc: \n" $list 39 | if [ -z "$list" ]; then 40 | for x in {5..1} 41 | do 42 | clear 43 | RED='\033[0;31m' 44 | NC='\033[0m' # No Color 45 | echo -e "Powered by MediTech JSC,.. & LongVan IDC\n${RED}Khong co file trong thu muc, script se tu dong thoat sau $x.\n" 46 | sleep 1 47 | done 48 | clear 49 | exit 50 | else 51 | read -p 'Bam [Enter]...' 52 | date >> /opt/list-stream.txt 53 | for file in $list 54 | do 55 | eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width $file) 56 | size=${streams_stream_0_width}x${streams_stream_0_height} 57 | folder=`echo $file | tr '.' ' ' | awk {'print $1'}` 58 | REPO=$DOC_ROOT/upload/$year/$month/$folder 59 | mkdir -p $REPO 60 | ffmpeg -y -i $file -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -s $size -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list $REPO/index.m3u8 -segment_list_flags +live-cache -segment_time 5 $REPO/$file-%04d.ts 61 | ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` 62 | #rm -rf $file 63 | echo "http://$ip/upload/$year/$month/$folder/index.m3u8" >> /opt/list-stream.txt 64 | echo "Danh sach stream duoc luu tai: /opt/list-stream.txt" 65 | done 66 | fi 67 | -------------------------------------------------------------------------------- /Script/post-livesteam.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ports=`netstat -npl | awk {'print $4'} | awk -F ':' {'print $2'} | sed '/^\s*$/d'` 4 | port1=`awk 'BEGIN{srand();print int(rand()*(5500-2000))+2000 }'` 5 | port2=$((port1+69)) 6 | 7 | #echo "Usage: sp-stream sop://:3092/29393 " 8 | #echo "Cac port dang duoc su dung: " $ports 9 | 10 | read -p "Nhap link Sopcast: " link 11 | read -p "Nhap ten Stream: " stream 12 | if [ -n $link ] 13 | then 14 | sp-sc $link $port1 $port2 > /dev/null & 15 | nohup ffmpeg -re -i "http://localhost:$port2" -c:v copy -c:a:0 libfdk_aac -b:a:0 480k -f flv rtmp://localhost/live/$stream & 16 | fi 17 | 18 | ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` 19 | echo "Link: rtmp://$ip/live/$stream" 20 | 21 | -------------------------------------------------------------------------------- /Script/sopcast-32bit/libstdc++5_3.3.6-17~ppa~karmic_i386.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/sopcast-32bit/libstdc++5_3.3.6-17~ppa~karmic_i386.deb -------------------------------------------------------------------------------- /Script/sopcast-32bit/sopcast-player_0.8.5~ppa1_i386.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/sopcast-32bit/sopcast-player_0.8.5~ppa1_i386.deb -------------------------------------------------------------------------------- /Script/sopcast-32bit/sp-auth-3.2.6-69.1stella.x86_64.rpm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/sopcast-32bit/sp-auth-3.2.6-69.1stella.x86_64.rpm -------------------------------------------------------------------------------- /Script/sopcast-32bit/sp-auth_3.2.6~ppa1_i386.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/Script/sopcast-32bit/sp-auth_3.2.6~ppa1_i386.deb -------------------------------------------------------------------------------- /Script/sopcast-ubuntu-amd64-v1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # yum group install "Development Tools" -yum 4 | # yum install -y wget tar zip 5 | # yum install libgcc_s.so.1 -y 6 | # mkdir -p /opt/sopcast 7 | # cd /opt/sopcast 8 | # wget http://download.sopcast.com/download/sp-auth.tgz 9 | # wget http://www.sopcast.com/download/libstdcpp5.tgz 10 | # cd /opt/sopcast 11 | # tar xzf sp-auth.tgz 12 | # tar xzf libstdcpp5.tgz 13 | # cd /opt/sopcast/usr/lib 14 | # cp -a libstdc++.so.5* /usr/lib 15 | # cp /opt/sopcast/sp-auth/sp-sc-auth /usr/bin/ 16 | 17 | 18 | apt-get update -y 19 | wget http://ppa.launchpad.net/lyc256/sopcast-player/ubuntu/pool/main/s/sp-auth/sp-auth_3.2.6~ppa1_amd64.deb 20 | wget http://ppa.launchpad.net/lyc256/sopcast-player/ubuntu/pool/main/s/sopcast-player/sopcast-player_0.8.5~ppa1_amd64.deb 21 | apt-get install python -y 22 | apt-get install -f 23 | apt-get install vlc -y 24 | dpkg -i sopcast-player_0.8.5~ppa1_amd64.deb 25 | dpkg -i sp-auth_3.2.6~ppa1_amd64.deb -------------------------------------------------------------------------------- /Script/sopcast-ubuntu-amd64-v2.sh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # yum group install "Development Tools" -yum 4 | # yum install -y wget tar zip 5 | # yum install libgcc_s.so.1 -y 6 | # mkdir -p /opt/sopcast 7 | # cd /opt/sopcast 8 | # wget http://download.sopcast.com/download/sp-auth.tgz 9 | # wget http://www.sopcast.com/download/libstdcpp5.tgz 10 | # cd /opt/sopcast 11 | # tar xzf sp-auth.tgz 12 | # tar xzf libstdcpp5.tgz 13 | # cd /opt/sopcast/usr/lib 14 | # cp -a libstdc++.so.5* /usr/lib 15 | # cp /opt/sopcast/sp-auth/sp-sc-auth /usr/bin/ 16 | 17 | apt-get update -y 18 | apt-get install gcc vlc wget -y 19 | wget http://ppa.launchpad.net/lyc256/sopcast-player/ubuntu/pool/main/s/sp-auth/sp-auth_3.2.6~ppa1_amd64.deb 20 | wget http://ppa.launchpad.net/lyc256/sopcast-player/ubuntu/pool/main/s/sopcast-player/sopcast-player_0.8.5~ppa1_amd64.deb 21 | dpkg -i sp-auth_3.2.6~ppa1_amd64.deb 22 | dpkg -i sopcast-player_0.8.5~ppa1_amd64.deb 23 | apt-get install -y python 24 | apt-get install -f -y 25 | echo "Test: sp-sc sop://broker.sopcast.com:3912/128789 2222 80" 26 | -------------------------------------------------------------------------------- /Script/torrent-video.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | sudo apt-get install curl 4 | curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - 5 | sudo apt-get install nodejs 6 | sudo npm install -g peerflix 7 | 8 | sudo apt-get install vlc xterm python-libtorrent wget 9 | wget https://raw.github.com/hotice/webupd8/master/Torrent-Video-Player -O /tmp/Torrent-Video-Player 10 | sudo install /tmp/Torrent-Video-Player /usr/local/bin/ 11 | 12 | wget https://raw.github.com/danfolkes/Magnet2Torrent/master/Magnet_To_Torrent2.py -O /tmp/Magnet_To_Torrent2.py 13 | sudo install /tmp/Magnet_To_Torrent2.py /usr/local/bin/ 14 | wget https://raw.github.com/hotice/webupd8/master/Magnet-Video-Player -O /tmp/Magnet-Video-Player 15 | sudo install /tmp/Magnet-Video-Player /usr/local/bin/ 16 | 17 | echo -e "peerflix http://some-torrent/movie.torrent\nPlay: http://ip-addr:8888" -------------------------------------------------------------------------------- /Script/video.txt: -------------------------------------------------------------------------------- 1 | 792 259 486 2 | // Get resolution video: 3 | http://stackoverflow.com/questions/684015/how-can-i-get-the-resolution-width-and-height-for-a-video-file-from-a-linux-co 4 | 5 | a=$(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width input.mkv) 6 | size=${streams_stream_0_width}x${streams_stream_0_height} 7 | echo $size 8 | 9 | // Convert video to ts (No set bitrate) 10 | 11 | ffmpeg -y -i ABC.mp4 -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -s 1280x720 -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list ./test/ABC.m3u8 -segment_list_flags +live-cache -segment_time 5 ./test/ABC-6b%04d.ts 12 | // vtc9 13 | http://vtc9.tivi12h.net:1935/live/myStream/chunklist.m3u8?wowzasessionid=1 14 | http://14.161.5.88:1935/live/myStream/playlist.m3u8 15 | http://103.21.148.45:81/icomchannelvtc/smil:vtc9_adb_security.smil/chunklist_b628000_sleng.m3u8 16 | 17 | 18 | // Render 19 | 20 | ffmpeg input.mp4 -filter_complex "nullsrc=size=1920x1080 [vmain]: [0:v] setpts=PTS-STARTPTS, scale=in_w/2:in_h [vleft]; [0:v] setpts=PTS-STARTPTS, cropasin_w:in_h/2:x=1:y=270, scale=in_w/2:in_h [vright]: [mmain][vleft] overlay=shortest=1 [vidl]; [vidl][vright] overlay=shortest=1:x=960:y=270" -vcodec libx264 -profile:v high -level 4.0 -coder 1 -refs 3 -preset ultrafast -b:v 2680k -minrate 2680k -maxrate 2680k -bufsize Ok -c:a copy output.mp4 21 | 22 | // m3u8 to mp4 23 | 24 | 25 | ffmpeg -i list.m3u8 -bsf:a aac_adtstoasc -vcodec copy -c copy -crf 50 file.mp4 26 | 27 | http://stackoverflow.com/questions/33108105/converting-an-hls-m3u8-to-mp4 28 | 29 | --- 30 | // Video to TS (set bitrate) 31 | 32 | ffmpeg -y -i /usr/share/nginx/html/video.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 /usr/share/nginx/html/video/file.m3u8 -segment_list_flags +live-cache -segment_time 5 /usr/share/nginx/html/video/file-%04d.ts 33 | 34 | --- 35 | 36 | ffmpeg -i vlk2.webm -i lk2.webm -vf drawtext="fontfile=/root/test1/ARIAL.TTF: text='YouTube.com/VideosTongHop': fontcolor=white: fontsize=24: box=1: boxcolor=black@0.5: boxborderw=5: x=20: y=20" -c:v libx264 -s 1280x720 -c copy -map 0:0 -map 1:0 -shortest lk2.mp4 37 | 38 | 39 | // Mux video 40 | Với MAP: 41 | Ở 1 video 0 là HÌNH, 1 là TIẾNG 42 | Ví dụ lấy HÌNH video 1, âm thanh video 2 43 | 44 | ffmpeg -i input_0.mp4 -i input_1.mp4 -c copy -map 0:0 -map 1:1 -shortest out.mp4 45 | // Âm thanh thì chỉ có 1 kênh 0 46 | 47 | // Crop video 48 | 49 | ffmpeg -i p3.mp4 -filter:v "crop=858:480" -s 1280x720 out.mp4 50 | // Giữa video 51 | 52 | LIVE 53 | ffmpeg -i demo.mp4 -y -c:v libx264 -vprofile baseline -preset medium -x264opts level=41 -threads 4 -s 1280x720 -map 0:v -map 0:a:0 -c:a libfdk_aac -b:a 160000 -ac 2 -hls_time 10 -hls_list_size 6 -hls_wrap 18 -start_number 1 ./tmp/stream.m3u8 54 | 55 | 56 | ffmpeg -i input.mp4 -af "atempo=1.27,volume=1.6" -vf "hflip ,setpts=PTS/1.27,"crop=iw/2:ih/2",scale=1280:720,boxblur=1:1 [mv]; movie=90xanh.png [f1]; [mv][f1]overlay=0:0" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 2500k -acodec libmp3lame -b:a 128k -ar 44100 -preset ultrafast output.mp4 57 | 58 | 59 | ffmpeg -i input.mp4 -af "atempo=1.27,volume=1.6" -vf "hflip ,setpts=PTS/1.27,scale=1280:720,"crop=iw/2:ih/2",boxblur=1:1 [mv]; movie=90xanh.png[opacity=50%];[mv][opacity=50%]overlay=0:0" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 2500k -acodec libmp3lame -b:a 128k -ar 44100 -preset ultrafast -preset ultrafast output.mp4 60 | 61 | ngoài. https://www.reddit.com/ 62 | http://www.4chan.org/ 63 | https://www.quora.com/ 64 | http://www.myvidster.com/ 65 | https://www.buzzfeed.com/ 66 | http://www.cinemahaven.com 67 | http://videosift.com/ 68 | http://www.wonderhowto.com/ 69 | còn tiếp các bác tự tìm hiểu nha. 70 | 71 | 1.https://www.reddit.com/ 72 | 2.http://www.4chan.org/ 73 | 3.https://www.quora.com/ 74 | 4.http://www.myvidster.com/ 75 | 5.https://www.buzzfeed.com/ 76 | 6.http://www.cinemahaven.com 77 | 7.http://videosift.com/ 78 | 8.http://www.wonderhowto.com/ 79 | 9.https://www.quora.com/ 80 | 10.https://www.reddit.com/ 81 | http://www.stumbleupon.com/ 82 | http://digg.com/submit 83 | https://delicious.com/ 84 | http://www.yemle.com/ 85 | http://www.stupidvideos.com/ 86 | http://www.cheezburger.com/ 87 | http://lemmino.deviantart.com/ 88 | http://www.wikia.com/Wikia 89 | https://www.minds.com/ 90 | http://vidstatsx.com/ 91 | http://forum.bodybuilding.com/ 92 | http://memebase.cheezburger.com/ 93 | https://vine.co/ 94 | http://www.funnyjunk.com/member 95 | http://linkis.com/ 96 | https://huzzaz.com/ 97 | http://www.disclose.tv/ 98 | http://www.wykop.pl/ 99 | http://www.break.com/ 100 | https://onlywire.com/secure/networks 101 | http://www.metacafe.com/ 102 | http://www.world-of- lucid-dreaming.com/forum/ 103 | http://www.livejournal.com/ 104 | https://www.instapaper.com/ 105 | https://www.plurk.com/ 106 | https://getpocket.com/ 107 | http://www.skyrock.com/ 108 | http://www.tagged.com/?loc=en_US 109 | https://www.xing.com/en 110 | https://tagloom.com/ 111 | https://voat.co/v/ 112 | http://www.f169bbs.com/bbs/news/ 113 | http://www.fark.com/ 114 | https://vid.me/ 115 | http://www.thetoptens.com/ 116 | http://newshustle.com/ 117 | https://flipboard.com/@denharsh 118 | http://www.buzzfeed.com/post 119 | http://buzzfeed.tumblr.com/submit 120 | http://mashable.com/submit/ 121 | http://gawker.com/370687/submit-a- story-to- gawkercom 122 | http://www.huffingtonpost.com/contact/ 123 | http://boingboing.net/s/submitterator/ 124 | http://www.upworthy.com/submit 125 | http://gawker.com/370687/submit-a- story-to- gawkercom 126 | http://www.humortimes.com/videos/1805-user- submitted-videos/submission- form/ 127 | https://www.playbuzz.com/ 128 | http://junkee.com/about 129 | http://www.worldstarhiphop.com/videos/vsent.php 130 | https://submit.gopro.com/ 131 | http://devour.com/submit/ 132 | http://www.itgetsbetter.org/page/s/submit-a- video 133 | http://newshustle.com/ 134 | http://www.cabronazi.com/ 135 | 136 | trang này lấy phim hoạt hình 137 | kisscartoon.me 138 | http://www.cartoonnetworkasia.com/ 139 | trang này lấy show pháp 140 | topreplay.com 141 | trang này lấy show mỹ http://freeform.go.com/ 142 | watchseries.ac http://www.watchseriesgo.to/link/allmyvideos.net/6058460 143 | 144 | 0:10, 3:30, 7:00, 10:30, 14:00, 17:30, 21:00, 24:30, 28:00, 31:30, 35:00, 38:30, 42:00, 45:30, 49:00, 52:30, 56:00, 1:03:30, 1:07:00, 1:10:30, 1:14:00, 1:17:30, 1:21:00, 1:24:30, 1:28:00, 1:31:30, 1:35:00, 1:38:30, 1:42:00, 1:45:30, 1:49:00, 1:52:30, 1:56:00, 2:03:30, 2:07:00, 2:10:30, 2:14:00, 2:17:30, 2:21:00, 2:24:30, 2:28:00, 2:31:30, 2:35:00, 2:38:30, 2:42:00, 2:45:30, 2:49:00, 2:52:30, 2:56:00, 3:03:30, 3:07:00, 3:10:30, 3:14:00, 3:17:30, 3:21:00, 3:24:30, 3:28:00, 3:31:30, 3:35:00, 3:38:30, 3:42:00, 3:45:30, 3:49:00, 3:52:30, 3:56:00, 4:03:30, 4:07:00, 4:10:30, 4:14:00, 4:17:30, 4:21:00, 4:24:30, 4:28:00, 4:31:30, 4:35:00, 4:38:30, 4:42:00, 4:45:30, 4:49:00, 4:52:30, 4:56:00, 5:03:30, 5:07:00, 5:10:30, 5:14:00, 5:17:30, 5:21:00, 5:24:30, 5:28:00, 5:31:30, 5:35:00, 5:38:30, 5:42:00, 5:45:30, 5:49:00, 5:52:30, 5:56:00 145 | 146 | 0:25, 7:30, 15:00, 22:30, 30:00, 37:30, 45:00, 52:30, 1:00:00, 1:07:30, 1:15:00, 1:22:30, 1:30:00, 1:37:30, 1:45:00, 1:52:30, 2:00:00, 2:07:30, 2:15:00, 2:22:30, 2:30:00, 2:37:30, 2:45:00, 2:52:30, 3:00:00, 3:07:30, 3:15:00, 3:22:30, 3:30:00, 3:37:30, 3:45:00, 3:52:30, 4:00:00, 4:07:30, 4:15:00, 4:22:30, 4:30:00, 4:37:30, 4:45:00, 4:52:30, 5:00:00, 5:07:30, 5:15:00, 5:22:30, 5:30:00, 5:37:30, 5:45:00, 5:52:30, 6:00:00, 6:07:30, 6:15:00, 6:22:30, 6:30:00, 6:37:30, 6:45:00, 6:52:30, 7:00:00, 7:07:30, 7:15:00, 7:22:30, 7:30:00, 7:37:30, 7:45:00, 7:52:30, 8:00:00, 8:07:30, 8:15:00, 8:22:30, 8:30:00, 8:37:30, 8:45:00, 8:52:30, 9:00:00, 9:07:30, 9:15:00, 9:22:30, 9:30:00, 9:37:30, 9:45:00, 9:52:30, 10:00:00, 10:07:30, 10:15:00, 10:22:30, 10:30:00, 10:37:30, 10:45:00, 10:52:30, 11:00:00, 11:07:30, 11:15:00, 11:22:30, 11:30:00, 11:37:30, 11:45:00, 11:52:30 147 | 148 | http://www.allure.com/ 149 | http://beauty.about.com/od/allaboutyoureyes/qt/bigeyes.htm 150 | http://www.howcast.com/guides/600-how-to-get-a-tattoo/ 151 | 152 | http://akb48awesome.blogspot.co.uk/2016/11/161110-akb48.html 153 | 154 | http://stream10.tv.zdn.vn/streaming/9422011389a6f4259b5b3f6114587387/58147894/Video480/2015/0429/da/d621a22179e5660b0e556b662b65df98.mp4?format=f480&device=other 155 | http://www.nogizaka46.com/video/index.php?bclid=2syunen 156 | 157 | http://hls.vcmedia.vn/vtv/ownw8ttzjcwzpvkgxkvrk1yp3poiy0/2016/11/01/01112016-phim-v1-1478013319531-25e07.mp4/master.m3u8 158 | 159 | 4 46 55 160 | 4 52 21 161 | 162 | Code lách bản quyền hình ảnh-âm thanh phim cho người mới. 163 | ffmpeg -y -i "{input}.*" -i "{input}.*" -i "Filter_HD_Pixel10.png" -filter_complex "[0:v]setpts=PTS/1.1, scale=4*iw:-1, crop=iw/4:ih/4, boxblur=5:1, scale=854:480[v1],[v1][2:v]overlay=0:0[vmain];[1:v] setpts=PTS/1.1, scale=530:320,pad=538:328:4:4:color=white, boxblur=1:0[vo];[vmain][vo] overlay=10:8, hue=s=1.5[vout];[0:a] atempo=1.1, aecho=0.8:0.88:6:0.4, aecho=0.4:0.66:2:0.2,aecho=0.8:0.88:60:0.4, equalizer = f = 1000: width_type = q: width = 1: g = 2,equalizer = f = 100: width_type = q: width = 2: g = -5 ,volume=1.5 [aout]" -map "[vout]" -map "[aout]" -vcodec libx264 -pix_fmt yuv420p -r 30 -g 60 -b:v 680k -profile:v main -level 3.1 -acodec libmp3lame -b:a 128k -ar 44100 -metadata title="" -metadata artist="" -metadata album_artist="" -metadata album="" -metadata date="" -metadata track="" -metadata genre="" -metadata publisher="" -metadata encoded_by="" -metadata copyright="" -metadata composer="" -metadata performer="" -metadata TIT1="" -metadata TIT3="" -metadata disc="" -metadata TKEY="" -metadata TBPM="" -metadata language="eng" -metadata encoder="" -threads 0 -preset superfast "{output}.mp4" 164 | Ý nghĩa các con số cơ bản: 165 | Filter_HD_Pixel10.png : Ảnh làm mờ video 166 | - crop=iw/4:ih/4: Tỷ lệ crop video nền, số 4 có nghĩa là phóng to 4 lần 167 | - boxblur=5:1: Đây là độ mờ của video nền, cái này các tự tìm hiểu, hình như là tối đa 8:8 168 | - scale=854:480: Đây là định dạng đầu ra của video nền - 480p. Cái này phải khớp với định dạng của ảnh làm mờ "Filter_HD_Pixel10.png", ở đây ảnh có định dạng 480p nên video đầu ra phải là 480p. 169 | - setpts=PTS/1.1 : tăng tốc độ chạy video lên 1.1, cái này phải khớp với tốc độ âm thanh atempo=1.1 ở đoạn code lách âm. 170 | - scale=530:320,pad=538:328:4:4:color=white : 530:320 là chiều dài, rộng của video chính, video càng nặng bảng quyền thì các bác chỉnh thông số này càng nhỏ xuống là được, 4:4 là độ rộng của viền video, white làm màu viền, 538:328 là 530+4x2 và 320+4x2. Các số này đều có thể chỉnh sửa được, nhưng phải khớp nhau. 171 | - overlay=10:8 Là vị trí đặt video chính, ở đây mình chọn góc phía trên bên trái nên đặt là 10:8, nếu bác nào muốn đặt phía dưới bên phải thì là 316:152, vì video nền định dạng là 854:480 nên nếu chuyển video xuống góc dưới bên phải thì 854-538=316, 480-328=152, con số 316:152 ở đây ra đấy. Các bác có thể thay đổi thông số này sao cho thích thì thôi. 172 | - atempo=1.1, aecho=0.8:0.88:6:0.4, aecho=0.4:0.66:2:0.2,aecho=0.8:0.88:60:0.4 : Đây là code lách âm thanh, còn mạnh nữa thì thêm đoạn này vào aecho=0.8:0.9:1000:0.3,aecho=0.8:0.9:1000|1800:0.3|0.25 173 | Các bác muốn thêm chữ kêu gọi theo dõi hay like hay v.v lên video thi chỉ cần vào trang sửa ảnh online https://pixlr.com/editor/ rồi chỉnh sửa ảnh Filter_HD_Pixel10.png tại đó các bác thêm chữ các bạn muốn vào. Khi xuất ảnh nhớ xuất đuôi png. 174 | Phần mềm render MyRenderTools 1.0.0.4 cho bác nào chưa biết. 175 | - Link ảnh Filter_HD_Pixel10.png : http://2.pi/ k.vn/20163c21cfcf-b865-4c88-8ffe-aa2208085ae0.png 176 | tải ảnh về các bác nhớ đặt tên là Filter_HD_Pixel10 177 | Ảnh phải là định dạng png đấy mn. 178 | Hết. 179 | Tiện thể xin key, bác nào có key ngon cho em xin vào ib với, dạo đói quá. 180 | https://www.youtube.com/watch?v=vkYA5JmRWk8 181 | 18 15 55 16 -------------------------------------------------------------------------------- /Setup-NGINX-RTMP.md: -------------------------------------------------------------------------------- 1 | # Hướng dẫn cài đặt NIGNX-RTMP 2 | 3 | ## Nội dung bài viết 4 | 5 | [1. Chuẩn bị ](#1) 6 | 7 | [2. Cài đặt và cấu hình ](#2) 8 | 9 | - [2.1 Biên dịch NIGNX-RTMP ](#2.1) 10 | 11 | - [2.2 Cấu hình RTMP ](#2.2) 12 | 13 | - [2.3 Cấu hình HTTP Server cho HLS và DASH ](#2.3) 14 | 15 | - [2.4 Cấu hình HLS ](#2.4) 16 | 17 | - [2.5 Cấu hình DASH ](#2.5) 18 | 19 | - [2.6 File cấu hình hoàn chỉnh ](#2.6) 20 | 21 | [3. Kết luận ](#3) 22 | 23 | ### 1. Chuẩn bị 24 | 25 | **Thông tin về server:** 26 | 27 | ``` 28 | OS: Ubuntu 16.04 29 | RAM: 2GB 30 | Cores: 2 31 | Bandwidth: 1Gb/s 32 | eth0: 192.168.100.197 33 | Gateway: 192.168.100.1 34 | NETWORK: 192.168.100.0/24 35 | ``` 36 | 37 | 38 | 39 | ### 2. Cài đặt và cấu hình 40 | 41 | #### 2.1 Biên dịch NIGNX-RTMP 42 | 43 | **Cài đặt các trình biên dịch:** 44 | 45 | ``` 46 | apt-get update -y 47 | apt-get install build-essential libpcre3 libpcre3-dev libssl-dev git wget dpkg-dev zlib1g-dev unzip -y 48 | ``` 49 | 50 | **Tải các gói cài đặt cần thiết:** 51 | 52 | #### NGINX và giải nén 53 | 54 | ``` 55 | wget http://nginx.org/download/nginx-1.10.1.tar.gz 56 | tar -xf nginx-1.10.1.tar.gz 57 | ``` 58 | 59 | #### Module RTMP 60 | 61 | ``` 62 | git clone https://github.com/arut/nginx-rtmp-module.git 63 | ``` 64 | 65 | **Biên dịch chương trình:** 66 | 67 | ``` 68 | cd nginx-1.10.1 69 | ./configure --user=nginx --group=nginx --add-module=../nginx-rtmp-module/ --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 70 | 71 | make 72 | make install 73 | ``` 74 | 75 | **Tạo User `nginx` và phân quyền cho một số thư mục đặc biệt của `nginx-rtmp`** 76 | 77 | ``` 78 | useradd -r nginx 79 | mkdir -p /var/cache/nginx/client_temp/ 80 | mkdir -p /etc/nginx/html/vod/ 81 | mkdir -p /etc/nginx/html/dash/ 82 | mkdir -p /etc/nginx/html/hls/ 83 | chown nginx. /etc/nginx/html/hls/ 84 | chown nginx. /etc/nginx/html/vod/ 85 | chown nginx. /var/cache/nginx/client_temp/ 86 | ``` 87 | 88 | **Tạo file `crossdomain.xml` cho phép client đọc file HLS** 89 | 90 | ``` 91 | vi /etc/nginx/html/crossdomain.xml 92 | ``` 93 | 94 | Với nội dung như sau: 95 | 96 | ``` 97 | 98 | 99 | 100 | 101 | ``` 102 | 103 | #### 2.2 Cấu hình RTMP 104 | 105 | Băng thông cho RTMP khá nhẹ, push chất lượng HD thì dung lượng ~ 500KB cho một stream. 106 | 107 | Mở cấu hình `/etc/nginx/nginx.conf` và thêm block `rtmp` vào file 108 | 109 | ``` 110 | rtmp { 111 | server { 112 | listen 1935; 113 | application vod { 114 | play /etc/nginx/html/vod; 115 | } 116 | 117 | application live { 118 | live on; 119 | record off; 120 | } 121 | # # Record stream 122 | # record all; 123 | # record_path /etc/nginx/html/vod/; 124 | # record_suffix -%d-%b-%y-%T.flv; 125 | # record_notify on; 126 | 127 | } 128 | } 129 | ``` 130 | 131 | ##### Chú thích: 132 | 133 | - `listen 1935;`: Cổng lắng nghe của RTMP, mặc định 1935 134 | - `application live`: Khai báo một app tên là `live` 135 | - `live on;`: Cho phép live. Sử dụng để push và play stream `rtmp://ip-server/live/stream-name` 136 | - `play /path/to/folder;`: Cho phép Play các video ở trong thư mục khai báo theo giao thức RTMP. `rtmp://ip-server/vod/file-name.mp4` 137 | 138 | #### 2.3 Cấu hình HTTP Server cho HLS và DASH 139 | 140 | Băng thông cho HLS và DASH khá tốn, play một stream chất lượng HD thì dung lượng >= 1MB/s cho một stream. 141 | 142 | Thêm block `http` và file cấu hình `nginx.conf` 143 | 144 | ``` 145 | http { 146 | include mime.types; 147 | default_type application/octet-stream; 148 | 149 | sendfile on; 150 | #tcp_nopush on; 151 | 152 | #keepalive_timeout 0; 153 | keepalive_timeout 65; 154 | 155 | gzip on; 156 | 157 | server { 158 | listen 80; 159 | server_name localhost; 160 | server_tokens off; 161 | #charset koi8-r; 162 | 163 | access_log /var/log/nginx/access_http_log combined; 164 | error_log /var/log/nginx/error_http_log; 165 | location / { 166 | root html; 167 | index index.html index.htm; 168 | } 169 | 170 | #error_page 404 /404.html; 171 | 172 | # redirect server error pages to the static page /50x.html 173 | # 174 | error_page 500 502 503 504 /50x.html; 175 | location = /50x.html { 176 | root html; 177 | } 178 | location /stat { 179 | rtmp_stat all; 180 | rtmp_stat_stylesheet stat.xsl; 181 | } 182 | 183 | location /stat.xsl { 184 | root html; 185 | } 186 | } 187 | ``` 188 | 189 | #### 2.4 Cấu hình HLS 190 | 191 | Thêm một vài dòng cấu hình sau vào app bạn muốn sử dụng HLS: 192 | 193 | ``` 194 | hls on; # Bat HLS 195 | hls_nested; # Cho cac stream vao trong 1 thu muc co ten ~ stream 196 | hls_path /etc/nginx/html/hls; # Thu muc chua stream 197 | hls_fragment 3; # Do dai cua stream 198 | hls_playlist_length 10; # Do dai cua playlist 199 | ``` 200 | 201 | Ví dụ thêm vào app `live` 202 | 203 | ``` 204 | application live { 205 | live on; 206 | record off; 207 | # # Turn on HLS 208 | hls on; 209 | hls_nested; 210 | hls_path /etc/nginx/html/hls; 211 | hls_fragment 3; 212 | hls_playlist_length 10; 213 | } 214 | ``` 215 | 216 | #### 2.5 Cấu hình DASH 217 | 218 | Thêm một vài dòng cấu hình sau vào app bạn muốn sử dụng DASH: 219 | 220 | ``` 221 | dash on; # Bat dash 222 | dash_nested; # Cho cac stream vao trong 1 thu muc co ten ~ stream 223 | dash_path /etc/nginx/html/dash; # Thu muc chua stream 224 | dash_fragment 3; # Do dai cua stream 225 | dash_playlist_length 10; # Do dai cua playlist 226 | ``` 227 | 228 | Ví dụ thêm vào app `live` 229 | 230 | ``` 231 | application live { 232 | live on; 233 | record off; 234 | # # Turn on DASH 235 | dash on; 236 | dash_nested; 237 | dash_path /etc/nginx/html/dash; 238 | dash_fragment 3; 239 | dash_playlist_length 10; 240 | } 241 | ``` 242 | 243 | #### 2.6 File cấu hình hoàn chỉnh 244 | 245 | ``` 246 | user nginx; 247 | worker_processes auto; 248 | 249 | pid /var/run/nginx.pid; 250 | 251 | events { 252 | worker_connections 1024; 253 | } 254 | 255 | rtmp { 256 | server { 257 | listen 1935; 258 | access_log /var/log/nginx/access_rtmp_log combined; 259 | 260 | application vod { 261 | play /etc/nginx/html/vod; 262 | } 263 | 264 | application live { 265 | live on; 266 | record off; 267 | # # Turn on HLS 268 | hls on; 269 | hls_path /etc/nginx/html/hls; 270 | hls_fragment 3; 271 | hls_playlist_length 10; 272 | hls_nested on; 273 | # # Turn on DASH 274 | dash on; 275 | dash_nested on; 276 | dash_path /etc/nginx/html/dash; 277 | dash_fragment 3; 278 | dash_playlist_length 10; 279 | 280 | } 281 | # # Record stream 282 | # record all; 283 | # record_path /etc/nginx/html/vod/; 284 | # record_suffix -%d-%b-%y-%T.flv; 285 | # record_notify on; 286 | 287 | } 288 | } 289 | 290 | http { 291 | include mime.types; 292 | default_type application/octet-stream; 293 | 294 | sendfile on; 295 | #tcp_nopush on; 296 | 297 | #keepalive_timeout 0; 298 | keepalive_timeout 65; 299 | 300 | gzip on; 301 | 302 | server { 303 | listen 80; 304 | server_name localhost; 305 | server_tokens off; 306 | #charset koi8-r; 307 | 308 | access_log /var/log/nginx/access_http_log combined; 309 | error_log /var/log/nginx/error_http_log; 310 | location / { 311 | root html; 312 | index index.html index.htm; 313 | } 314 | 315 | # # Player get M3U8 316 | location /hls { 317 | # Disable cache 318 | add_header 'Cache-Control' 'no-cache'; 319 | 320 | # CORS setup 321 | add_header 'Access-Control-Allow-Origin' '*' always; 322 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 323 | add_header 'Access-Control-Allow-Headers' 'Range'; 324 | 325 | # allow CORS preflight requests 326 | if ($request_method = 'OPTIONS') { 327 | add_header 'Access-Control-Allow-Origin' '*'; 328 | add_header 'Access-Control-Allow-Headers' 'Range'; 329 | add_header 'Access-Control-Max-Age' 1728000; 330 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 331 | add_header 'Content-Length' 0; 332 | return 204; 333 | } 334 | 335 | types { 336 | application/dash+xml mpd; 337 | application/vnd.apple.mpegurl m3u8; 338 | video/mp2t ts; 339 | } 340 | root html; 341 | } 342 | 343 | #error_page 404 /404.html; 344 | 345 | # redirect server error pages to the static page /50x.html 346 | # 347 | error_page 500 502 503 504 /50x.html; 348 | location = /50x.html { 349 | root html; 350 | } 351 | location /stat { 352 | rtmp_stat all; 353 | rtmp_stat_stylesheet stat.xsl; 354 | } 355 | 356 | location /stat.xsl { 357 | root html; 358 | } 359 | } 360 | } 361 | 362 | ``` 363 | 364 | ### 3. Kết luận 365 | 366 | Trên đây là một số hướng dẫn về cấu hình một streamming server sử dụng phần mềm mã nguồn mở. Hy vọng có thể giúp các bạn hiểu thêm về công nghệ đang "Hót hòn họt" trên thị trường trong vài năm trở lại đây. Các bạn muốn tìm hiểu sâu hơn về lĩnh vực này vui lòng tìm hiểu trang chủ. 367 | 368 | Một vài kỹ thuật nâng cao như Secure stream, HA stream sẽ được cập nhật trong thời gian tới. Cảm ơn các bạn đã quan tâm! 369 | 370 | - http://nginx-rtmp.blogspot.com 371 | - https://github.com/arut/nginx-rtmp-module/wiki/Getting-started-with-nginx-rtmp 372 | - Directives: https://github.com/arut/nginx-rtmp-module/wiki/Directives -------------------------------------------------------------------------------- /ghichep-Wowza/README.md: -------------------------------------------------------------------------------- 1 | ## Hướng dẫn cài đặt và cấu hình Wowza Streaming Engine (Bản Trail) 2 | 3 | ### Menu 4 | 1. Tải bộ cài đặt 5 | 2. Cài đặt 6 | 3. Khởi động Wowza Engine 7 | 4. Thêm live video từ broadcaster 8 | 9 | ### 1. Tải bộ cài đặt 10 | 11 | Để tải bộ cài đặt Wowza Streaming Engine, chúng ta vào trang chủ tại 12 | 13 | ``` 14 | https://www.wowza.com/ 15 | ``` 16 | 17 | Sau đó, bấm vào `Trail` để tải bản cài đặt dùng thử 180 ngày. 18 | 19 | 20 | 21 | Chọn `Wowza Engine Streaming` 22 | 23 | 24 | 25 | Điền thông tin cá nhân của bạn, key trail sẽ được gửi và email của bạn 26 | 27 | 28 | 29 | Một bảng chọn platform hiện ra, chúng ta chọn Linux 64 bit 30 | 31 | 32 | 33 | Click chuột phải vào nút `Download` và chọn `Sao chép địa chỉ liên kết` (Đối với trình duyệt tiếng Việt) 34 | 35 | 36 | 37 | Sau đó, dùng `wget` để tải về trên Terminal 38 | 39 | 40 | 41 | Chúng ta check mail để lấy key mà Wowza đã gửi 42 | 43 | 44 | 45 | Email gửi về với nội dung chính là `License Key`, Thông tin của chủ key và ngày hết hạn 46 | 47 | ### 2. Cài đặt 48 | 49 | #### 2.1 Chuẩn bị môi trường cài đặt 50 | 51 | Wowza cần Java để thực thi các hoạt động, vì vậy chúng ta cần cài đặt Java JDK hoặc JRE Server, khuyến cáo từ trang chủ là dùng bản 8. 52 | 53 | ##### Tải JAVA mới nhất từ trang chủ: 54 | 55 | ``` 56 | http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 57 | ``` 58 | 59 | ##### Cài đặt 60 | 61 | Hiện tại, bản Java mới nhất là `jdk-8u111`. Sau khi tải về, chúng ta sẽ chạy cài đặt bằng lệnh `rpm` và cà đặt biến môi trường: 62 | 63 | 64 | 65 | ``` 66 | 67 | rpm -ivh jdk-8u111-linux-x64.rpm 68 | java -version 69 | export JAVA_HOME=/usr/java/jdk1.8.0_111/jre 70 | sh -c "echo export JAVA_HOME=/usr/java/jdk1.8.0_111/jre >> /etc/environment" 71 | 72 | ``` 73 | 74 | #### 2.2 Cài đặt Wowza Streaming Engine 75 | 76 | Sau khi tải xong bản setup của Wowza, chúng ta phân quyền cho nó bằng lệnh `chmod` và chạy cài đặt 77 | 78 | ``` 79 | chmod +x WowzaStreamingEngine-4.5.0-linux-x64-installer.run 80 | ./WowzaStreamingEngine-4.5.0-linux-x64-installer.run 81 | ``` 82 | 83 | Sau khi chạy file, setup sẽ hỏi chúng ta có muốn tiếp tục. Bấm `Enter` để đồng ý. 84 | 85 | 86 | 87 | Wowza sẽ đưa ra các điều khoản sử dụng, bấm `Enter` để cuộn trang. 88 | 89 | 90 | 91 | Chọn `Y` để Đồng ý với các điều khoản sử dụng 92 | 93 | 98 | 99 | Tạo tài khoản quản trị Wowza Streaming Engine 100 | 101 | 102 | 103 | Chúng ta chọn `Wowza Streaming Engine 4.5.0` và cho nó khởi động cùng với hệ thống 104 | 105 | 106 | 107 | Tiếp tục chọn `Y` và quá trình cài đặt sẽ diễn ra trong vài phút. Khi có thông báo như phần bôi đỏ trong hình thì quá trình cài đặt diễn ra thành công. 108 | 109 | 110 | 111 | Như vậy, chúng ta đã cài đặt xong Wowza. 112 | 113 | ### 3. Khởi động Wowza Engine 114 | 115 | Từ trình duyệt Web, chúng truy cập vào Wowza qua địa chỉ IP của Server và port `8088` và bấm `Next` 116 | 117 | 118 | 119 | **Chú ý**: Nếu không truy cập được, hãy kiểm tra lại `SELinux` và `iptables`. 120 | 121 | ``` 122 | sed -i s/SELINUX=enforcing/SELINUX=permissive/g /etc/selinux/config 123 | iptables -A INPUT -p tcp -m tcp --dport 8088 -j ACCEPT 124 | iptables -A INPUT -p tcp -m tcp --dport 1935 -j ACCEPT 125 | service iptables save 126 | service iptables reload 127 | ``` 128 | 129 | Tiếp theo, Wowza giới thiệu qua về workflow. Bấm `Next` để tiếp tục 130 | 131 | 132 | 133 | Đăng nhập bằng tài khoản quản lý mà chúng ta vừa tạo ở trên. 134 | 135 | 136 | 137 | Tạo user publisher để public các livestream, Bấm `Done` để vào Dashboard 138 | 139 | 140 | 141 | Giao diện Dashboard của Wowza, chúng ta có thể xem trạng thái của nó ở đây. 142 | 143 | 144 | 145 | 146 | 147 | 148 | ### 4. Thêm live video từ broadcaster 149 | -------------------------------------------------------------------------------- /ghichep-nginx-RTMP/LB_RTMP.txt: -------------------------------------------------------------------------------- 1 | // Nếu LB RTMP dùng pull 2 | // Nếu LB HLS dùng push 3 | 4 | // Phân tải RTMP 5 | C1: 6 | exec ffmpeg -re -i rtmp://localhost/live/$name -c copy -f flv rtmp://192.168.100.201/live/$name; // Đẩy stream cùng tên sang server 7 | 8 | Relay 9 | C2: 10 | 11 | pull rtmp://srv-orginal; 12 | Ý tưởng: 13 | | | 14 | |Server Relay| 15 | | NGINX | 16 | |Server Orginal| 17 | PLAY: HAProxy: 1935 18 | POST: Nginx: 1936 19 | | | 20 | |Server Relay| 21 | | NGINX | 22 | 23 | Cấu hình HAProxy: 24 | 25 | listen stats 26 | bind *:1234 27 | mode http 28 | stats enable 29 | stats refresh 5s 30 | stats show-node 31 | stats hide-version 32 | stats realm Haproxy\ Statistics 33 | stats uri / 34 | stats auth Username:Password 35 | 36 | frontend ft_rtpm 37 | bind *:1935 38 | mode tcp 39 | maxconn 1000 40 | default_backend bk_rtmp 41 | 42 | backend bk_rtmp 43 | mode tcp 44 | balance roundrobin 45 | stick store-request src 46 | stick-table type ip size 200k expire 20m 47 | stick on src 48 | # source 0.0.0.0 usesrc clientip 49 | server media01 192.168.100.201:1935 check maxconn 500 weight 10 50 | server media02 192.168.100.195:1935 check maxconn 500 weight 10 51 | 52 | 53 | 54 | // Phân tải HLS/DASH 55 | 56 | Cách 1: // Thêm vào file cấu hình HAProxy trên 57 | frontend ft_hls 58 | bind *:80 59 | mode http 60 | maxconn 1000 61 | default_backend bk_hls 62 | 63 | backend bk_hls 64 | mode http 65 | balance roundrobin 66 | server media01 192.168.100.196:80 check maxconn 500 weight 10 67 | server media02 192.168.100.195:80 check maxconn 500 weight 10 68 | 69 | Cách 2: 70 | 71 | - 1 Server (srv1) nhận stream từ người dùng (NGINX-RTMP) 72 | - Chia sẻ folder HLS/DASH của srv1 cho các Web server 73 | - Phân tải cho các Web server -------------------------------------------------------------------------------- /ghichep-nginx-RTMP/README.md: -------------------------------------------------------------------------------- 1 | ## Hướng dẫn cài đặt NGINX RTMP làm server Streaming Video HLS 2 | 3 | ### 1. Giới thiệu 4 | ### 2. Thành phần 5 | ### 3. Các bước cài đặt 6 | ### 4. Test 7 | 8 | ### 1. Giới thiệu 9 | ### 2. Thành phần 10 | ### 3. Các bước cài đặt 11 | ### 4. Test 12 | -------------------------------------------------------------------------------- /hls-vod/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:16.3-alpine3.12 2 | 3 | RUN apk update && apk add ffmpeg --no-cache && \ 4 | npm install -g npm@latest && \ 5 | npm install -g hls-vod-too && \ 6 | npm cache clean --force && \ 7 | rm -rf /tmp/* 8 | 9 | EXPOSE 4040 10 | 11 | CMD hls-vod-too --debug --root-path /opt/videos 12 | -------------------------------------------------------------------------------- /hls-vod/README.MD: -------------------------------------------------------------------------------- 1 | ## Dockerfile for hls-vod-too 2 | 3 | ### Build: 4 | 5 | ``` 6 | docker build -t hls-vod-too:v1 . 7 | ``` 8 | 9 | ### Run: 10 | 11 | ``` 12 | docker run -d --name hls-vod-too -p 4040:4040 -v /data/videos:/opt/videos hls-vod-too:v1 13 | ``` 14 | 15 | - `/data/videos`: Your video directory 16 | 17 | Ref: https://github.com/kmxz/hls-vod-too 18 | -------------------------------------------------------------------------------- /images/5lcn44htxb_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hoangdh/ghichep-StreamingVideo/820ad5499cf62b52de02376e9bd0d523c380033e/images/5lcn44htxb_image.png -------------------------------------------------------------------------------- /images/README.md: -------------------------------------------------------------------------------- 1 | # Photos 2 | -------------------------------------------------------------------------------- /nginx-rtmp/ffmpeg-nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | user root; 3 | worker_processes 4; 4 | 5 | #error_log logs/error.log; 6 | #error_log logs/error.log notice; 7 | #error_log logs/error.log info; 8 | 9 | #pid logs/nginx.pid; 10 | 11 | 12 | events { 13 | worker_connections 1024; 14 | } 15 | 16 | 17 | rtmp { 18 | server { 19 | listen 1935; 20 | chunk_size 4096; 21 | application vod { 22 | play /mnt/stream/vod; 23 | } 24 | ## rtmp://192.168.100.196/vod//1/1.flv # Thêm // Truoc subfolder 25 | application live { 26 | live on; 27 | record off; 28 | # allow publish 127.0.0.1; 29 | # allow publish 0.0.0.0; 30 | # deny publish all; 31 | # exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name; 32 | # sample HLS 33 | exec mkdir -p /tmp/hls/$name 34 | hls on; 35 | hls_path /tmp/hls; 36 | hls_sync 100ms; 37 | #exec ffmpeg -i rtmp://localhost/live/$name -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -s 1280x720 -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list /tmp/hls/$name/index.m3u8 -segment_list_flags +live-cache -segment_time 5 /tmp/hls/$name/$name-%04d.ts; 38 | 39 | # exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 /tmp/hls/$name/index.m3u8; 40 | 41 | # exec ffmpeg -i rtmp://localhost/live/$name -map 0 -codec:v libx264 -codec:a libfaac -f ssegment -segment_list /tmp/hls/$name/index.m3u8 -segment_list_flags +live -segment_time 5 /tmp/hls/$name/$name-%03d.ts; 42 | exec ffmpeg -re -i rtmp://localhost/live/$name -map 0 -flags +global_header -codec:v libx264 -codec:a copy -f ssegment -segment_list /tmp/hls/$name/index.m3u8 -segment_list_type hls -segment_list_size 5 -segment_list_flags +live -segment_time 2 /tmp/hls/$name/$name-%03d.ts; 43 | 44 | } 45 | application live360p { 46 | live on; 47 | record off; 48 | # allow publish 127.0.0.1; 49 | # allow publish 0.0.0.0; 50 | # deny publish all; 51 | } 52 | } 53 | } 54 | http { 55 | include mime.types; 56 | default_type application/octet-stream; 57 | 58 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 59 | # '$status $body_bytes_sent "$http_referer" ' 60 | # '"$http_user_agent" "$http_x_forwarded_for"'; 61 | 62 | #access_log logs/access.log main; 63 | 64 | sendfile on; 65 | #tcp_nopush on; 66 | 67 | #keepalive_timeout 0; 68 | keepalive_timeout 65; 69 | 70 | #gzip on; 71 | 72 | server { 73 | listen 80; 74 | server_name localhost; 75 | 76 | #charset koi8-r; 77 | 78 | #access_log logs/host.access.log main; 79 | 80 | location / { 81 | root /tmp/hls; 82 | index index.html index.htm; 83 | } 84 | 85 | #error_page 404 /404.html; 86 | 87 | # redirect server error pages to the static page /50x.html 88 | # 89 | error_page 500 502 503 504 /50x.html; 90 | location = /50x.html { 91 | root html; 92 | } 93 | 94 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 95 | # 96 | #location ~ \.php$ { 97 | # proxy_pass http://127.0.0.1; 98 | #} 99 | 100 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 101 | # 102 | #location ~ \.php$ { 103 | # root html; 104 | # fastcgi_pass 127.0.0.1:9000; 105 | # fastcgi_index index.php; 106 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 107 | # include fastcgi_params; 108 | #} 109 | 110 | # deny access to .htaccess files, if Apache's document root 111 | # concurs with nginx's one 112 | # 113 | #location ~ /\.ht { 114 | # deny all; 115 | #} 116 | } 117 | 118 | 119 | # another virtual host using mix of IP-, name-, and port-based configuration 120 | # 121 | #server { 122 | # listen 8000; 123 | # listen somename:8080; 124 | # server_name somename alias another.alias; 125 | 126 | # location / { 127 | # root html; 128 | # index index.html index.htm; 129 | # } 130 | #} 131 | 132 | 133 | # HTTPS server 134 | # 135 | #server { 136 | # listen 443 ssl; 137 | # server_name localhost; 138 | 139 | # ssl_certificate cert.pem; 140 | # ssl_certificate_key cert.key; 141 | 142 | # ssl_session_cache shared:SSL:1m; 143 | # ssl_session_timeout 5m; 144 | 145 | # ssl_ciphers HIGH:!aNULL:!MD5; 146 | # ssl_prefer_server_ciphers on; 147 | 148 | # location / { 149 | # root html; 150 | # index index.html index.htm; 151 | # } 152 | #} 153 | 154 | } 155 | -------------------------------------------------------------------------------- /nginx-rtmp/file-cau-hinh-nhap/1.nginx.conf: -------------------------------------------------------------------------------- 1 | user nginx; 2 | worker_processes auto; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | pid /var/run/nginx.pid; 9 | 10 | # RTMP configuration 11 | rtmp { 12 | 13 | server { 14 | listen 1935; # Listen on standard RTMP port 15 | chunk_size 4096; 16 | max_connections 2000; 17 | application live { 18 | live on; 19 | # Turn on HLS 20 | hls on; 21 | hls_path /tmp/hls/; 22 | hls_fragment 1; 23 | hls_playlist_length 5; 24 | hls_nested on; 25 | # disable consuming the stream from nginx as rtmp 26 | # deny play all; 27 | 28 | } 29 | # # Record 30 | record all; 31 | record_path /tmp/vod/; 32 | record_suffix -%d-%b-%y-%T.flv; 33 | } 34 | } 35 | 36 | http { 37 | sendfile off; 38 | tcp_nopush on; 39 | aio on; 40 | directio 512; 41 | default_type application/octet-stream; 42 | 43 | server { 44 | listen 80; 45 | access_log /var/log/nginx/access_log combined; 46 | location / { 47 | # Disable cache 48 | add_header 'Cache-Control' 'no-cache'; 49 | 50 | # CORS setup 51 | add_header 'Access-Control-Allow-Origin' '*' always; 52 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 53 | add_header 'Access-Control-Allow-Headers' 'Range'; 54 | 55 | # allow CORS preflight requests 56 | if ($request_method = 'OPTIONS') { 57 | add_header 'Access-Control-Allow-Origin' '*'; 58 | add_header 'Access-Control-Allow-Headers' 'Range'; 59 | add_header 'Access-Control-Max-Age' 1728000; 60 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 61 | add_header 'Content-Length' 0; 62 | return 204; 63 | } 64 | 65 | types { 66 | application/dash+xml mpd; 67 | application/vnd.apple.mpegurl m3u8; 68 | video/mp2t ts; 69 | } 70 | 71 | root /tmp/; 72 | } 73 | location /stat { 74 | rtmp_stat all; 75 | rtmp_stat_stylesheet stat.xsl; 76 | } 77 | location /stat.xsl { 78 | root /tmp/stat.xsl; 79 | } 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /nginx-rtmp/file-cau-hinh-nhap/2.lam-nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | #user nobody; 3 | worker_processes 1; 4 | 5 | #error_log logs/error.log; 6 | #error_log logs/error.log notice; 7 | #error_log logs/error.log info; 8 | 9 | #pid logs/nginx.pid; 10 | 11 | 12 | events { 13 | worker_connections 1024; 14 | } 15 | 16 | rtmp { 17 | server { 18 | listen 1935; 19 | chunk_size 4096; 20 | timeout 5s; 21 | application vod { 22 | play /mnt/stream/vod; 23 | } 24 | 25 | application live { 26 | live on; 27 | record off; 28 | # Turn on HLS 29 | hls on; 30 | hls_path /etc/nginx/html/live; 31 | hls_fragment 3; 32 | hls_playlist_length 5; 33 | hls_nested on; 34 | ## disable consuming the stream from nginx as rtmp 35 | # deny play all; 36 | # allow publish 127.0.0.1; 37 | # allow publish 0.0.0.0; 38 | # deny publish all; 39 | } 40 | } 41 | } 42 | 43 | http { 44 | include mime.types; 45 | default_type application/octet-stream; 46 | 47 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 48 | # '$status $body_bytes_sent "$http_referer" ' 49 | # '"$http_user_agent" "$http_x_forwarded_for"'; 50 | 51 | #access_log logs/access.log main; 52 | 53 | sendfile on; 54 | #tcp_nopush on; 55 | 56 | #keepalive_timeout 0; 57 | keepalive_timeout 65; 58 | 59 | gzip on; 60 | 61 | server { 62 | listen 80; 63 | server_name localhost; 64 | 65 | #charset koi8-r; 66 | 67 | #access_log logs/host.access.log main; 68 | 69 | location / { 70 | root html; 71 | index index.html index.htm; 72 | } 73 | 74 | #error_page 404 /404.html; 75 | 76 | # redirect server error pages to the static page /50x.html 77 | # 78 | error_page 500 502 503 504 /50x.html; 79 | location = /50x.html { 80 | root html; 81 | } 82 | 83 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 84 | # 85 | #location ~ \.php$ { 86 | # proxy_pass http://127.0.0.1; 87 | #} 88 | 89 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 90 | # 91 | #location ~ \.php$ { 92 | # root html; 93 | # fastcgi_pass 127.0.0.1:9000; 94 | # fastcgi_index index.php; 95 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 96 | # include fastcgi_params; 97 | #} 98 | 99 | # deny access to .htaccess files, if Apache's document root 100 | # concurs with nginx's one 101 | # 102 | #location ~ /\.ht { 103 | # deny all; 104 | #} 105 | } 106 | 107 | 108 | # another virtual host using mix of IP-, name-, and port-based configuration 109 | # 110 | #server { 111 | # listen 8000; 112 | # listen somename:8080; 113 | # server_name somename alias another.alias; 114 | 115 | # location / { 116 | # root html; 117 | # index index.html index.htm; 118 | # } 119 | #} 120 | 121 | 122 | # HTTPS server 123 | # 124 | #server { 125 | # listen 443 ssl; 126 | # server_name localhost; 127 | 128 | # ssl_certificate cert.pem; 129 | # ssl_certificate_key cert.key; 130 | 131 | # ssl_session_cache shared:SSL:1m; 132 | # ssl_session_timeout 5m; 133 | 134 | # ssl_ciphers HIGH:!aNULL:!MD5; 135 | # ssl_prefer_server_ciphers on; 136 | 137 | # location / { 138 | # root html; 139 | # index index.html index.htm; 140 | # } 141 | #} 142 | 143 | } 144 | -------------------------------------------------------------------------------- /nginx-rtmp/file-cau-hinh-nhap/ffmpeg-nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | user root; 3 | worker_processes 4; 4 | 5 | #error_log logs/error.log; 6 | #error_log logs/error.log notice; 7 | #error_log logs/error.log info; 8 | 9 | #pid logs/nginx.pid; 10 | 11 | 12 | events { 13 | worker_connections 1024; 14 | } 15 | 16 | 17 | rtmp { 18 | server { 19 | listen 1935; 20 | chunk_size 4096; 21 | 22 | application live { 23 | live on; 24 | record off; 25 | # allow publish 127.0.0.1; 26 | # allow publish 0.0.0.0; 27 | # deny publish all; 28 | # exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name; 29 | # sample HLS 30 | exec mkdir -p /tmp/hls/$name 31 | hls on; 32 | hls_path /tmp/hls; 33 | hls_sync 100ms; 34 | #exec ffmpeg -i rtmp://localhost/live/$name -r 25 -g 25 -c:a libfdk_aac -b:a 128k -c:v libx264 -preset veryfast -s 1280x720 -c:a libfdk_aac -vbsf h264_mp4toannexb -flags -global_header -f ssegment -segment_list /tmp/hls/$name/index.m3u8 -segment_list_flags +live-cache -segment_time 5 /tmp/hls/$name/$name-%04d.ts; 35 | 36 | # exec ffmpeg -i rtmp://localhost/live/$name -c:v libx264 -c:a aac -ac 1 -strict -2 -crf 18 -profile:v baseline -maxrate 400k -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 /tmp/hls/$name/index.m3u8; 37 | 38 | # exec ffmpeg -i rtmp://localhost/live/$name -map 0 -codec:v libx264 -codec:a libfaac -f ssegment -segment_list /tmp/hls/$name/index.m3u8 -segment_list_flags +live -segment_time 5 /tmp/hls/$name/$name-%03d.ts; 39 | exec ffmpeg -re -i rtmp://localhost/live/$name -map 0 -flags +global_header -codec:v libx264 -codec:a copy -f ssegment -segment_list /tmp/hls/$name/index.m3u8 -segment_list_type hls -segment_list_size 5 -segment_list_flags +live -segment_time 2 /tmp/hls/$name/$name-%03d.ts; 40 | 41 | } 42 | application live360p { 43 | live on; 44 | record off; 45 | # allow publish 127.0.0.1; 46 | # allow publish 0.0.0.0; 47 | # deny publish all; 48 | } 49 | } 50 | } 51 | http { 52 | include mime.types; 53 | default_type application/octet-stream; 54 | 55 | #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 56 | # '$status $body_bytes_sent "$http_referer" ' 57 | # '"$http_user_agent" "$http_x_forwarded_for"'; 58 | 59 | #access_log logs/access.log main; 60 | 61 | sendfile on; 62 | #tcp_nopush on; 63 | 64 | #keepalive_timeout 0; 65 | keepalive_timeout 65; 66 | 67 | #gzip on; 68 | 69 | server { 70 | listen 80; 71 | server_name localhost; 72 | 73 | #charset koi8-r; 74 | 75 | #access_log logs/host.access.log main; 76 | 77 | location / { 78 | root /tmp/hls; 79 | index index.html index.htm; 80 | } 81 | 82 | #error_page 404 /404.html; 83 | 84 | # redirect server error pages to the static page /50x.html 85 | # 86 | error_page 500 502 503 504 /50x.html; 87 | location = /50x.html { 88 | root html; 89 | } 90 | 91 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 92 | # 93 | #location ~ \.php$ { 94 | # proxy_pass http://127.0.0.1; 95 | #} 96 | 97 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 98 | # 99 | #location ~ \.php$ { 100 | # root html; 101 | # fastcgi_pass 127.0.0.1:9000; 102 | # fastcgi_index index.php; 103 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 104 | # include fastcgi_params; 105 | #} 106 | 107 | # deny access to .htaccess files, if Apache's document root 108 | # concurs with nginx's one 109 | # 110 | #location ~ /\.ht { 111 | # deny all; 112 | #} 113 | } 114 | 115 | 116 | # another virtual host using mix of IP-, name-, and port-based configuration 117 | # 118 | #server { 119 | # listen 8000; 120 | # listen somename:8080; 121 | # server_name somename alias another.alias; 122 | 123 | # location / { 124 | # root html; 125 | # index index.html index.htm; 126 | # } 127 | #} 128 | 129 | 130 | # HTTPS server 131 | # 132 | #server { 133 | # listen 443 ssl; 134 | # server_name localhost; 135 | 136 | # ssl_certificate cert.pem; 137 | # ssl_certificate_key cert.key; 138 | 139 | # ssl_session_cache shared:SSL:1m; 140 | # ssl_session_timeout 5m; 141 | 142 | # ssl_ciphers HIGH:!aNULL:!MD5; 143 | # ssl_prefer_server_ciphers on; 144 | 145 | # location / { 146 | # root html; 147 | # index index.html index.htm; 148 | # } 149 | #} 150 | 151 | } 152 | -------------------------------------------------------------------------------- /nginx-rtmp/file-cau-hinh-nhap/hls-native-nginx.conf: -------------------------------------------------------------------------------- 1 | user nginx; 2 | worker_processes auto; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | pid /var/run/nginx.pid; 9 | 10 | # RTMP configuration 11 | rtmp { 12 | server { 13 | listen 1935; # Listen on standard RTMP port 14 | chunk_size 4000; 15 | application live { 16 | live on; 17 | # Turn on HLS 18 | hls on; 19 | hls_path /mnt/hls/; 20 | hls_fragment 2; 21 | hls_playlist_length 3; 22 | ## disable consuming the stream from nginx as rtmp 23 | # deny play all; 24 | } 25 | } 26 | } 27 | 28 | http { 29 | sendfile off; 30 | tcp_nopush on; 31 | aio on; 32 | directio 512; 33 | default_type application/octet-stream; 34 | 35 | server { 36 | listen 80; 37 | access_log /var/log/nginx/access_log combined; 38 | location / { 39 | # Disable cache 40 | add_header 'Cache-Control' 'no-cache'; 41 | 42 | # CORS setup 43 | add_header 'Access-Control-Allow-Origin' '*' always; 44 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 45 | add_header 'Access-Control-Allow-Headers' 'Range'; 46 | 47 | # allow CORS preflight requests 48 | if ($request_method = 'OPTIONS') { 49 | add_header 'Access-Control-Allow-Origin' '*'; 50 | add_header 'Access-Control-Allow-Headers' 'Range'; 51 | add_header 'Access-Control-Max-Age' 1728000; 52 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 53 | add_header 'Content-Length' 0; 54 | return 204; 55 | } 56 | 57 | types { 58 | application/dash+xml mpd; 59 | application/vnd.apple.mpegurl m3u8; 60 | video/mp2t ts; 61 | } 62 | 63 | root /mnt/; 64 | index index.html index.htm index.php; 65 | } 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /nginx-rtmp/file-cau-hinh-nhap/livesoccer-nginx.conf: -------------------------------------------------------------------------------- 1 | #user nginx; 2 | worker_processes auto; 3 | 4 | #error_log logs/error.log; 5 | #error_log logs/error.log notice; 6 | #error_log logs/error.log info; 7 | 8 | pid /var/run/nginx.pid; 9 | 10 | events { 11 | worker_connections 1024; 12 | } 13 | 14 | rtmp { 15 | server { 16 | listen 1935; 17 | # listen 1936 proxy_protocol; 18 | chunk_size 4096; 19 | timeout 5s; 20 | notify_method get; 21 | 22 | application vod { 23 | play /etc/nginx/html/vod/; 24 | 25 | } 26 | application rtmp { 27 | live on; 28 | #on_publish http://localhost/on_publish; 29 | # exec ffmpeg -i rtmp://localhost/$app/$name -async 1 -vsync -1 30 | # -c:v libx264 -c:a libmp3lame -b:v 256k -b:a 32k -vf "scale=480:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/live/$name_low 31 | # -c:v libx264 -c:a libmp3lame -b:v 468k -b:a 96k -vf "scale=720:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/live/$name_mid 32 | # -c:v libx264 -c:a libmp3lame -b:v 824k -b:a 128k -vf "scale=960:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/live/$name_high 33 | # -c:v libx264 -c:a libmp3lame -b:v 1000k -b:a 128k -vf "scale=1280:trunc(ow/a/2)*2" -tune zerolatency -preset veryfast -crf 23 -f flv rtmp://localhost/live/$name_hd720; 34 | } 35 | 36 | application live { 37 | live on; 38 | record off; 39 | #on_publish http://localhost/on_publish; 40 | hls on; 41 | hls_path /etc/nginx/html/live; 42 | hls_nested on; 43 | hls_fragment 3s; 44 | hls_playlist_length 10s; 45 | # dash on; 46 | # dash_path /etc/nginx/html/vod; 47 | # dash_nested on; 48 | 49 | 50 | 51 | # hls on; # Enable HTTP Live Streaming 52 | # hls_nested on; 53 | # # Pointing this to an SSD is better as this involves lots of IO 54 | # hls_path /etc/nginx/html/live/; 55 | 56 | # # Instruct clients to adjust resolution according to bandwidth 57 | # hls_variant _low BANDWIDTH=288000; # Low bitrate, sub-SD resolution 58 | # hls_variant _mid BANDWIDTH=448000; # Medium bitrate, SD resolution 59 | # hls_variant _high BANDWIDTH=1152000; # High bitrate, higher-than-SD resolution 60 | # hls_variant _hd720 BANDWIDTH=1300000; # High bitrate, HD 720p resolution 61 | 62 | #exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 $dirname/$basename.mp4; 63 | #exec bash -c "echo $addr > /tmp/hoang.ip"; 64 | 65 | } 66 | # # Record stream 67 | # record all; 68 | # record_path /etc/nginx/html/vod/; 69 | # record_suffix -%d-%b-%y-%H%M%S.flv; 70 | 71 | } 72 | } 73 | 74 | http { 75 | include mime.types; 76 | default_type application/octet-stream; 77 | 78 | #log_format main ' - [] "" ' 79 | # ' "" ' 80 | # '"" ""'; 81 | 82 | #access_log logs/access.log main; 83 | 84 | sendfile on; 85 | #tcp_nopush on; 86 | 87 | #keepalive_timeout 0; 88 | keepalive_timeout 65; 89 | 90 | gzip on; 91 | server { 92 | listen 80; 93 | server_name cloud.livesoccer.cf; 94 | location / { 95 | root /opt/vod/; 96 | index index.html index.htm; 97 | } 98 | } 99 | server { 100 | listen 80; 101 | server_name srv1.livesoccer.cf; 102 | server_tokens off; 103 | #charset koi8-r; 104 | 105 | access_log /var/log/nginx/access_log combined; 106 | error_log /var/log/nginx/error_log; 107 | location / { 108 | root html; 109 | index index.html index.htm; 110 | # return 301 http://www.livesoccer.cf; 111 | } 112 | # # Player get M3U8 113 | location /live { 114 | # Disable cache 115 | add_header 'Cache-Control' 'no-cache'; 116 | 117 | # CORS setup 118 | add_header 'Access-Control-Allow-Origin' '*' always; 119 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 120 | add_header 'Access-Control-Allow-Headers' 'Range'; 121 | 122 | # allow CORS preflight requests 123 | if ($request_method = 'OPTIONS') { 124 | add_header 'Access-Control-Allow-Origin' '*'; 125 | add_header 'Access-Control-Allow-Headers' 'Range'; 126 | add_header 'Access-Control-Max-Age' 1728000; 127 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 128 | add_header 'Content-Length' 0; 129 | return 204; 130 | } 131 | 132 | types { 133 | application/dash+xml mpd; 134 | application/vnd.apple.mpegurl m3u8; 135 | video/mp2t ts; 136 | } 137 | root html; 138 | } 139 | # # Secure VOD 140 | # location /videos { 141 | # secure_link_secret livestream; 142 | # if ($secure_link = "") { return 403; } 143 | 144 | # rewrite ^ /vod/$secure_link; 145 | # } 146 | 147 | # location /vod { 148 | # internal; 149 | # root /etc/nginx/html; 150 | # } 151 | # Secure RTMP 152 | location /on_publish { 153 | 154 | # set connection secure link 155 | secure_link $arg_st,$arg_e; 156 | secure_link_md5 livesoccer$arg_app$arg_addr/$arg_name$arg_e; 157 | 158 | # bad hash 159 | if ($secure_link = "") { 160 | return 501; 161 | } 162 | 163 | # link expired 164 | if ($secure_link = "0") { 165 | return 502; 166 | } 167 | 168 | return 200; 169 | } 170 | #error_page 404 /404.html; 171 | 172 | # redirect server error pages to the static page /50x.html 173 | # 174 | error_page 500 502 503 504 /50x.html; 175 | location = /50x.html { 176 | root html; 177 | } 178 | location /nginx_status { 179 | stub_status on; 180 | access_log off; 181 | } 182 | 183 | location /stat { 184 | rtmp_stat all; 185 | rtmp_stat_stylesheet stat.xsl; 186 | } 187 | 188 | location /stat.xsl { 189 | allow all; 190 | root html; 191 | } 192 | } 193 | 194 | } -------------------------------------------------------------------------------- /nginx-rtmp/file-cau-hinh-nhap/record.sh: -------------------------------------------------------------------------------- 1 | _date=`date +"%Y-%m-%k%M"` 2 | mkdir -p /tmp/vod/$1/$_date 3 | echo $1 4 | ffmpeg -re -i rtmp://localhost/live/$1 -map 0 -codec:v libx264 -codec:a copy -flags -global_header -f ssegment -segment_list /tmp/vod/$1/$_date/index.m3u8 -segment_list_flags +live-cache -segment_time 2 /tmp/vod/$1/$_date/$1-%03d.ts; 5 | -------------------------------------------------------------------------------- /nginx-rtmp/nginx-auto-change-bitrate-and-record.conf: -------------------------------------------------------------------------------- 1 | user root; 2 | worker_processes auto; 3 | 4 | events { 5 | worker_connections 1024; 6 | } 7 | 8 | pid /var/run/nginx.pid; 9 | 10 | # RTMP configuration 11 | rtmp { 12 | 13 | server { 14 | listen 1935; # Listen on standard RTMP port 15 | chunk_size 4096; 16 | max_connections 2000; 17 | application src { 18 | live on; 19 | # default recorder 20 | record all; 21 | record_path /tmp/vod/; 22 | record_suffix -%d-%b-%y-%T.flv; 23 | record_notify on; 24 | #exec_record_done ffmpeg -y -i $path -acodec libmp3lame -ar 44100 -ac 1 -vcodec libx264 /tmp/vod/$basename.mp4; 25 | exec ffmpeg -i rtmp://localhost/src/$name 26 | -c:a libfdk_aac -b:a 32k -c:v libx264 -b:v 128K -s 256x144 -f flv rtmp://localhost/live/$name_144 27 | -c:a libfdk_aac -b:a 64k -c:v libx264 -b:v 256k -s 426x240 -f flv rtmp://localhost/live/$name_240 28 | -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 512K -s 640x360 -f flv rtmp://localhost/live/$name_360 29 | -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 1M -s 854x480 -f flv rtmp://localhost/live/$name_480 30 | -c:a libfdk_aac -b:a 320k -c:v libx264 -b:v 1.2M -s 1280x720 -f flv rtmp://localhost/live/$name_720; 31 | } 32 | application live { 33 | live on; 34 | # Turn on HLS 35 | hls on; 36 | hls_path /tmp/hls/; 37 | hls_fragment 1; 38 | hls_playlist_length 5; 39 | hls_nested on; 40 | hls_variant _144 BANDWIDTH=300000; #256x144 41 | hls_variant _240 BANDWIDTH=450000; #426x240 42 | hls_variant _320 BANDWIDTH=600000; #640x360 43 | hls_variant _480 BANDWIDTH=800000; #854x480 44 | hls_variant _720 BANDWIDTH=1000000;#1280x720 45 | 46 | # disable consuming the stream from nginx as rtmp 47 | # deny play all; 48 | 49 | } 50 | # # # Record 51 | # record all; 52 | # record_path /tmp/vod/; 53 | # record_suffix -%d-%b-%y-%T.flv; 54 | # record_notify on; 55 | 56 | } 57 | } 58 | 59 | http { 60 | sendfile off; 61 | tcp_nopush on; 62 | aio on; 63 | directio 512; 64 | default_type application/octet-stream; 65 | 66 | server { 67 | listen 80; 68 | access_log /var/log/nginx/access_log combined; 69 | location / { 70 | # Disable cache 71 | add_header 'Cache-Control' 'no-cache'; 72 | 73 | # CORS setup 74 | add_header 'Access-Control-Allow-Origin' '*' always; 75 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 76 | add_header 'Access-Control-Allow-Headers' 'Range'; 77 | 78 | # allow CORS preflight requests 79 | if ($request_method = 'OPTIONS') { 80 | add_header 'Access-Control-Allow-Origin' '*'; 81 | add_header 'Access-Control-Allow-Headers' 'Range'; 82 | add_header 'Access-Control-Max-Age' 1728000; 83 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 84 | add_header 'Content-Length' 0; 85 | return 204; 86 | } 87 | 88 | types { 89 | application/dash+xml mpd; 90 | application/vnd.apple.mpegurl m3u8; 91 | video/mp2t ts; 92 | } 93 | 94 | root /tmp/; 95 | } 96 | location /stat { 97 | rtmp_stat all; 98 | rtmp_stat_stylesheet stat.xsl; 99 | } 100 | location /stat.xsl { 101 | root /tmp/stat.xsl; 102 | } 103 | } 104 | } 105 | 106 | -------------------------------------------------------------------------------- /nginx-rtmp/nginx-centos-6.sh: -------------------------------------------------------------------------------- 1 | #RTMP using nginx 2 | 3 | yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel git wget 4 | mkdir -p ~/source 5 | cd ~/source 6 | wget http://nginx.org/download/nginx-1.8.0.tar.gz; 7 | tar -xzf nginx-1.8.0.tar.gz 8 | git clone https://github.com/arut/nginx-rtmp-module.git 9 | cd nginx-1.8.0 10 | ./configure --user=nginx --group=nginx --add-module=../nginx-rtmp-module/ --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 11 | make 12 | make install 13 | useradd -r nginx 14 | #wget -O /etc/init.d/nginx http://pastebin.com/raw.php?i=XhNPr6Y7 15 | cat > /etc/init.d/nginx << H2 16 | #!/bin/sh 17 | # 18 | # nginx Startup script for nginx 19 | # 20 | # chkconfig: - 85 15 21 | # processname: nginx 22 | # config: /etc/nginx/nginx.conf 23 | # config: /etc/sysconfig/nginx 24 | # pidfile: /var/run/nginx.pid 25 | # description: nginx is an HTTP and reverse proxy server 26 | # 27 | ### BEGIN INIT INFO 28 | # Provides: nginx 29 | # Provides: nginx 30 | # Required-Start: \$local_fs \$remote_fs \$network 31 | # Required-Stop: \$local_fs \$remote_fs \$network 32 | # Default-Start: 2 3 4 5 33 | # Default-Stop: 0 1 6 34 | # Short-Description: start and stop nginx 35 | ### END INIT INFO 36 | 37 | # Source function library. 38 | . /etc/rc.d/init.d/functions 39 | 40 | if [ -f /etc/sysconfig/nginx ]; then 41 | . /etc/sysconfig/nginx 42 | fi 43 | 44 | prog=nginx 45 | nginx=\${NGINX-/usr/sbin/nginx} 46 | conffile=\${CONFFILE-/etc/nginx/nginx.conf} 47 | lockfile=\${LOCKFILE-/var/lock/subsys/nginx} 48 | pidfile=\${PIDFILE-/var/run/nginx.pid} 49 | SLEEPMSEC=100000 50 | RETVAL=0 51 | 52 | start() { 53 | echo -n \$"Starting \$prog: " 54 | 55 | daemon --pidfile=\${pidfile} \${nginx} -c \${conffile} 56 | RETVAL=\$? 57 | echo 58 | [ \$RETVAL = 0 ] && touch \${lockfile} 59 | return \$RETVAL 60 | } 61 | 62 | stop() { 63 | echo -n \$"Stopping \$prog: " 64 | killproc -p \${pidfile} \${prog} 65 | RETVAL=\$? 66 | echo 67 | [ \$RETVAL = 0 ] && rm -f \${lockfile} \${pidfile} 68 | } 69 | 70 | reload() { 71 | echo -n \$"Reloading \$prog: " 72 | killproc -p \${pidfile} \${prog} -HUP 73 | RETVAL=\$? 74 | echo 75 | } 76 | 77 | upgrade() { 78 | oldbinpidfile=\${pidfile}.oldbin 79 | 80 | configtest -q || return 6 81 | echo -n \$"Staring new master \$prog: " 82 | killproc -p \${pidfile} \${prog} -USR2 83 | RETVAL=\$? 84 | echo 85 | /bin/usleep \$SLEEPMSEC 86 | if [ -f \${oldbinpidfile} -a -f \${pidfile} ]; then 87 | echo -n \$"Graceful shutdown of old \$prog: " 88 | killproc -p \${oldbinpidfile} \${prog} -QUIT 89 | RETVAL=\$? 90 | echo 91 | else 92 | echo \$"Upgrade failed!" 93 | return 1 94 | fi 95 | } 96 | 97 | configtest() { 98 | if [ "\$#" -ne 0 ] ; then 99 | case "\$1" in 100 | -q) 101 | FLAG=\$1 102 | ;; 103 | *) 104 | ;; 105 | esac 106 | shift 107 | fi 108 | \${nginx} -t -c \${conffile} \$FLAG 109 | RETVAL=\$? 110 | return \$RETVAL 111 | } 112 | 113 | rh_status() { 114 | status -p \${pidfile} \${nginx} 115 | } 116 | 117 | # See how we were called. 118 | case "\$1" in 119 | start) 120 | rh_status >/dev/null 2>&1 && exit 0 121 | start 122 | ;; 123 | stop) 124 | stop 125 | ;; 126 | status) 127 | rh_status 128 | RETVAL=\$? 129 | ;; 130 | restart) 131 | configtest -q || exit \$RETVAL 132 | stop 133 | start 134 | ;; 135 | upgrade) 136 | upgrade 137 | ;; 138 | condrestart|try-restart) 139 | if rh_status >/dev/null 2>&1; then 140 | stop 141 | start 142 | fi 143 | ;; 144 | force-reload|reload) 145 | reload 146 | ;; 147 | configtest) 148 | configtest 149 | ;; 150 | *) 151 | echo \$"Usage: \$prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}" 152 | RETVAL=2 153 | esac 154 | 155 | exit \$RETVAL 156 | H2 157 | 158 | chmod a+x /etc/init.d/nginx 159 | chkconfig --add nginx 160 | mkdir -p /var/cache/nginx/client_temp 161 | chown nginx. /var/cache/nginx/client_temp 162 | ## Open port 80: nginx and 1935 for rtmp 163 | # iptables -I INPUT -p tcp --dport 80 -j ACCEPT 164 | # iptables -I INPUT -p tcp --dport 1935 -j ACCEPT 165 | service iptables save 166 | service iptables reload 167 | # Add to configure file nginx.conf 168 | 169 | # rtmp { 170 | # server { 171 | # listen 1935; 172 | # chunk_size 4096; 173 | 174 | # application live { 175 | # live on; 176 | # record off; 177 | # allow publish 127.0.0.1; 178 | # allow publish 0.0.0.0; 179 | # deny publish all; 180 | # exec ffmpeg -i rtmp://localhost/live/$name -threads 1 -c:v libx264 -profile:v baseline -b:v 350K -s 640x360 -f flv -c:a aac -ac 1 -strict -2 -b:a 56k rtmp://localhost/live360p/$name; 181 | # } 182 | # application live360p { 183 | # live on; 184 | # record off; 185 | # allow publish 127.0.0.1; 186 | # allow publish 0.0.0.0; 187 | # deny publish all; 188 | # } 189 | # } 190 | # } -------------------------------------------------------------------------------- /nginx-rtmp/nginx-centos-7.sh: -------------------------------------------------------------------------------- 1 | yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel git wget 2 | mkdir /opt/source/ 3 | cd /opt/source/ 4 | wget http://nginx.org/download/nginx-1.10.2.tar.gz 5 | tar -xzf nginx-1.10.2.tar.gz 6 | git clone https://github.com/arut/nginx-rtmp-module.git 7 | cd /opt/source/nginx-1.10.2 8 | ./configure --user=nginx --group=nginx --add-module=../nginx-rtmp-module/ --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 9 | 10 | make 11 | make install 12 | useradd -r nginx 13 | mkdir -p /var/cache/nginx/client_temp/ 14 | chown nginx. /var/cache/nginx/client_temp/ 15 | 16 | cat > /lib/systemd/system/nginx.service << H2 17 | [Unit] 18 | Description=The NGINX HTTP and reverse proxy server 19 | After=syslog.target network.target remote-fs.target nss-lookup.target 20 | 21 | [Service] 22 | Type=forking 23 | PIDFile=/run/nginx.pid 24 | ExecStartPre=/usr/sbin/nginx -t 25 | ExecStart=/usr/sbin/nginx 26 | ExecReload=/bin/kill -s HUP \$MAINPID 27 | ExecStop=/bin/kill -s QUIT \$MAINPID 28 | PrivateTmp=true 29 | 30 | [Install] 31 | WantedBy=multi-user.target 32 | H2 33 | 34 | chmod a+rx /lib/systemd/system/nginx.service 35 | systemctl enable nginx 36 | mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bk 37 | mkdir -p /mnt/stream/hls/ 38 | mkdir -p /mnt/stream/vod/ 39 | 40 | cat > /etc/nginx/nginx.conf << H2 41 | user nginx; 42 | worker_processes auto; 43 | 44 | events { 45 | worker_connections 1024; 46 | } 47 | 48 | # pid /var/run/nginx.pid; 49 | 50 | # RTMP configuration 51 | rtmp { 52 | 53 | server { 54 | listen 1935; # Listen on standard RTMP port 55 | chunk_size 4096; 56 | max_connections 2000; 57 | application live { 58 | live on; 59 | # Turn on HLS 60 | hls on; 61 | hls_path /mnt/stream/hls/; 62 | hls_fragment 2s; 63 | hls_playlist_length 60; 64 | hls_nested on; 65 | # disable consuming the stream from nginx as rtmp 66 | # deny play all; 67 | 68 | } 69 | # # Record 70 | # record all; 71 | # record_path /mnt/stream/vod/; 72 | # record_suffix -%d-%b-%y-%T.flv; 73 | 74 | 75 | } 76 | } 77 | 78 | http { 79 | sendfile off; 80 | tcp_nopush on; 81 | aio on; 82 | directio 512; 83 | default_type application/octet-stream; 84 | 85 | server { 86 | listen 80; 87 | access_log /var/log/nginx/access_log combined; 88 | location / { 89 | # Disable cache 90 | add_header 'Cache-Control' 'no-cache'; 91 | 92 | # CORS setup 93 | add_header 'Access-Control-Allow-Origin' '*' always; 94 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 95 | add_header 'Access-Control-Allow-Headers' 'Range'; 96 | 97 | # allow CORS preflight requests 98 | if (\$request_method = 'OPTIONS') { 99 | add_header 'Access-Control-Allow-Origin' '*'; 100 | add_header 'Access-Control-Allow-Headers' 'Range'; 101 | add_header 'Access-Control-Max-Age' 1728000; 102 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 103 | add_header 'Content-Length' 0; 104 | return 204; 105 | } 106 | 107 | types { 108 | application/dash+xml mpd; 109 | application/vnd.apple.mpegurl m3u8; 110 | video/mp2t ts; 111 | } 112 | 113 | root /mnt/stream/; 114 | } 115 | location /stat { 116 | rtmp_stat all; 117 | rtmp_stat_stylesheet stat.xsl; 118 | } 119 | location /stat.xsl { 120 | root /mnt/stream/stat.xsl; 121 | } 122 | } 123 | } 124 | H2 125 | 126 | ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'` 127 | systemctl start nginx 128 | 129 | echo -e "Thuc hien nhu sau: 130 | - Push RTMP: rtmp://$ip/live/ 131 | - Play HLS: http://$ip/hls//index.m3u8" -------------------------------------------------------------------------------- /nginx-rtmp/nginx-ubuntu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update -y 4 | apt-get upgrade -y 5 | apt-get install build-essential libpcre3 libpcre3-dev libssl-dev git wget dpkg-dev zlib1g-dev unzip -y 6 | 7 | git clone https://github.com/arut/nginx-rtmp-module.git 8 | wget http://nginx.org/download/nginx-1.10.1.tar.gz 9 | tar -xf nginx-1.10.1.tar.gz 10 | cd nginx-1.10.1 11 | 12 | ./configure --user=nginx --group=nginx --add-module=../nginx-rtmp-module/ --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 13 | 14 | make 15 | make install 16 | useradd -r nginx 17 | mkdir -p /var/cache/nginx/client_temp/ 18 | chown nginx. /var/cache/nginx/client_temp/ 19 | -------------------------------------------------------------------------------- /nginx-rtmp/nginx.conf: -------------------------------------------------------------------------------- 1 | user nginx; 2 | worker_processes auto; 3 | 4 | load_module modules/ngx_rtmp_module.so; 5 | 6 | events { 7 | worker_connections 1024; 8 | } 9 | 10 | pid /var/run/nginx.pid; 11 | 12 | # RTMP configuration 13 | rtmp { 14 | server { 15 | listen 1935; # Listen on standard RTMP port 16 | chunk_size 4096; 17 | max_connections 2000; 18 | access_log /var/log/nginx/access_rtmp.log combined; 19 | application live { 20 | live on; 21 | # Turn on HLS 22 | hls on; 23 | hls_path /var/www/hls/; 24 | hls_fragment 3; 25 | hls_playlist_length 9; 26 | hls_nested on; 27 | # disable consuming the stream from nginx as rtmp 28 | # deny play all; 29 | } 30 | } 31 | } 32 | http { 33 | sendfile off; 34 | tcp_nopush on; 35 | aio on; 36 | directio 512; 37 | server_tokens off; 38 | default_type application/octet-stream; 39 | server { 40 | listen 80; 41 | access_log /var/log/nginx/access_log combined; 42 | location / { 43 | # Disable cache 44 | add_header 'Cache-Control' 'no-cache'; 45 | # CORS setup 46 | add_header 'Access-Control-Allow-Origin' '*' always; 47 | add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; 48 | add_header 'Access-Control-Allow-Headers' 'Range'; 49 | # allow CORS preflight requests 50 | if ($request_method = 'OPTIONS') { 51 | add_header 'Access-Control-Allow-Origin' '*'; 52 | add_header 'Access-Control-Allow-Headers' 'Range'; 53 | add_header 'Access-Control-Max-Age' 1728000; 54 | add_header 'Content-Type' 'text/plain charset=UTF-8'; 55 | add_header 'Content-Length' 0; 56 | return 204; 57 | } 58 | types { 59 | application/dash+xml mpd; 60 | application/vnd.apple.mpegurl m3u8; 61 | video/mp2t ts; 62 | } 63 | root /var/www/; 64 | } 65 | location /stat { 66 | rtmp_stat all; 67 | rtmp_stat_stylesheet stat.xsl; 68 | } 69 | location /stat.xsl { 70 | root /var/www/hls; 71 | } 72 | 73 | location /crossdomain.xml { 74 | default_type text/xml; 75 | return 200 ' 76 | 77 | 78 | 79 | 80 | 81 | '; 82 | expires 24h; 83 | } 84 | } 85 | } 86 | --------------------------------------------------------------------------------