Build an mp4/flv Streaming Media Server Based on tengine in CentOS6 (
Location ~ \. Mp4 $ {
Root/mnt/media/vod;
Mp4;
Limit_conn addr 20;
Limit_rate 200 k;
}
Location/hls {
# Serve HLS fragments
Alias/mnt/media/app;
}
Access_log logs/nginxflv_access.log access;
}
}
---------------- Nginx configuration file --------------
4. Convert your movies into mp4 and flv formats to test the nginx environment.
4.1) Prepare a movie and find it on the hard disk,
Rename the movie to movie1.mp4 and upload it to the server/opt/media/video. The directory is used to store our original videos. Another directory is/opt/media/vod, which is used to store converted videos.
The specific directory structure here is:
/Opt/media/video-> store the original video
/Opt/media/app-> stores videos converted to m3u8 for http access (HLS)
/Opt/media/vod-> stores converted flv and mp4 videos for http or rtmp access.
4.2) Use ffmpeg to convert mp4 files (ffmpeg does not support rmvb)
[Root @ ay130637915205z ~] # Cd/opt/media/video/
[Root @ ay130642515205z video] # ffmpeg-I movie1.mp4-y-vcodec libx264-vf scale = "640:-1"-r 15-acodec libfaac ../vod/movie1.flv
-Y: File Overwrite,-vf scale = "640:-1": the size is adjusted to 640 in width and the height is automatic.-r 15: The number of frames is 15fps, here, libfaac audio encoding is used to prevent the iPhone from having no sound when it is converted to ts format.
Add a key frame to support drag playback
[Root @ ay130637915205z video] # cd ../vod
[Root @ ay130642515205z vod] # mv movie1.flv movie1-src.flv
[Root @ ay130642515205z vod] # yamdi-I movie1-src.flv-o movie1.flv
[Root @ ay130638515205z vod] # rm-rf movie1-src.flv
4.3) Use mencoder to convert rmvb files
4.4) Convert flv to m3u8 of hls
Download and install segmenter
Yum install-y curl-devel zlib-devel openssl-devel perl-devel cpio expat-devel gettext-devel git
[Root @ ay130637915205z ~] # Git clonehttps: // github.com/johnf/m3u8-segmenter.git
[Root @ ay130637915205z ~] # Cd m3u8-segmenter/
[Root @ ay130642515205z m3u8-segmenter] # gcc-Wall-g m3u8-segmenter.c-o segmenter-lavformat
[Root @ ay130642515205z m3u8-segmenter] # cp segmenter/usr/bin/
To convert to ts, the source size and definition of the film depend on the flv file. Therefore, you must unify the conversion to flv.
[Root @ ay130638515205z vod] # cd/mnt/media/vod
[Root @ ay130642515205z vod] # mkdir/mnt/media/app/movie1/
[Root @ ay130638515205z vod] # ffmpeg-y-I movie1.flv-f mpegts-c: v copy-c: a copy-vbsf hsf-_mp4to1_ B/mnt/media/app/movie1/main. ts
Slice
[Root @ ay130642515205z movie1] # cd/mnt/media/app/movie1/
[Root @ ay130642515205z movie1] # segmenter-I main. ts-d 10-p movie1-m movie1.m3u8-uhttp: // 121.199.47.208/hls/movie1/
-D 10: each slice is 10 seconds.-p movie1: prefix of the slice name
-U URL: the prefix of the stream play list in m3u8. You can use movie1.m3u8 generated by cat to find out what is used.
Test it. Use Safari on the iPhone to access http: // 121.199.47.208/hls/movie1/movie1.m3u8.