/************************************
允許轉載,請註明文章來源和作者
Zhang Jianwei
BIT
************************************/一、搭建LAMP
在搭建LAMP時,主要參考了這一篇文章:http://wiki.ubuntu.org.cn/Apache,基本上按照上面的做法就可以了。不過在安裝phpmyadmin時,要按照第一種方法來做,第二種雖然是推薦方法,但是依此方法不能夠成功安裝。
二、安裝FFMPEG(網上教程較多,不做記述,一般可以apt-get安裝)
update:關於ffmpeg的安裝經常會出現問題,在ubuntu下安裝編譯ffmpeg最好沿用此網頁中的方法:
http://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
三、切片和生成m3u8文件
這一部分主要參考了文章:http://www.cnblogs.com/mystory/archive/2013/04/07/3006200.html
1、安裝支持庫
apt-get install libavformat-dev
2、獲得m3u8-segmenter
https://github.com/johnf/m3u8-segmenter
3、編譯安裝m3u8-segmenter
aclocal
automake -ac
./configure
make
sudo make install
4、編譯文件m3u8-segmenter
在這個教程中,使用的命令是:
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat
會報錯,報錯如下:
/usr/bin/ld: /tmp/ccxVPFGB.o: undefined reference to symbol 'avcodec_open2@@LIBAVCODEC_53'
/usr/bin/ld: note: 'avcodec_open2@@LIBAVCODEC_53' is defined in DSO /usr/lib/i386-linux-gnu/libavcodec.so.53 so try adding it to the linker command line
/usr/lib/i386-linux-gnu/libavcodec.so.53: could not read symbols: 無效的操作
可以發現是缺少鏈接庫所致,按照如下命令即可成功編譯:
gcc -Wall -g m3u8-segmenter.c -o segmenter -lavformat -lavcodec -lavutil
5、轉換文件格式(to .ts)
ffmpeg -y -i <in file> -vcodec copy -acodec copy -vbsf h264_mp4toannexb <output file>
6、對ts文件切片並生成m3u8文件
原文命令格式有誤,採用如下格式命令:
./segmenter -i <input file> -d <length in seconds> -p <output direction/prefix> -m <m3u8 filename> -u <url>
最後一個url參數可以是網址,也可以是本機路徑(如下),網址調試目前未成功,需繼續調試。
./segmenter -i test.ts -d 10 -p segtest/segtest_ -m test.m3u8 -u /home/vigor/source/
Update: Put the out-file direction in '/var/www/html', and order is
./segmenter -i test.ts -d 10 -p segtest/segtest_ -m test.m3u8 -u http://localhost/
7、使用VLC播放m3u8文件即可。