å€ãã®ãã©ãŠã¶ã§HTML5ãµããŒããå°å ¥ãããããšã«ããããããªã¿ã°ã䜿çšããŠãããªãã¬ãŒã€ãŒãåã蟌ãããšãå¯èœã«ãªããŸããã åãã©ãŠã¶ãŒã¯ãã³ãŒããã¯ãšã³ã³ãããŒã®ç¹å®ã®ã»ããããµããŒãããŸãã ãã®ãµããŒãã«ã€ããŠã¯ã httpïŒ//diveintohtml5.org/video.html#what-worksã§è©³ãã説æãããŠããŸã ã
ã·ã¹ãã ã®äž»ãªèŠä»¶ã®1ã€ã¯ãAppleããã€ã¹ïŒiPhoneãiPadãiPodïŒã®ãµããŒãã§ããã ãããã®ããã€ã¹ã¯åäžåœ¢åŒã®ãªã³ã©ã€ã³ãããªããµããŒãããŠãããšããäºå®ïŒMP4ã§ãããFlashãã¬ãŒã€ãŒã䜿çšã§ããªããããåœåã¯ãŠãããŒãµã«MP4ã³ã³ãããŒïŒH.264ãããªãšAACãªãŒãã£ãªïŒãåºç€ãšããããšã決å®ãããŸããã ãšã³ã³ãŒãæã«ã¯ããããã®ã³ãŒããã¯libx264ããã³libfaacã®ç¡æå®è£ ã䜿çšãããŸãã ãŠãŒã¶ãŒã®ãã©ãŠã¶ãŒããããªã¿ã°ããµããŒãããŠããªãå ŽåããŸãã¯ãã©ãŠã¶ãŒãMP4圢åŒã®ãããªããµããŒãããŠããªããããµããŒããäžå¯èœãªå Žåã«èªåçã«æ¥ç¶ããFlashãã¬ãŒã€ãŒã䜿çšããŠãä»ã®ãã©ãŠã¶ãŒã§ãããã®åœ¢åŒããµããŒããããªãããšãè£ãããšã«ããŸããã
建ç¯
ã·ã¹ãã ã®ã¢ãŒããã¯ãã£ã¯éåžžã«ã·ã³ãã«ã§ã2çš®é¡ã®ãµãŒããŒãå«ãŸããŠããŸãã
- å€æãµãŒããŒïŒããŒã¿ããŒã¹ãµãŒããŒããã³WebãµãŒããŒãšããŠãæ©èœïŒ
- å€æããããããªãã¡ã€ã«ã転éããããã¡ã€ã«ãµãŒããŒã
ã³ã³ãã³ãé ä¿¡ã®äž»ãªæ©èœã¯ãã¡ã€ã«ãµãŒããŒã§ãã ã¢ã€ãã¢ã¯ã人æ°ã®ãããããªãããŠã³ããŒãããå Žåã«ãããã¯ãŒã¯ã€ã³ã¿ãŒãã§ã€ã¹ã®è² è·ãžã£ã³ããåé¿ããããã«ãå€æåŸã§ããã ãæ©ãã¡ã€ã³ãµãŒããŒãããã¡ã€ã«ãµãŒããŒã«ãã¡ã€ã«ã転éããããšã§ãã ç¹å®ã®ãããªã¯ãªãããçŸåšé 眮ãããŠãããµãŒããŒãç¹å®ããããã«ãããŒã¿ããŒã¹ã«ã¯ãªã³ã¯ããŒãã«videos_serversããããŸãã ãããªã¹ããªãŒãã³ã°ããããŒããã£ã¹ãããããã®ã¢ãžã¥ãŒã«ã¯ããã¹ãŠã®ãã¡ã€ã«ãµãŒããŒãšå€æãµãŒããŒã«ã€ã³ã¹ããŒã«ãããŸãã ãµãŒããŒéã§ãã¡ã€ã«ã移åããããã«ãNFSãããã³ã«ã䜿çšãããŸãã
å€æãã¥ãŒã¯ãbeanstalkdãã¥ãŒãµãŒããŒïŒ http://kr.github.com/beanstalkd/ ïŒã䜿çšããŠç·šæãããŸãã ãã¹ãã§ã¯ã30åã®ã¯ãŒã«ãŒã6ã³ã¢ãµãŒããŒã§å®è¡ã§ããããšã瀺ãããŠããŸãã 30人ã®ãŠãŒã¶ãŒããã·ã¹ãã å šäœã®ããã©ãŒãã³ã¹ãæãªãããšãªããåæã«ãããªãå€æã§ããŸãïŒWebãµãŒããŒåŽã®ããŒãžçææéã¯èš±å®¹ç¯å²å ã§ãïŒã å€æ°ã®åŽåè ã䜿çšãããã¹ãã¯å®æœãããŸããã§ããããååãªåã®ããŒãžã³ããããå¿ èŠã«å¿ããŠåŽåè ã®æ°ãå¢ããããšãã§ããŸãã
ãµãŒããŒãœãããŠã§ã¢
Debian Lennyã¯ãå€æãµãŒããŒãšãã¹ãŠã®ãã¡ã€ã«ãµãŒããŒã«ã€ã³ã¹ããŒã«ãããŸãã
ãããªåŠçãœãããŠã§ã¢
ãããªãMP4圢åŒã«å€æããã«ã¯ãçŸæç¹ã§æã人æ°ã®ãããœãªã¥ãŒã·ã§ã³-ffmpegïŒ http://www.ffmpeg.org/ ïŒã䜿çšãããŸã ã ffmpegã¯ãããŸããŸãªåœ¢åŒã®ãããªãå€æããçŽ æŽãããä»äºããããã«ãã³ã¢ã·ã¹ãã ã§è€æ°ã®ããã»ããµã³ã¢ã䜿çšã§ããŸãã åŸåŠçã«ã¯ãgpacããã±ãŒãžïŒ http://gpac.sourceforge.net/ ïŒã®ãã°ãããMP4BoxãŠãŒãã£ãªãã£ã䜿çšããŸãã ffmpegã¯ãmoov-atomsãïŒãããªã«é¢ããã¡ã¿æ å ±ïŒããã¡ã€ã«ã®æåŸã«é 眮ãããããåŸåŠçãå¿ èŠã§ããããŠãŒã¶ãŒããããªãå®å šã«ããŒããããã®ãåŸ ããã«ãããªãèŠèŽã§ããããã«ããã«ã¯ããããã®ã¢ãã ããã¡ã€ã«ã®å é ã«ããå¿ èŠããããŸãã MP4Boxã¯ããããå é ã«ç§»åããããã«ããã¹ãŠã®æšæºã«åŸã£ãŠãã¡ã€ã«ãæã¡èŸŒã¿ã察å¿ããã¢ãžã¥ãŒã«ãä»ããã¹ããªãŒãã³ã°ã«é©ããŠããŸãã
$ ffmpeg -vpre videobam -y -i input.avi -s 320x240 -vcodec libx264 -acodec libfaac -threads 0 -ab 64k -b 400k -bt 500k -g 24 -r 24 temp.mp4 $ MP4Box -add temp.mp4 output.mp4
-g 24ãªãã·ã§ã³ã«æ³šæããŠãã ããã æ°ããããŒãã¬ãŒã ãä¿åããããã¬ãŒã æ°ã決å®ããŸãã ãŠãŒã¶ãŒãé·ããããªãå®å šã«ããŒããããã®ãåŸ ããã«ã¹ã¯ããŒã«ã§ããããã«ãããŒãã¬ãŒã ã®ååšãå¿ èŠã§ãã ãã®æ©èœã¯ãå€æã¢ãžã¥ãŒã«ã䜿çšããŠå®è£ ãããŸãã ã¯ã©ã€ã¢ã³ãïŒãã©ãŠã¶ãŒãŸãã¯Flashãã¬ãŒã€ãŒïŒã¯ãèµ·åGETãã©ã¡ãŒã¿ãŒãWebãµãŒããŒã«éä¿¡ããŸããããã¯ãå€æã¢ãžã¥ãŒã«ã«ãã£ãŠåŠçãããåçãéå§ããç§æ°ãæå³ããŸãã
GET /output.mp4?start=856.733 HTTP / 1.1
ããã«ã -threads 0ãã©ã¡ãŒã¿ãŒã¯ ãããã»ããµã³ã¢ã®æ°ãèªåçã«æ±ºå®ããŠããã»ã¹ã§äœ¿çšããå¿ èŠæ§ãããã°ã©ã ã«ç€ºãããšã«ãããå€æé床ãå€§å¹ ã«åäžãããŸãã å¿ èŠãªãã¬ãŒã æ°-r 24ãæå®ããããšãéèŠã§ãã 1ç§ãããã®ãã¬ãŒã æ°ãäžé©åã§ããïŒäž»ã«ã¹ã¯ãªãŒã³ãã£ã¹ãïŒãããäžéšã®ãããªã§åé¡ãçºçããŸããããã®ããããããªã®ç¶ç¶æéã«å¯ŸããŠå€ææéãå®å šã«äžé©åã§ããã
åãããªã«ã€ããŠãç¹å®ã®æç¹ã§ã¹ã¯ãªãŒã³ã·ã§ãããæ®åœ±ãããããããŠãŒã¶ãŒã¯ãããªã®å 容ããã°ããèŠãããšãã§ããŸãã ãã®ãããªç»åã®äŸã¯ã httpïŒ//videobam.com/tourã§èŠãããšãã§ããŸãã ffmpegã¯ãããã®åçããã°ããæ®ãããšãã§ããŸããïŒåœŒã¯ãããªãé©åãªç¬éã«å·»ãæ»ããŠããåçãæ®ããŸãïŒã ãã°ããåçãæ®ãã«ã¯ãmplayerãŠãŒãã£ãªãã£ïŒ http://www.mplayerhq.hu/ ïŒã䜿çšããŸãããã®ãŠãŒãã£ãªãã£ã¯ãããŒãã¬ãŒã ã䜿çšããŠã»ãŒç¬æã«ãã¡ã€ã«ã移åããŠåçãæ®åœ±ããŸãã
$ mplayer -ss 00:00:04 -sstep 12 -frames 16 -vo jpegïŒoutdir = / tmp / pictures / -nosound output.mp4
ãã¹ãŠã®ãœãããŠã§ã¢ã¯ãœãŒã¹ã³ãŒãããæåã§ã¢ã»ã³ãã«ãããããšã«æ³šæããŠãã ããïŒå¯Ÿå¿ããããŒãžã§ã³ç®¡çã·ã¹ãã ããè€è£œãããããæ°ãããã«ãã䜿çšãããŸãïŒã å®å®ãããã©ã³ãã®ææ°ããŒãžã§ã³ã䜿çšããããšã¯éåžžã«éèŠã§ãããã°ãä¿®æ£ãããç¬éãããããã®ä¿®æ£ãLinuxãã£ã¹ããªãã¥ãŒã·ã§ã³ã®ããã±ãŒãžã«åæ ããããŸã§ã«æéããããããã§ãã ç¹ã«ãäžéšã®QuickTimeã¯ãªãããMP4圢åŒã«å€æãããšãã«é³ãéåãããšããåé¡ãçºçããŸããã ãã®åé¡ã¯ãææ°ã®libfaacããã³libfaadã©ã€ãã©ãªãã€ã³ã¹ããŒã«ããããšã§æ£åžžã«è§£æ±ºãããŸããã
ãµãŒããŒã¢ãžã¥ãŒã«
泚ïŒh264ã¢ãžã¥ãŒã«ããã«ãããã«ã¯ããããhttp://pastie.org/1405286ãé©çšããå¿ èŠãããå ŽåããããŸãã
$ cd nginx-0.8.53 $ ./configure --add-module = .. / nginx_mod_h264_streaming-2.2.7 / --add-module = .. / ngx_http_secure_download /
ã¹ããªãŒãã³ã°ãããªã¯ãnginx WebãµãŒããŒçšã®h264ã¢ãžã¥ãŒã«ïŒ http://h264.code-shop.com/ ïŒã«ãã£ãŠæäŸãããŸãã ãã®ã¢ãžã¥ãŒã«ã®ã»ããã¢ããã¯éåžžã«ç°¡åã§ãã
/usr/local/nginx/conf/nginx.conf
å Žæã\ .mp4 $ { mp4; }
ãµãŒããŒãåèµ·åãã10ç§ãããããªãããŠã³ããŒãããããšããŸãã
$ wget -O temp.mp4â http://videobam.com/test.mp4?start=10.0â
ãªã³ã¯ã®ã³ããŒïŒããããªã³ã¯ïŒããä¿è·ããããã«ãHTTP Secure Downloadã¢ãžã¥ãŒã«ïŒ http://github.com/replay/ngx_http_secure_download ïŒã䜿çšããŸãã èšå®ã§ãœã«ãã»ããã䜿çšããŠããããªãã¡ã€ã«ãžã®ãªã³ã¯ããšã³ã³ãŒãã§ããŸãã
/usr/local/nginx/conf/nginx.conf
å Žæã* /ãããª{ secure_download on; secure_download_path_modeãã¡ã€ã«ã secure_download_secret saltsaltsalt $ remote_addr; ifïŒ$ secure_download = "-1"ïŒ{ /expired.html breakãæžãæããŸãã } ifïŒ$ secure_download = "-2"ïŒ{ /bad_hash.html breakãæžãæããŸãã } ifïŒ$ secure_download = "-3"ïŒ{ 500ãè¿ããŸãã } mp4; æžãæã^ïŒã*ïŒ/ [0-9a-zA-Z] * / [0-9a-zA-Z] * $ $ 1ãã¬ãŒã¯; }
ããŠã³ããŒããªã³ã¯ã¯æ¬¡ã®ããã«çæãããŸãã
ãããªãã¯é¢æ°secure_urlïŒ$ urlïŒ { $ ts =æéïŒïŒ+ 3600; $ ts_in_hex = dechexïŒ$ tsïŒ; $ secret = 'saltsaltsalt'ã $ _SERVER ['REMOTE_ADDR']; $ hash = md5ïŒ$ urlã '/'ã$ secretã '/'ã$ ts_in_hexïŒ; $ urlãè¿ããŸãã ã/ãã $ããã·ã¥ã ã/ãã $ ts_in_hex; }
NFSãšautofs
ãã¡ã€ã«ãµãŒããŒãæäœããããã«ãautofsãå€æãµãŒããŒã«ã€ã³ã¹ããŒã«ãããŸãã èŠæ±ã«å¿ããŠå¿ èŠãªãã¡ã€ã«ãµãŒããŒãããŠã³ãããŸãã ãã¹ãŠã®NFSããŒãã£ã·ã§ã³ã¯ãœããã¢ãŒãã§ããŠã³ãããããã¡ã€ã«ãµãŒããŒã«é害ãçºçããå Žåã«ã³ããŒããã»ã¹ãããªãŒãºããã®ãé²ããŸãã
/etc/auto.storage
0ïŒ/ var / www / shared / local_storage 1 -fstype = nfsãrwãasyncãsoftãintrãtimeo = 20ãrsize = 64000ãwsize = 64000 f1.videobam.com:/var/storage 2 -fstype = nfsãrwãasyncãsoftãintrãtimeo = 20ãrsize = 64000ãwsize = 64000 f2.videobam.com:/var/storage 3 -fstype = nfsãrwãasyncãsoftãintrãtimeo = 20ãrsize = 64000ãwsize = 64000 f3.videobam.com:/var/storage 4 -fstype = nfsãrwãasyncãsoftãintrãtimeo = 20ãrsize = 64000ãwsize = 64000 f4.videobam.com:/var/storage
ãã¹ãŠã®ãµãŒããŒäžã®ãã¡ã€ã«ãšãã©ã«ããŒã®æ§é ã¯åäžã§ããããããã¡ã€ã«ãµãŒããŒã§ã®äœæ¥ã¯ããã¹ãã³ãã¬ãŒãã§ãµãŒããŒèå¥åã眮ãæããããšã«ããééçã«å®è¡ãããŸãã ç¹å®ã®ãã£ã¬ã¯ããªå ã®ãã¡ã€ã«ãšãã©ã«ãã®æ°ã«é¢ããext3ãã¡ã€ã«ã·ã¹ãã ã®å¶éã«ã€ããŠèŠããŠããããšãéèŠã§ãããã¹ãŠã®ãããªã¯ãvideos / a / ab / video.mp4ãšãã圢åŒã®ãã£ã¬ã¯ããªã«ä¿åãããŸãããaããšãabãã¯ãããªåã®æåã®æåã§ãã
ã¯ã©ã€ã¢ã³ãéš
åè¿°ã®ããã«ãVideoJSïŒ http://videojs.com ïŒã䜿çšããŠãHTML5ãããªãåçããã³ã¹ã¿ã€ã«ããŸãã ããã«ãVideoJSã¯Flashãã¬ãŒã€ãŒãžã®ãããã¹ããŒããªãããŒã«ããã¯ãå®è¡ããŸãïŒãã©ãŠã¶ãŒããœãŒã¹ãªã¹ãã®ãããªãã¡ã€ã«ããµããŒãããŠããªãå ŽåïŒã Flashãã¬ãŒã€ãŒãšããŠãflowplayerïŒ http://flowplayer.org ïŒã䜿çšãããŸãã
ããŒãå¥ãªã³ã¯
ãœãããŠã§ã¢ïŒ
beanstalkd kr.github.com/beanstalkd
VideoJS videojs.com
flowplayer flowplayer.org
ffmpeg www.ffmpeg.org
mplayer www.mplayerhq.hu
gpacïŒMP4BoxïŒ gpac.sourceforge.net
nginx 0.8.53 nginx.org/en
nginx h264ã¹ããªãŒãã³ã°ã¢ãžã¥ãŒã«h264.code-shop.com
nginx httpã»ãã¥ã¢ããŠã³ããŒãgithub.com/replay/ngx_http_secure_download
nginxã¢ããããŒãé²è¡ã¢ãžã¥ãŒã«github.com/masterzen/nginx-upload-progress-gimodule
è¿œå è³æïŒ
diveintohtml5.org/video.html
rob.opendot.cl/index.php/useful-stuff/ffmpeg-x264-encoding-guide
sites.google.com/site/linuxencoding/x264-ffmpeg-mapping
x264dev.multimedia.cx
rodrigopolo.com/ffmpeg/cheats.html
e-mats.org/2010/01/fixing-stuttering-audio-with-ffmpeg-and-quicktime
www.videohelp.com/tools/mp4box