1. 下载ffmpeg-2.3.2
https://www.ffmpeg.org/download.html
2.编译安装
./configure
make
make install
3.ts 分割:
ffmpeg -i input.ts -map 0:0 -map 0:1 -c copy -f segment -segment_time 10 -segment_list test.m3u8 -segment_format ts 'fileSequence%d.ts'
4.带转码复杂点的应用参考:
ffmpeg -i input.mkv -codec copy -map 0 -f segment -vbsf h264_mp4toannexb -flags -global_header -segment_format mpegts -segment_list sample.m3u8 -segment_time 10 seg-%03d.ts
ffmpeg -i /home/charlie/Videos/1080p.mp4 -map 0:0 -map 0:1 -c copy -f segment -segment_time 22 -vbsf h264_mp4toannexb -segment_list test.m3u8 -segment_format ts 'fileSequence%d.ts'
http://sinclairmediatech.com/encoding-hls-with-ffmpeg/
Nginx 服务器搭建:
1.下载依赖库:pcre-8.02.tar.gz
下载地址:http://sourceforge.net/projects/pcre/?source=typ_redirect
tar -zxvf pcre-8.02.tar.gz
./configure
make
sudo make install
1.安装依赖库openssl
sudo apt-get install openssl
sudo apt-get install libssl-dev
sudo apt-get install libssl0.9.8
2.下载nginx-0.7.65.tar.gz
下载地址:https://code.google.com/p/dpvps/downloads/detail?name=nginx-0.7.65.tar.gz&can=2&q=
或者这里下载最新代码:https://github.com/nginx/nginx
./configure --with-http_stub_status_module --prefix=/opt/nginx
make
sudo make install
安装到/opt/nginx
编译错误解决: 有时候会出现warning treat as error ,导致编译退出。
解决方案:vi objs/Makefile ,将-Werror选项去掉
#CFLAGS = -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g
CFLAGS = -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -g
3.配置nginx
1> /opt/nginx/sbin/nginx 运行程序
2> /opt/nginx/conf/nginx.conf 配置文件
server {
listen 80; /*配置端口*/
server_name localhost;
3> 文件类型问题:编辑 /usr/local/nginx/conf/mime.types 文件,添加如下类型,我没有添加也可以
application/x-mpegURL m3u8;
video/MP2T ts;
4> server 文件访问目录:
/opt/nginx/html/
4.启动nginx
export LD_LIBRARY_PATH=/usr/local/lib /*pcre.so 放在这里,不指定的话会报找不到pcre.so库错误*/
./nginx
上述两个命令写在start.sh中
用 sudo ./start.sh 启动
停止nginx ,直接kill -9
5.访问nginx 服务
执行输入 http://ip
就可以访问到 /opt/nginx/html/index.html
/*ffmpeg 转码例子*/
将带2个audio track 的mkv 文件转换为mp4格式,编码格式不变
./ffmpeg -i /home/XXX/Videos/2audiotracke.mkv -strict -2 -codec copy -map 0:0 -map 0:1 -map 0:2 /home/XXX/Videos/2audiotracke_2.mp4
-----------------------------------------------------------------------------------------------------------------------------
ffmpeg 参数: (详细解释清参考http://www.ffmpeg.org/ffmpeg.html)
-i filename 输入文件
-map file:stream 设置输入流映射(比如输入文件有多路音轨,设置哪路音轨到输出文件)
-c codec 设置编码格式 copy表示不进行重新编码
-ss position 设置开始编码的start point