Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use nginx to build flv or mp4 streaming Media Server based on rtmp or http

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to use nginx to build flv or mp4 streaming media servers based on rtmp or http". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

I. streaming media playback mode

1. HTTP mode

In this way, you need to download FLV video files for local playback. Once the FLV video files are downloaded, it will not consume the resources and bandwidth of the server. But the drag function is not as powerful as RTMP/RTMP streaming media. Many video websites are implemented in HTTP, such as YouTube, Tudou, Ku6, etc.

2. RTMP/RTMP streaming media

This method does not need to download FLV video files locally, can play flv files in real time, and can drag and drop the playback progress bar at will, but it consumes the resources of the server.

Second, use nginx to build flv streaming media server

1. Install git

Yum install git

two。 Install dependency packages

Yum-y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64

3. Install ffmpeg and its dependent packages (my dependent packages are installed under / usr/local/src, but the installation location can be determined according to personal habits)

The following installation packages can be installed with yum, try to install with yum, and those that are not available can be obtained by wget.

# wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz

# tar xzvf yasm-1.2.0.tar.gz

# cd yasm-1.2.0

#. / configure

# make

# make install

# cd..

# git clone git://git.videolan.org/x264

# cd x264

#. / configure-enable-shared

# make

# make install

# cd..

# wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz

# tar xzvf lame-3.99.5.tar.gz

# cd lame-3.99.5

#. / configure-enable-nasm

# make

# make install

# cd..

# yum install libogg

Note: libogg is installed according to the .tar.gz package used in all versions of the tutorials on the Internet, but installing libvorbis,libvpx after installation will find that the libogg installation location can not be found, resulting in installation failure.

# wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz

# tar xzvf libvorbis-1.3.3.tar.gz

# cd libvorbis-1.3.3

#. / configure

# make

# make install

# cd..

# git clone http://git.chromium.org/webm/libvpx.git

# cd libvpx

#. / configure-enable-shared

# make

# make install

# cd..

# wget http://downloads.sourceforge.net/project/faac/faad2-src/faad2-2.7/faad2-2.7.tar.gz

# tar zxvf faad2-2.7.tar.gz

# cd faad2-2.7

#. / configure

# make

# make install

# cd..

# wget http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz

# tar zxvf faac-1.28.tar.gz

# cd faac-1.28

#. / configure

# make

# make install

# cd..

# wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz

# tar zxvf xvidcore-1.3.2.tar.gz

# cd xvidcore/build/generic

#. / configure

# make

# make install

# cd..

# git clone git://source.ffmpeg.org/ffmpeg

# cd ffmpeg

# / configure-- prefix=/opt/ffmpeg/-- enable-version3-- enable-libvpx-- enable-libfaac-- enable-libmp3lame-- enable-libvorbis-- enable-libx264-- enable-libxvid-- enable-shared-- enable-gpl-- enable-postproc-- enable-nonfree-- enable-avfilter-- enable-pthreads

# make & & make install

# cd..

Modify / etc/ld.so.conf as follows:

Include ld.so.conf.d/*.conf

/ lib

/ lib64

/ usr/lib

/ usr/lib64

/ usr/local/lib

/ usr/local/lib64

/ opt/ffmpeg/lib

Third, install the nginx module

# wget http://h364.code-shop.com/download/nginx_mod_h364_streaming-2.2.7.tar.gz

# tar zxvf nginx_mod_h364_streaming-2.2.7.tar.gz

# git clone git://github.com/arut/nginx-rtmp-module.git

# yum install pcre

Nginx could not find the address, so it had to be downloaded manually and uploaded.

# tar zxvf nginx-1.2.6.tar.gz

# cd nginx-1.2.6

# / configure-- prefix=/usr/local/nginx-- add-module=../nginx_mod_h364_streaming-2.2.7-- with-http_flv_module-- with-http_gzip_static_module-- with-http_stub_status_module-- with-http_mp4_module-- add-module=../nginx-rtmp-module-- add-module=../nginx-rtmp-module/hls-- with-cc-opt=-I/opt/ffmpeg/include-- with -ld-opt='-L/opt/ffmpeg/lib-Wl -rpath=/opt/ffmpeg/lib'

# make & & make install

Install yamdi

The function of yadmi is to add keyframes to flv files before dragging and playing.

# download yadmi

Wget http://sourceforge.net/projects/yamdi/files/yamdi/1.4/yamdi-1.4.tar.gz/download

# install yadmi

Tar xzvf yamdi-1.4.tar.gz

Cd yamdi-1.4

Make & & make install

Usage: yamdi-I input.flv-o out.flv

Add keyframes to input.flv files and export them to out.flv files

IV. Modify the nginx main configuration file

Vi / usr/local/nginx/conf/nginx.conf

User www www

Worker_processes 30

Error_log / usr/local/nginx/logs/error.log crit

Pid / usr/local/nginx/logs/nginx.pid

Events {

Use epoll

Worker_connections 65535

}

Http {

Include mime.types

Default_type application/octet-stream

Log_format main'$remote_addr-$remote_user [$time_local]'

'$ request'$status $bytes_sent'

'"$http_referer"$http_user_agent"'

'' $gzip_ratio''

Keepalive_timeout 60

Server_names_hash_bucket_size 128

Client_header_buffer_size 32k

Large_client_header_buffers 4 32k

Access_log off

Gzip on

Gzip_min_length 1100

Gzip_buffers 4 8k

Gzip_types text/plain

Output_buffers 1 32k

Postpone_output 1460

Client_header_timeout 3m

Client_body_timeout 3m

Send_timeout 3m

Sendfile on

Tcp_nopush on

Tcp_nodelay on

Server {

Listen 80

Server_name 192.168.1.105

Root / usr/local/nginx/html/

Limit_rate_after 5m; # Speed limit begins after 5m of flv video files have been downloaded

Limit_rate 512k; # Speed limit is 512K

Index index.html

Charset utf-8

Location ~\ .flv {

Flv

}

Location ~\ .mp4 ${

Mp4

}

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root html

}

}

}

5. Start nginx

Detect nginx.conf file configuration before startup

/ usr/local/nginx/sbin/nginx-t-c / usr/nginx/conf/nginx.conf

Or

/ usr/nginx/sbin/nginx-t

If there is an error, it will be corrected according to the number of rows reported.

If an error occurs: [error]: invalid PID number "" in "/ var/run/nginx.pid"

Usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf

Nginx start

/ usr/local/nginx/sbin/nginx-s reload

test

Http://192.168.1.105/player.swf?type=http&file=test1.flv

(where player.swf is the player and test1.flv is the video file)

The player should be placed with the video file.

The location of the video file corresponds to the location configured in nginx.conf.

This is the end of the content of "how to use nginx to build flv or mp4 streaming media servers based on rtmp or http". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report