👨‍🏫 Tutorial CREATE A Streaming SERVER (For advanced User)

JohnDoePH

Journeyman
CREATE A Streaming SERVER (For advanced User)

For Main Streaming Site: https://phcorner.org/threads/create-a-streaming-site-for-advanced-user.1033781/#post-17655661

Introduction:

Gusto mo bang gumawa ng strêâmïng server at e host ang sarili mong files? Well, subokan mo to.
and advantage nito ay controlado mo ang lahat simula sa website mo hanggang sa kinikita mo.
at sempre goodbye sa mga sagabal na ads mula sa mga ibang website tulad ng mixdrop at iba pa tapos ang kunti pa ang kinikita mo sa kanila.
ganun din ang pag iwas sa pag hohost ng files doon na may expiration sa loob ng 60 days kung ito ay hindi active.

Requirements:

1.SERVER para sa iyong Files. (Intel Xeon E3-1220 v3 3.50GHz Turbo, 4 Cores, 4 Threads 8GB DDR3 1x 2TB SATA Unmetered 1Gbps Shared) with fresh Ubuntu 16/18
2.DOMAIN para sa iyong Files.

Step 1: Pag setup ng SERVER para sa iyong Streaming SERVER.

Prerequisites: (Domain name)

Open your terminal emulator like Putty kung naka windows ka at e login ang root with password gamit ang IP Address ng Server mo sa Streaming Server.

Code:
sudo apt update 
sudo apt upgrade
reboot

(Restart your terminal and login ulit)

(Some server have an apache installed, it is better to check this.)

Code:
sudo apt install nginx
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Sa tutorial na ito ay HLS format ang ating gagamitin.

Code:
mkdir /var/www/html/hls && sudo chown -R www-data:www-data /var/www/html/hls/ && sudo chmod -R 755 /var/www/html/hls/

Code:
sudo nano /etc/nginx/sites-available/DOMAIN_NAME

Paste niyo lang ito at palitan ang domain.

Code:
server {
    listen 80;
    listen [::]:80;
    root /var/www/html;
    index  index.php index.html index.htm;
    server_name  DOMAIN_NAME;
    client_max_body_size 100M;
    autoindex off;
    location / {
    }

    location /hls {
        # Disable cache
        add_header Cache-Control no-cache;

        # CORS setup
        add_header 'Access-Control-Allow-Origin' 'https://DOMAIN_NAME_NG_IYONG_MAIN_STREAMING_SITE';
        add_header 'Access-Control-Expose-Headers' 'Content-Length';

        # allow CORS preflight requests
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }

        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
    }

}

After that, just save it at e restart ang NGINX.

Code:
nginx -t
sudo systemctl restart nginx.service

Activate natin ang Server Block ng NGINX then restart ulit ang NGINX.

Code:
sudo ln -s /etc/nginx/sites-available/DOMAIN_NAME /etc/nginx/sites-enabled/
sudo systemctl restart nginx.service

Now, Sa tutorial na ito ay embis Cloudflare ay Let's Encrypt ang gagamitin para sa HTTPS.
Kailangan kasi naka HTTPS ang server natin para gumana ang Video FIles natin kasi HLS Format ang gagamitin natin.

Code:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
sudo nginx -t
sudo systemctl reload nginx
sudo certbot --nginx -d DOMAIN_NAME.COM
sudo certbot renew --dry-run
sudo crontab -e
0 1 * * * /usr/bin/certbot renew >> /var/log/letsencrypt/renew.log

Same as usual, restart ulit ang NGINX.

Code:
sudo systemctl restart nginx.service

Now check mo ang server kung naka secure na, open browser then type mo ang domain mo.

The last one is mag Install ng FFMPEG to transcode the video files tulad ng MP4 to HLS, MKV to HLS, at iba.

Code:
sudo apt install ffmpeg

Banggg,,, Now ang iyong Server ay live na...

Q: Paanu malagyan ng mga files ang server ko sa madaling paraan?
A: Gagamitin natin ang (Remote Upload).

TIPS and TRICK:

Remote Upload mula sa Google Drive papunta sa iyong Server.

Gumawa ng folder.
Code:
mkdir /var/www/html/hls/VIDEO_FILE_FOLDER

Copyahin ang file mula sa google drive.
Code:
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=GOOGLE_FILE_ID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=GOOGLE_FILE_ID" -O /var/www/html/hls/VIDEO_FILE_FOLDER/MOVIE_TILE.mp4 && rm -rf /tmp/cookies.txt

Convert ang file mula sa MP4 format to HLS format.
Code:
ffmpeg -i /var/www/html/hls/VIDEO_FILE_FOLDER/MOVIE_TILE.mp4 -profile:v baseline -preset ultrafast -strict -2 -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls /var/www/html/hls/VIDEO_FILE_FOLDER/playlist.m3u8

Hintayin lang hanggang matapos ang pag convert then try to mo e paste ang URL ng file mo sa Main Streaming Site mo.
Example: https://DOMAIN_NAME.COM/hls/VIDEO_FILE_FOLDER/playlist.m3u8

NOTE: wag e try sa ibang HLS Streaming Player Tester Site kasi mag eerror gawa ng naka assign na ang iyong main streaming site sa crossdomain ng HLS files mo.

MORE TIPS:

Remote Upload mula sa Youtube papunta sa iyong Server.

Mag Install ng youtube-dl download manager for video and audio from YouTube.
Code:
sudo apt-get install youtube-dl

Gumawa ng folder ulit.
Code:
mkdir /var/www/html/hls/VIDEO_FILE_FOLDER_FROM_YOUTUBE

Remote Upload youtube to Your Server.
Code:
youtube-dl -o "/var/www/html/hls/VIDEO_FILE_FOLDER_FROM_YOUTUBE" https://www.youtube.com/watch?v=YOUTUBE_ID

Convert ang file mula sa MP4 format to HLS format.
Code:
ffmpeg -i /var/www/html/hls/VIDEO_FILE_FOLDER_FROM_YOUTUBE/MOVIE_TILE.mp4 -profile:v baseline -preset ultrafast -strict -2 -level 3.0 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls /var/www/html/hls/VIDEO_FILE_FOLDER_FROM_YOUTUBE/playlist.m3u8


Thats it... mag tanung lang po kayo kung sino ang may gusto. baka alam ko ang itatanung at masagot ko..
 

About this Thread

  • 4
    Replies
  • 1K
    Views
  • 5
    Participants
Last reply from:
Well1AmNichtDiePerson

Trending Topics

Online now

Members online
1,019
Guests online
1,568
Total visitors
2,587

Forum statistics

Threads
2,273,384
Posts
28,949,110
Members
1,235,723
Latest member
xberzerker
Back
Top