一个简单视频网站开发小记
前言
視頻格式轉(zhuǎn)換,視頻圖片截取,視頻存儲設(shè)計,大文件上傳處理以及相關(guān)配置,前端視頻播放,視頻播放流暢度,每一個都不簡單,都需要花心思思考解決方法!基本上每個問題,都是使用相應(yīng)的開源庫!
?
需求背景
手機拍攝的視頻越來越多,然而手機的容量有限,故想到開發(fā)一個手機視頻保存與播放的簡單網(wǎng)站,只需要實現(xiàn)我的需求即可!
?
技術(shù)實現(xiàn)方案
VBox+LNMP+Laravel5.1+ffmpeg+ckplayer
網(wǎng)站運行于筆記本虛擬機中
?
運行系統(tǒng)相關(guān)說明
Virtual Box:4.3.18
Linux:CentOS Linux release 7.1.1503 (Core)
Nginx:nginx/1.8.0
MySQL:Ver 5.7.9 for Linux on x86_64 (MySQL Community Server (GPL))
PHP:PHP 5.6.16
ffmpeg:version 2.6.3
?
實現(xiàn)效果圖
?
源代碼下載
http://files.cnblogs.com/files/wadeyu/familyvideo.zip
?
問題總結(jié)之PHP
1)編譯安裝PHP
yum install gcc gcc-c++ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel openssl openssl-devel
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr --with-mysqli=mysqlnd --with-iconv-dir=/usr --with-gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-openssl --with-mhash --enable-pcntl --enable-sockets --enable-soap --without-pear --enable-zip --with-bz2 --enable-calendar --enable-ftp --enable-ctype --enable-exif --disable-ipv6 --with-sqlite3 --enable-pdo --with-pdo-mysql=/usr --enable-phar --with-curl
2)yum install libmcrypt
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
No package libmcrypt available.
Error: Nothing to do
解決辦法:
yum install epel-release //擴展包更新包
yum update //更新yum源
3)configure: error: Cannot find MySQL header files under /usr.
安裝mysql-devel包 yum install mysql-devel
4)3.configure: error: Cannot find libmysqlclient under /usr.
find / -name '*libmysqlclient*'
/usr/lib64/mysql/libmysqlclient.so.18
/usr/lib64/mysql/libmysqlclient_r.so.18
/usr/lib64/mysql/libmysqlclient_r.so.18.1.0
/usr/lib64/mysql/libmysqlclient.so.20
/usr/lib64/mysql/libmysqlclient.so.18.1.0
/usr/lib64/mysql/libmysqlclient.so
/usr/lib64/mysql/libmysqlclient.a
/usr/lib64/mysql/libmysqlclient.so.20.0.9
發(fā)現(xiàn)其實保存在lib64那個目錄下了,拷貝一份到/usr/lib/mysql目錄下就可以了
cp /usr/lib64/mysql/* /usr/lib/mysql/
5)composer安裝
https://getcomposer.org/download/
file_get_contents(): Failed to enable crypto
解決方法:
wget http://curl.haxx.se/ca/cacert.pem
curl -sS https://getcomposer.org/installer | php -- --cafile=cacert.pem
6)php-ffmpeg擴展編譯安裝
因為php-ffmpeg擴展很久沒有更新,跟我使用的ffmpeg版本不兼容,編譯安裝過程中碰到不少坑,
我使用這個擴展最新版本+加上修改編譯配置才能成功
從GIT下載兼容最新版本的代碼
git clone https://github.com/tony2001/ffmpeg-php.git ffmpeg-php-0.6.0
源代碼目錄找到config.m4文件,ffmpeg頭部檢測的代碼修改為:
7)mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket 'MySQL' (2)
如果是localhost mysql客戶端會嘗試通過SOCKET連接 所以連不上 換成Ip地址就可以了 127.0.0.1
?
問題總結(jié)之Nginx
1)[error] 3109#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 10.0.2.2, server: localhost, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/usr/local/php/run/php-fpm.socket:", host: "192.168.1.2"
nginx配置WEB根目錄沒有配置,在SERVER CONTEXT設(shè)置好通用的ROOT就可以了,還需要設(shè)置好SCRIPT_FILENAME這個參賽,需要包含完整的路徑,有時候包含的fastcgi_params文件沒有這個參數(shù)的設(shè)置,需要主動設(shè)置好
2)windows下編輯虛擬機共享目錄下的靜態(tài)文件,NGINX還是返回修改之前的文件
gzip on;開啟gzip壓縮解決了這個問題,為什么?
3)[error] 2126#0: *384 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 10.0.2.2, server: localhost, request: "POST /upload/ HTTP/1.1", upstream: "fastcgi://unix:/usr/local/php/run/php-fpm.socket", host: "192.168.1.2", referrer: "http://192.168.1.2/upload/"
fastcgi_read_timeout 600; # Set fairly high for debugging
?
問題總結(jié)之CentOS7
1)防火墻默認(rèn)使用的是firewall不是iptables,需要開放端口外部才能訪問
開啟端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
重啟防火墻
firewall-cmd --reload
2)開源視頻庫ffmpeg安裝
因為用的最新的CentOS系統(tǒng),官方倉庫中沒要找到現(xiàn)成的rpm包,費了一番周折找到第三方RPM倉庫包含
先安裝第三方倉庫源 rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
再安裝ffmpeg yum install ffmpeg ffmpeg-devel
3)ffmpeg命令使用
ffmpeg -y -i IMG_0071.MOV -f mp4 -async 1 -acodec aac -vcodec libxvid -qscale 7 -dts_delta_threshold 1 -strict -2 output.mp4
ffmpeg -i test.asf -y -f image2 -t 0.001 -s 352x240 a.jpg
?
問題總結(jié)之MySQL
1)phpmysqladmin ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
1 ALTER USER 'root'@'localhost' IDENTIFIED BY 'yh!2@#A33@@$$' 2 GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'yh!2@#A33@@$$' WITH GRANT OPTION; 3 FLUSH PRIVILEGES;?2)?Your password has expired.
MySQL5.7版本以及以上自動開啟了用戶密碼過期功能,通過設(shè)置mysqld參數(shù):
default_password_lifetime=0 禁用此功能然后重啟mysql服務(wù)器
其它
1. nginx php-fpm php配置好了相關(guān)上傳大文件的配置還是上傳失敗
1)檢查php臨時目錄大小是否比上傳文件要大幾倍
2)臨時目錄需要有可寫可執(zhí)行權(quán)限
3)如果是虛擬機,文件不要存儲在共享目錄下,通過PHP move_uploaded_file文件移動到共享目錄很慢,而且碰到CGI程序中途退出
2.提供訪問速度
1)laravel框架緩存
php artisan optimize --force
2)開啟字節(jié)碼緩存 opcache
?
后記
1.碰到的最大難點是ffmpeg庫以及ffmpeg php擴展安裝
2.視頻需要加上標(biāo)簽分類
3.視頻需要分片提高響應(yīng)速度
4.使用虛擬機播放視頻比較慢,后面嘗試使用樹莓派
?
參考資料
[1] CentOS yum安裝mcrypt
http://www.cnblogs.com/linux-super-meng/archive/2014/12/08/4150987.html
[2] PHP FastCGI Example
https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
[3] FastCGI sent in stderr: “Primary script unknown”
http://stackoverflow.com/questions/17194196/1-fastcgi-sent-in-stderr-primary-script-unknown
http://serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown/517207#517207
[4] CentOS7 firewalld設(shè)置端口
http://www.cnblogs.com/kootao/p/4752435.html
[5] fedora/centos7防火墻FirewallD詳解
http://www.cnblogs.com/yudar/p/4294500.html
[6] CentOS修改系統(tǒng)環(huán)境變量
http://www.linuxidc.com/Linux/2012-07/64532.htm
[7] 安裝composer SSL operation failed with code 1
http://www.cnblogs.com/brookin/p/4425950.html
[8] Packagist / Composer 中國全量鏡像
http://pkg.phpcomposer.com/
http://www.phpcomposer.com/
[9] 更改yum源為163鏡像站點
http://mirrors.163.com/.help/centos.html
[10] FFmpeg常用基本命令
http://www.cnblogs.com/dwdxdy/p/3240167.html
http://www.cnblogs.com/top5/archive/2009/12/30/1636349.html
[11] Unable to install FFMPEG PHP extension
https://community.centminmod.com/threads/unable-to-install-ffmpeg-php-extension.1519/page-2
[12] Compile against newer ffmpeg fails because of avutil/time.h
http://sourceforge.net/p/ffmpeg-php/bugs/59/
[13] ffmpeg官方網(wǎng)站
http://ffmpeg-php.sourceforge.net/index.php
[14] mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket 'MySQL'
http://stackoverflow.com/questions/13769504/mysqlimysqli-hy000-2002-cant-connect-to-local-mysql-server-through-sock
http://segmentfault.com/q/1010000000328531
[15] 解決大文件上傳相關(guān)配置
http://blog.csdn.net/z_p_h/article/details/8995160
[16]mysql用戶密碼過期策略
http://dev.mysql.com/doc/refman/5.7/en/password-expiration-policy.html
轉(zhuǎn)載于:https://www.cnblogs.com/wadeyu/p/5092794.html
總結(jié)
以上是生活随笔為你收集整理的一个简单视频网站开发小记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: angularJS的controller
- 下一篇: Spring 学习笔记 3. 尚硅谷_佟