Use nginx to build and test the rtmp server on the android phone

Source: Internet
Author: User

1. Compile nginx that can be used in android and add the option -- add-module =/path/nginx-rtmp-module, prepare ffmpeg files and related library files that can be used by shell on android and m3u8 segmenter files.
2. Put the compiled nginx files in the data/android. nginx directory of the mobile phone to this directory.
3. Compile the configuration file
--------------------------------- Nginx. conf start here ----------------------------------------------------
User root;
Worker_processes 2;

Error_log/data/android. nginx/logs/error. log;
Error_log/data/android. nginx/logs/error. log notice;
Error_log/data/android. nginx/logs/error. log info;

Pid logs/nginx. pid;


Events {
Worker_connections 1024;
}

Rtmp {
Server {
Listen 1935;

Chunk_size 4096;

Application myapp {
Live on;
}
}
}


Http {
Include mime. types;
Default_type application/octet-stream;

# Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
# '$ Status $ body_bytes_sent "$ http_referer "'
# '"$ Http_user_agent" "$ http_x_forwarded_for "';

# Access_log logs/access. log main;

Sendfile on;
# Tcp_nopush on;

# Keepalive_timeout 0;
Keepalive_timeout 65;

# Gzip on;

Server {
Listen 801;

Location/stat {
Rtmp_stat all;
Rtmp_stat_stylesheet stat. xsl;
}

Location/stat. xsl {
Root/data/android. rtmp;
}

Location /{
Root/data/android. rtmp/test/rtmp-publisher;
}
}

Server {
Listen 80 default;
Server_name localhost;
Autoindex on;
Autoindex_exact_size on;
Root/data/android. wwwroot;
Index index.html index.htm index. php;

# Charset koi8-r;

# Access_log logs/host. access. log main;

# Error_page 404/404 .html;

# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}

# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ \. Php $ {
# Proxy_pass http: // 127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ * \. Php $ {
Fastcgi_index index. php;
Client_max_body_size 64 m;
Fastcgi_pass unix:/data/android. php-fpm/tmp/php-fpm.socket;
Fastcgi_param SCRIPT_FILENAME/data/android. wwwroot $ fastcgi_script_name;
Include fastcgi_params;
}

Location ~ \. Flv $ {
Flv;
}
Location ~ \. Mp4 $ {
Mp4;
}


# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
#
# Location ~ /\. Ht {
# Deny all;
#}
}


# Another virtual host using mix of IP-, name-, and port-based configuration
#
# Server {
# Listen 8000 default;
# Listen somename: 8080;
# Server_name somename alias another. alias;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}


# HTTPS server
#
# Server {
# Listen 443 default;
# Server_name localhost;

# Ssl on;
# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. key;

# Ssl_session_timeout 5 m;

# Ssl_protocols SSLv2 SSLv3 TLSv1;
# Ssl_ciphers HIGH :! ANULL :! MD5;
# Ssl_prefer_server_ciphers on;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}

}

----------------------------------- Nginx. conf end here ----------------------------------------------------
4. adb pushes nginx. conf/data/android. nginx/conf/

5. Start nginx and run./nginx-c./conf/nginx. conf in the/data/android. nginx directory.

6. Prepare the ffmpeg file.
Adb shell
Su
Chmod 777/system/bin/
Adb push ffmpeg/system/bin/
Adb shell
Su
Cd system/bin
Chmod 777 ffmpeg
Exit
Exit
Adb push libvorbisenc. so.2/system/lib
Adb push libvorbis. so.0/system/lib
Adb push libogg. so.0/system/lib
Adb push libtheoraenc. so.1/system/lib
Adb push libtheoradec. so.1/system/lib
Adb push libmp 3lame. so.0/system/lib
Adb push libfdk-aac.so.0/system/lib
Adb push segmenter/system/bin
Adb shell
Su
Cd/system/bin
Chmod 777 segmenter
Exit
Exit


7. Prepare relevant documents
Adb push 1.flv/data/android. wwwroot/

8. Prepare rtmp files.
Create the rtmp directory under the/data/directory and use the adb push method to push all files under the nginx-rtmp-module Directory to the/data/rtmp directory.
Modify./test/rtmp-publisher/player.html under this directory
---------------------------Player.html start here ---------------------------------------------------------------
! DOCTYPE html>


RTMP Player
<Script type = "text/javascript" src = "swfobject. js"> </script>
<Script type = "text/javascript">
Var flashVars = {
Streamer: 'rtmp: // 192.168.1.2/myapp ',
File: 'test1'
};
Swfobject. embedSWF ("RtmpPlayer.swf", "rtmp-publisher", "500", "400", "9.0.0", null, flashVars );
</Script>



Flash not installed





---------------------------Player.html end here ---------------------------------------------------------------

9. streaming
"Rtmp: // 192.168.1.2/myapp" indicates url, and "test1" indicates stream

Streaming Method 1: ffmpeg-re-I 1.flv-f flv rtmp: // 192.168.1.2/myapp/test1
Note: push the related files
Here I will write this simple as pushrtmp Batch Processing
------------------------------- Pushrtmp start here -----------------------------------------------------------
! /System/bin/sh
File = $1
File_name = 'echo $ {file} | busybox awk-F'. ''{print $1 ""}''
Ffmpeg-re-I./$ 1.flv-f flv rtmp: // 192.168.1. $2/myapp/test1
--------------------------------- Pushrtmp end here -----------------------------------------------------------
The execution method is simple./pushrtmp 1 2.

10. Test
Access http: // 192.168.1.2: 801/player.html on another machine.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.