FFMPEG STB Android

https://github.com/WritingMinds/ffmpeg-android/releases

copy ffmpeg binary to stb

start stream ffmpeg -i input -c:a aac -strict -2 -c:v h264 -f flv rtmp://xxxx

Streaming youtube-dl to FFMPEG

youtube-dl -o - "https://www.youtube.com/watch?v=xxx" | ffmpeg -i - -c:a aac -strict -2 -vf "transpose=1","scale=iw:ih","drawtext=fontcolor=white:fontsize=40:fontfile='/path/font.ttf':textfile='/path/msg.txt':reload=1:y=h-line_h-52:x=w-(mod(4*n\,w+tw)-tw/40)" -c:v h264 -f flv rtmp://xxx/live/xxxx

Ffmpeg streaming

In all the examples below we’ll assume you do not know the codecs and will want to replace them with H264/AAC. (source : https://news.mistserver.org/news/71/An+introduction+to+encoding+and+pushing+with+ffmpeg)

  • RTMP stream Input to FLV file, reencode

ffmpeg -i rtmp://IP:PORT/live/STREAMNAME -c:a aac -strict -2 -c:v h264 OUTPUT.flv

  • MP4 file Input to RTMP stream, reencode

ffmpeg -re -i INPUT.mp4 -c:a aac -strict -2 -c:v h264 -f flv rtmp://IP:PORT/live/STREAMNAME

  • HLS stream input to RTMP stream, reencode

ffmpeg -i http://IP:PORT/hls/STREAMNAME/index.m3u8 -c:a aac -strict -2 -c:v h264 -f flv rtmp://IP:PORT/live/STREAMNAME

  • MP4 file input to RTSP stream, reencode

ffmpeg -re -i INPUT.mp4 -c:a aac -strict -2 -c:v h264 -f rtsp -rtsp_transport tcp rtsp://IP:PORT/STREAMNAME

  • HLS stream input to RTSP stream, reencode

ffmpeg -i http://IP:PORT/hls/STREAMNAME/index.m3u8 -c:a aac
-strict -2 -c:v h264 -f rtsp -rtsp_transport tcp
rtsp://IP:PORT/STREAMNAME

  • RTSP stream input over TCP to RTMP stream, copy

*Using ffmpeg to ingest over TCP instead of UDP makes sure you don’t have the packet loss problem that UDP has and gives a better and more stable picture for your stream. -rtsp_transport tcp -i CameraURL -c copy -f flv rtmp://IP:PORT/live/STREAMNAME

 

run.sh

@echo on

:START
ffmpeg -i input_ch -c:a aac -strict -2 -vf "transpose=1","scale=iw/2:ih/2","drawtext=fontcolor=white:fontsize=40:fontfile='/font.ttf':textfile='/msg.txt':reload=1:y=h-line_h-52:x=w-(mod(4*n\,w+tw)-tw/40)" -c:v h264 -f flv rtmp://...
if errorlevel 3 goto START

pause
:fin

Change STB Logo

Step 1
Create image with dimention 720P and 1080P. Then copy to /data/720P.jpg and /data/1080P.jpg

Step 2
Copy and edit config
#sed -e s:logo_720P.jpg:/data/720P.jpg:g -e s:logo_1080P.jpg:/data/1080P.jpg:g /system/etc/material.conf > /tmp/material.conf

Step 3
Create logo.img
#mklogo /tmp/material.conf /tmp/logo.bin
#mkimg /tmp/logo.bin /tmp/logo.img jpeg V713002 1 1 1

Step 4
flash logo.img to logo partition
#dd if=/tmp/logo.img of=/dev/block/logo

Done

Ubuntu 18.04 compile Nginx + RTMP + VOD + HLS

This tutorial will explain how to setup your own streaming server on ubuntu 18.04 with RTMP, HLS and VOD add on module.
Firtsly, we prepare nginx source, download from http://nginx.org/en/download.html

#wget http://nginx.org/download/nginx-1.14.1.tar.gz
#tar -zxvf nginx-1.14.1.tar.gz

Clone source nginx-rtmp-module and nginx-vod-module

#git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git
#git clone https://github.com/kaltura/nginx-vod-module.git

Install nginx dependencies

#sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev

Download zlib from http://zlib.net/

#wget http://zlib.net/zlib-1.2.11.tar.gz
#tar -zxxvf zlib-1.2.11.tar.gz

compile nginx

#cd nginx
#./configure --add-module=../nginx-rtmp-module/ --add-module=../nginx-vod-module/ --with-file-aio --with-threads --with-zlib=../zlib-1.2.11
#make
#make install

move to nginx installation folder and edit nginx.conf

#cd /usr/local/nginx/
#nano conf/nginx.conf

add rtmp server on nginx configuration

rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        allow play all;
        application live {
            allow play all;
            live on;
            record all;
            record_path /film;
        }
        #allows you to play your recordings of your live streams using a URL like "rtmp://my-ip:1935/vod/filename.flv"
        application vod {
            play /film;
        }
        application hls {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # record stream to folder /film/
            record all;
            record_path /film;
            # disable consuming the stream from nginx as rtmp
			deny play all;
        }
    }
}

Create folder /mnt/hls and /film
Give nginx permission to access that folder

add hls streaming config on htto section at nginx configuration

server {
    listen 8080;

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

        # CORS setup
        add_header 'Access-Control-Allow-Origin' '*' always;
        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;
        }

        root /mnt/;
    }
}
}

add vod server on http section at nginx configuration

    server {
        listen 8384;

        # vod caches
        vod_metadata_cache metadata_cache 256m;
        vod_response_cache response_cache 128m;

        # vod settings
        vod_mode local;
        vod_segment_duration 2000; # 2s
        vod_align_segments_to_key_frames on;

        #file handle caching / aio
        open_file_cache max=1000 inactive=5m;
        open_file_cache_valid 2m;
        open_file_cache_min_uses 1;
        open_file_cache_errors on;
        aio on;

        location /filmku/ {
            alias /film/;
            vod hls;
            add_header Access-Control-Allow-Headers '*';
            add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
            add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
            add_header Access-Control-Allow-Origin '*';
            expires 100d;
        }
    }

check configuration and run nginx

# /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx

If you stream video using OBS to rtmp://your_ip/hls/streamname
so you can access your streaming via hls streaming http://your_ip:8080/hls/streamname.m3u8
or with rtmp vod rtmp://yourip/vod/streamname.flv
of with hls vod http://your_ip:8384/filmku/streamname.flv/index.m3u8

RTMP server + HLS Ubuntu 18.04.1 LTS

Install Nginx

sudo apt install libnginx-mod-rtmp

Install rtmp-module


sudo apt install libnginx-mod-rtmp
service nginx restart

Setting nginx conf
nano /etc/nginx/nginx.conf


rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        allow play all;
        application live {
            allow play all;
            live on;
        }
        application hls {
            live on;
            # Turn on HLS
            hls on;
            hls_path /mnt/hls/;
            hls_fragment 3;
            hls_playlist_length 60;
            # disable consuming the stream from nginx as rtmp
            deny play all;
        }
    }
}

Create new nginx config file
nano /etc/nginx/conf.d/hls.conf


server {
    listen 8080;

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

        # CORS setup
        add_header 'Access-Control-Allow-Origin' '*' always;
        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;
        }

        root /mnt;
        add_header Cache-Control no-cache;
    }
}

Restart Nginx…Done

Basic uri syntax: rtmp://your_ip/hls/stream_name
video will be available as http://your_ip:8080/hls/stream_name.m3u8

Raspberry – Compile Nginx with RTMP Module

Install utils and libraries needed for compilation and some extra Nginx modules

sudo apt-get install -y curl build-essential make gcc libpcre3 libpcre3-dev libpcre++-dev zlib1g-dev libbz2-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libperl-dev libssl-dev libcurl4-openssl-dev

Download NGINX Source and RTMP Module


cd /tmp
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
wget http://nginx.org/download/nginx-1.7.9.tar.gz
tar -zxvf nginx-1.7.9.tar.gz
unzip master.zip

cd nginx-1.7.9
./configure --add-module=/tmp/nginx-rtmp-module-master
make
sudo make install

Mikrotik script get Public IP

/tool fetch url="http://ifconfig.co/ip" mode=http dst-path=mypublicip.txt
:local ipku [file get mypublicip.txt contents]
:global ipnow "";
:global ipold;
:for i from=0 to=([:len $ipku]-1) do={ :local tmp [:pick $ipku $i];
:if ($tmp !="\n") do={ :set ipnow "$ipnow$tmp" }
}

:if ($ipnow != $ipold) do={ 
:log info "ip diupdate"; 
:set ipold "$ipnow";
/tool fetch url="http://xxx.xxx/update.php\3Fip=$ipnow" keep-result=no;
} else={ :log info "Tidak diupdate"}

:log info $ipnow