Difference between revisions of "Membuat Sendiri TV Internet"

From OnnoWiki
Jump to navigation Jump to search
 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
Sumber: http://www.howtoforge.com/build-your-own-video-community-with-lighttpd-and-flowplayer-ubuntu-9.10
 
Sumber: http://www.howtoforge.com/build-your-own-video-community-with-lighttpd-and-flowplayer-ubuntu-9.10
  
Tulisan ini menjelaskan bagaimana kita dapat membuat sendiri streaming video komunitas menggunakan lighttpd menggunakan modul streaming mod_flv_streaming (untuk streaming video .flv, format yang digunakan oleh banyak video streaming komunitas seperti YouTube) dan modul mod_secdownload (untuk menghalangi hotlinking dari video) di Ubuntu. Kita akan menggunakan FlowPlayer video player, sebuah  Flash video player yang mendukung modul lighttpd mod_flv_streaming. Kita juga akan memperlihatkan bagaimana meng-encode video (.mp4 .mov .mpg .3gp .mpeg .wmv .avi) ke format FLV yang di dukjung oleh Adobe Flash.
+
Tulisan ini menjelaskan bagaimana kita dapat membuat sendiri streaming video komunitas menggunakan lighttpd menggunakan modul streaming mod_flv_streaming (untuk streaming video .flv, format yang digunakan oleh banyak video streaming komunitas seperti YouTube) dan modul mod_secdownload (untuk menghalangi hotlinking dari video) di Ubuntu. Kita akan menggunakan FlowPlayer video player, sebuah  Flash video player yang mendukung modul lighttpd mod_flv_streaming. Kita juga akan memperlihatkan bagaimana meng-encode video (.mp4 .mov .mpg .3gp .mpeg .wmv .avi) ke format FLV yang di dukung oleh Adobe Flash.
  
  
Line 11: Line 11:
 
  [[IP Address]] 192.168.0.9
 
  [[IP Address]] 192.168.0.9
  
. These settings might differ for you, so you have to replace them where appropriate.
+
Cara instalasi lighttpd di terangkan di
  
We need a lighttpd installation with PHP support, as shown in this tutorial: Installing Lighttpd With PHP5 And MySQL Support On Ubuntu 9.10. I won't cover this here, so please refer to this tutorial if you haven't already set up lighttpd with PHP support.
+
* [[Instalasi Lighttpd]]
  
Because we must run all the steps from this tutorial with root privileges, we can either prepend all commands in this tutorial with the string sudo, or we become root right now by typing
+
Kita menjalankan semua perintah di bawah sebagai root. Pastikan anda login sebagai root melalui perintah
  
sudo su
+
sudo su
  
 
2 Installing ffmpeg
 
  
We will use ffmpeg to convert our video files to the FLV format. The problem with the official Ubuntu ffmpeg package is that is doesn't come with MP3 encoding support, which means that our FLV videos will lose their sound after the conversion. Therefore we add the Debian-Multimedia repository to our sources.list and install the ffmpeg package from that repository - it comes with MP3 support by default. (You might wonder why we use the Debian-Multimedia repository instead of the Medibuntu repository, but the Medibuntu repository has no ffmpeg package at all.)
+
==Instalasi==
  
vi /etc/apt/sources.list
+
Instalasi menggunakan perintah
  
Add the Debian-Multimedia repository (you can find a mirror close to you here), e.g. like this:
+
apt-get install ffmpeg flvtool2
  
[...]
 
deb http://ftp-stud.hs-esslingen.de/pub/Mirrors/debian-multimedia/ stable main
 
deb-src http://ftp-stud.hs-esslingen.de/pub/Mirrors/debian-multimedia/ stable main
 
  
Then download the debian-multimedia-keyring package and install it:
+
==Buat Directory untuk menyimpan video==
  
wget http://www.debian-multimedia.org/pool/main/d/debian-multimedia-keyring/debian-multimedia-keyring_2008.10.16_all.deb
+
Misalnya
dpkg -i debian-multimedia-keyring_2008.10.16_all.deb
 
  
Next we create the file /etc/apt/preferences with the following contents to give the Debian-Multimedia packages a higher priority than the packages from the Ubuntu Karmic repository (to make sure that the ffmpeg package along with its dependencies get installed from the Debian-Multimedia repository, not from the Karmic repository):
+
mkdir -p /var/videos/incoming
 +
mkdir -p /var/videos/flv
  
vi /etc/apt/preferences
 
  
Package: *
+
==Encode Video menjadi FLV==
Pin: release a=karmic
 
Pin-Priority: 650
 
  
Package: *
+
Berikut akan di contohkan konversi video.avi di /var/videos/incoming (cara yang sama sebetulnya dapat juga dilakukan untuk extension .mp4 .mov .mpg .3gp .mpeg .wmv). Kita kan mengkonversikan file tersebut menjadi video.flv dan menyimpannya di directory /var/videos/flv. File video.flv dibuat untuk pixel 320x240 dengan frekuensi audio sampling 44100 Hz, dua kanal audio (stereo), dengan frame rate 12 fps. Caranya adalah sebagai berikut:
Pin: release a=stable
 
Pin-Priority: 700
 
  
(You might want to check out A Short Introduction To Apt-Pinning to find out why /etc/apt/preferences looks like that.)
+
ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 -ac 2 /var/videos/flv/video.flv
  
Finally update your package-list:
+
Untuk melihat pilihan yang lain ada baiknya melihat perintah
  
aptitude update
+
man ffmpeg
  
We can now install ffmpeg as follows:
+
Proses ini akan memerlukan beberapa waktu, keluaran / outputnya adalah sebagai berikut:
  
aptitude install ffmpeg
+
root@server1:~# ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 -ac 2 /var/videos/flv/video.flv
 +
FFmpeg version SVN-r13582, Copyright (c) 2000-2008 Fabrice Bellard, et al.
 +
  configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --bindir=${prefix}/bin --incdir=${prefix}/include /ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-libamr-nb --enable-libamr-wb --enable-x11grab --enable-libgsm --enable-libx264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscale --enable-libdc1394 --enable-nonfree --disable-mmx --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
 +
  libavutil version: 49.7.0
 +
  libavcodec version: 51.58.0
 +
  libavformat version: 52.16.0
 +
  libavdevice version: 52.0.0
 +
  libavfilter version: 0.0.0
 +
  built on May  3 2009 12:07:18, gcc: 4.3.2
 +
Input #0, avi, from '/var/videos/incoming/video.avi':
 +
  Duration: 00:10:53.82, start: 0.000000, bitrate: 5455 kb/s
 +
    Stream #0.0: Video: mpeg4, yuv420p, 1024x576 [PAR 1:1 DAR 16:9], 24.00 tb(r)
 +
    Stream #0.1: Audio: ac3, 48000 Hz, 5:1, 448 kb/s
 +
Output #0, flv, to '/var/videos/flv/video.flv':
 +
    Stream #0.0: Video: flv, yuv420p, 320x240 [PAR 4:3 DAR 16:9], q=2-31, 200 kb/s, 12.00 tb(c)
 +
    Stream #0.1: Audio: libmp3lame, 44100 Hz, stereo, 64 kb/s
 +
Stream mapping:
 +
  Stream #0.0 -> #0.0
 +
  Stream #0.1 -> #0.1
 +
Press [q] to stop encoding
 +
[libmp3lame @ 0x7f983556f6c0]lame: output buffer too small (buffer index: 8359, free bytes: 281)
 +
frame= 7847 fps= 13 q=2.0 Lsize=  21696kB time=653.92 bitrate= 271.8kbits/s
 +
video:16067kB audio:5114kB global headers:0kB muxing overhead 2.428783%
 +
root@server1:~#
  
+
Pastikan pada bagian output, kita melihat dua stream, satu untuk video, satu untuk audio. Jika kita hanya melihat video saja, maka artinya suaranya hilang.
3 Installing flvtool2
 
  
When we convert videos to the FLV format, we need to add some metadata such as the duration of the video to the FLV file so that FlowPlayer can properly display the length of the video. We can add this metadata with flvtool2. We can install flvtool2 as follows:
+
Setelah melalukan konversi kita dapat menambahkan metadata ke video.flv menggunakan flvtool2:
  
aptitude install flvtool2
+
cat /var/videos/flv/video.flv | flvtool2 -U stdin /var/videos/flv/video.flv
  
 
4 Creating Video Directories
 
  
In this tutorial I'm assuming that your lighttpd document root for your video web site is /var/www (the default document root for lighttpd on Ubuntu). Of course, we don't want to store the original videos and the FLV videos in the document root (or a subdirectory) to prevent that anyone can download them directly (if he knows the link). Therefore we create a directory for the original videos (e.g. /var/videos/incoming) and a directory for the FLV videos (e.g. /var/videos/flv) outside the document root:
+
==Konfigurasi Lighttpd==
  
mkdir -p /var/videos/incoming
+
Selanjutnya kita perlu membuka file konfigurasi /etc/lighttpd/lighttpd.conf, dan add/enable module mod_secdownload dan modul mod_flv_streaming. Penting untuk di perhatikan agar mod_secdownload di tulis sebelum mod_flv_streaming dalam urutan server.modules. Jika kita melakukannya terbalik, tampaknya akan menyebabkan video fast-forwarding di FlowPlayer tidak jalan.
mkdir -p /var/videos/flv
 
  
You (or your users) can then upload their original videos to /var/videos/incoming (e.g. through FTP or some web interface that you program), and you can then encode the videos to FLV (either manually or through some script), as shown in the next chapter.
+
vi /etc/lighttpd/lighttpd.conf
  
   
+
  [...]
5 Encoding Videos To FLV
+
server.modules              = (
 +
            "mod_access",
 +
            "mod_alias",
 +
            "mod_accesslog",
 +
            "mod_compress",
 +
#          "mod_rewrite",
 +
#          "mod_redirect",
 +
#          "mod_evhost",
 +
#          "mod_usertrack",
 +
#          "mod_rrdtool",
 +
#          "mod_webdav",
 +
#          "mod_expire",
 +
            "mod_secdownload",
 +
            "mod_flv_streaming",
 +
#          "mod_evasive"
 +
)
 +
[...]
  
Let's assume we have a video called video.avi in /var/videos/incoming (works for the extensions .mp4 .mov .mpg .3gp .mpeg .wmv as well). We want to convert it to the file video.flv and store it in the directory /var/videos/flv. I want video.flv to have a size of 320x240 pixels with an audio sampling frequency of 44100 Hz, two audio channels (stereo), and a frame rate of 12 fps. This is how we do it:
+
Di file yang sama, kita dapat menambahkan konfigurasi berikut di akhir file /etc/lighttpd/lighttpd.conf:
  
ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 -ac 2 /var/videos/flv/video.flv
+
[...]
 +
flv-streaming.extensions = ( ".flv" )
 +
secdownload.secret          = "somesecret"
 +
secdownload.document-root  = "/var/videos/flv/"
 +
secdownload.uri-prefix      = "/dl/"
 +
secdownload.timeout        = 120
  
(For more options, take a look at
+
Kita dapat mengganti somesecret dengan password yang kita inginkan.
  
man ffmpeg
+
Modul mod_secdownload akan melakukan hal berikut:
  
)
+
Sebuah aplikasi web misalnya sebuah PHP script dengan link dengan format sebagai berikut
  
This can take some time, and the output should look something like this:
+
<uri-prefix>/<token>/<timestamp-in-hex>/<rel-path>
  
root@server1:~# ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 -ac 2 /var/videos/flv/video.flv
+
contoh
FFmpeg version SVN-r13582, Copyright (c) 2000-2008 Fabrice Bellard, et al.
 
  configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --bindir=${prefix}/bin --incdir=${prefix}/include/ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-libamr-nb --enable-libamr-wb --enable-x11grab --enable-libgsm --enable-libx264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscale --enable-libdc1394 --enable-nonfree --disable-mmx --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
 
  libavutil version: 49.7.0
 
  libavcodec version: 51.58.0
 
  libavformat version: 52.16.0
 
  libavdevice version: 52.0.0
 
  libavfilter version: 0.0.0
 
  built on May  3 2009 12:07:18, gcc: 4.3.2
 
Input #0, avi, from '/var/videos/incoming/video.avi':
 
  Duration: 00:10:53.82, start: 0.000000, bitrate: 5455 kb/s
 
    Stream #0.0: Video: mpeg4, yuv420p, 1024x576 [PAR 1:1 DAR 16:9], 24.00 tb(r)
 
    Stream #0.1: Audio: ac3, 48000 Hz, 5:1, 448 kb/s
 
Output #0, flv, to '/var/videos/flv/video.flv':
 
    Stream #0.0: Video: flv, yuv420p, 320x240 [PAR 4:3 DAR 16:9], q=2-31, 200 kb/s, 12.00 tb(c)
 
    Stream #0.1: Audio: libmp3lame, 44100 Hz, stereo, 64 kb/s
 
Stream mapping:
 
  Stream #0.0 -> #0.0
 
  Stream #0.1 -> #0.1
 
Press [q] to stop encoding
 
[libmp3lame @ 0x7f983556f6c0]lame: output buffer too small (buffer index: 8359, free bytes: 281)
 
frame= 7847 fps= 13 q=2.0 Lsize=  21696kB time=653.92 bitrate= 271.8kbits/s
 
video:16067kB audio:5114kB global headers:0kB muxing overhead 2.428783%
 
root@server1:~#
 
  
Please make sure that in the Output section, you see two streams, one for video, one for audio. If you see video only, this means that the sound gets lost.
+
/dl/d8a8cb150f7e5962f6a8443b0b6c6cc2/46c1d9f6/video.flv
  
After the conversion, we can now add metadata to video.flv with flvtool2:
+
Dimana <token> adalah MD5 dari
  
cat /var/videos/flv/video.flv | flvtool2 -U stdin /var/videos/flv/video.flv
+
# password (yang diberikan user)
 +
# <rel-path> (start dengan /)
 +
# <timestamp-in-hex>
  
6 Configuring Lighttpd
+
mod_secdownload akan memetakan link tersebut ke file yang benar di secdownload.document-root (yang berada di luar document root dari web) dan mengijinkan akses ke file tersebut untuk secdownload.timeout detik. Setelah secdownload.timeout detik, link tersebut menjadi tidak valid, akses akan di tolak.
 
  
Now we have to open lighttpd's main configuration file, /etc/lighttpd/lighttpd.conf, and add/enable the modules mod_secdownload and mod_flv_streaming in it. It is very important that mod_secdownload is listed before mod_flv_streaming in the server.modules stanza. When I did it the other way round, I found that fast-forwarding the video in FlowPlayer didn't work!
+
Setelah kita menginstalasi FlowPlayer, kita akan menggunakan PHP script untuk menghasilkan video link yang benar untuk mod_secdownload.
  
vi /etc/lighttpd/lighttpd.conf
+
Kita dapat memperoleh informasi tentang mod_secdownload di http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload
  
[...]
+
Jangan lupa untuk me-restart lighttpd sesudah kita melakukan perubahan di /etc/lighttpd/lighttpd.conf:
server.modules              = (
 
            "mod_access",
 
            "mod_alias",
 
            "mod_accesslog",
 
            "mod_compress",
 
#          "mod_rewrite",
 
#          "mod_redirect",
 
#          "mod_evhost",
 
#          "mod_usertrack",
 
#          "mod_rrdtool",
 
#          "mod_webdav",
 
#          "mod_expire",
 
            "mod_secdownload",
 
            "mod_flv_streaming",
 
#          "mod_evasive"
 
)
 
[...]
 
  
In the same file, we add also add the following configuration (you can add it right at the end of /etc/lighttpd/lighttpd.conf):
+
/etc/init.d/lighttpd restart
  
[...]
+
flv-streaming.extensions = ( ".flv" )
+
==Instalasi FlowPlayer==
secdownload.secret          = "somesecret"
 
secdownload.document-root  = "/var/videos/flv/"
 
secdownload.uri-prefix      = "/dl/"
 
secdownload.timeout        = 120
 
  
Please replace somesecret with your own secret string (you can choose one).
+
Ambil FlowPlayer
  
What mod_secdownload does is this: a web application (e.g. a PHP script) can have a link in it of the following form:
+
* http://releases.flowplayer.org/flowplayer/flowplayer-3.2.7.zip
 +
* http://releases.flowplayer.org/flowplayer/flowplayer-3.2.7-src.zip - [[source code]] jika dibutuhkan
  
<uri-prefix>/<token>/<timestamp-in-hex>/<rel-path>
+
Go to http://flowplayer.org/download and download the latest FlowPlayer version to your /tmp directory, e.g. like this:
  
e.g.
+
apt-get install unzip
 +
cp flowplayer-3.2.7.zip /usr/local/src
 +
cd /usr/local/src
 +
unzip flowplayer-3.2.7.zip
 +
mv flowplayer /var/www/
  
/dl/d8a8cb150f7e5962f6a8443b0b6c6cc2/46c1d9f6/video.flv
 
  
where <token> is an MD5 of
+
==Konfigurasi FlowPlayer==
  
  1. a secret string (user supplied)
+
FlowPlayer telah di instalasi, selanjutnya kita perlu membuat file HTML yang memungkinkan kita  untuk melihat video. Kita akan membuat file PHP sederhana dengan nama /var/www/flowplayertest.php yang berisis semua parameter untuk menjalankan FlowPlayer di browser dan membuat video link yang benar untuk mod_secdownload:
  2. <rel-path> (starts with /)
 
  3. <timestamp-in-hex>
 
  
mod_secdownload will then map this link to the appropriate file in the secdownload.document-root (which is outside the document root of the web site) and allow access to that file for secdownload.timeout seconds. After secdownload.timeout seconds, the link isn't valid anymore, and access is denied.
+
vi /var/www/flowplayertest.php
  
After we have installed FlowPlayer, we will use a PHP script to generate the appropriate video links for mod_secdownload.
+
isi dengan
 
 
You can find more information about mod_secdownload here: http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload
 
 
 
Don't forget to restart lighttpd after your changes to /etc/lighttpd/lighttpd.conf:
 
 
 
/etc/init.d/lighttpd restart
 
  
 +
<?php
 +
 +
$secret = "somesecret";
 +
$uri_prefix = "/dl/";
 +
 +
# filename
 +
$f = "/video.flv";
 +
 +
# current timestamp
 +
$t = time();
 +
 +
$t_hex = sprintf("%08x", $t);
 +
$m = md5($secret.$f.$t_hex);
 +
 +
?>
 +
 +
<html>
 +
<head>
 +
<title>Flowplayer Test</title>
 +
 +
<script src="/flowplayer/example/flowplayer-3.2.6.min.js"></script>
 +
 +
</head>
 +
<body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
 +
 +
<a
 +
    href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
 +
    style="display:block;width:320px;height:256px;"
 +
    id="player">
 +
</a>
 
   
 
   
7 Installing FlowPlayer
+
<script language="JavaScript">
 
+
flowplayer("player", "/flowplayer/flowplayer-3.2.7.swf");
Go to http://flowplayer.org/download and download the latest FlowPlayer version to your /tmp directory, e.g. like this:
+
</script>
 
 
cd /tmp
 
wget http://releases.flowplayer.org/flowplayer/flowplayer-3.1.5.zip
 
 
 
FlowPlayer comes in .zip format, so we must install unzip to uncompress it:
 
 
 
aptitude install unzip
 
 
 
Afterwards we can uncompress it:
 
 
 
unzip flowplayer-3.1.5.zip
 
 
 
This creates a directory called flowplayer in the /tmp directory. I'd like to have that directory in the document root of my video web site (/var/www), so I move it there:
 
 
 
mv flowplayer /var/www/
 
 
 
 
   
 
   
8 Configuring FlowPlayer
+
</body>
 +
</html>
  
FlowPlayer is now installed, so all that is left to do is create an HTML file that lets us watch our video. I will create a PHP file for this called /var/www/flowplayertest.php which contains all parameters to start FlowPlayer in the user's browser and which also creates valid video links for mod_secdownload:
+
Penting untuk memastikan bahwa nilai $secret sama dengan secdownload.secret di /etc/lighttpd/lighttpd.conf. Juga $uri_prefix dan secdownload.uri-prefix harus sama. Jika ini di penuhi, script di atas akan menghasilkan link yang benar. $f harus mempunyai nama file FLV video, di mulai dengan (/). (Dalam contoh di atas filename dibuat hard-coded, tentunya kita dapat dengan mudah membuatnya dinamik).
  
vi /var/www/flowplayertest.php
+
Bagian penting yang memanggil FlowPlayer adalah <script src="/flowplayer/example/flowplayer-3.2.6.min.js"></script> (yang mengacu pada script flowplayer-3.2.6.min.js di directory /var/www/flowplayer/example) di bagian <head></head> dan dua bagian <body></body>:
  
<?php
+
<a
 +
    href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
 +
    style="display:block;width:320px;height:256px;"
 +
    id="player">
 +
</a>
  
$secret = "somesecret";
+
Bagian terpenting adalah parameter href yang di set pada script PHP di atas yang menentukan path ke file video FLV. Pada parameter style, kita dapat menset lebar dan tinggi layar video player.
$uri_prefix = "/dl/";
 
  
# filename
+
dan
$f = "/video.flv";
 
  
# current timestamp
+
<script language="JavaScript">
$t = time();
+
flowplayer("player", "/flowplayer/flowplayer-3.1.5.swf");
 +
</script>
  
$t_hex = sprintf("%08x", $t);
+
Disini kita menset path ke file FlowPlayer .swf
$m = md5($secret.$f.$t_hex);
 
  
?>
+
Ubah owner & permission
<html>
 
<head>
 
<title>Flowplayer Test</title>
 
  
<script src="/flowplayer/example/flowplayer-3.1.4.min.js"></script>
+
chown -Rf www-data.www-data /var/www
 +
chown -Rf www-data.www-data /var/videos
 +
chmod -Rf 777 /var/www
 +
chmod -Rf 777 /var/videos
  
</head>
+
Konfigurasi FlowPlayer ini di ambil dari http://flowplayer.org/demos/installation/index.html. Untuk mempelajari lebih lanjut bagaimana cara memanggil FlowPlayer ada baiknya melihat-lihat contoh di http://flowplayer.org/demos/index.html.
<body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
 
  
<a
+
Sekarag mari kita test setup yang telah kita lakukan. Akses ke alamat http://192.168.0.9/flowplayertest.php atau http://server1.example.com/flowplayertest.php, video anda harusnya start di browser:
    href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
 
    style="display:block;width:320px;height:256px;"
 
    id="player">
 
</a>
 
  
<script language="JavaScript">
+
Click to enlarge
flowplayer("player", "/flowplayer/flowplayer-3.1.5.swf");
 
</script>
 
  
</body>
+
Berikut adalah tampilan native Flash 9 pada mode full screen:
</html>
 
 
 
It's very important that $secret has the same value than secdownload.secret in /etc/lighttpd/lighttpd.conf. Also, $uri_prefix and secdownload.uri-prefix must match. If this is fulfilled, the above script will generate valid links. $f must hold the filename of the FLV video, beginning with a slash (/). (The filename is hard-coded in the above example, but of course you can program whatever you like to dynamically generate the filename.)
 
 
 
The important parts that call FlowPlayer are <script src="/flowplayer/example/flowplayer-3.1.4.min.js"></script> (which refers to the flowplayer-3.1.4.min.js script in the /var/www/flowplayer/example directory) in the <head></head> section and the following two parts in the <body></body> section:
 
 
 
<a
 
    href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
 
    style="display:block;width:320px;height:256px;"
 
    id="player">
 
</a>
 
 
 
(The most important setting is the href parameter (which is set by PHP in the above script) which specifies the path to the FLV video. In the style parameter, we can specify the width and height of our video player.)
 
 
 
and
 
 
 
<script language="JavaScript">
 
flowplayer("player", "/flowplayer/flowplayer-3.1.5.swf");
 
</script>
 
 
 
(Here we specify the path to our FlowPlayer .swf file.)
 
 
 
This FlowPlayer configuration is taken from http://flowplayer.org/demos/installation/index.html.
 
 
 
To learn more about other ways of calling FlowPlayer and how to call it with specific settings, take a look at the examples on http://flowplayer.org/demos/index.html.
 
 
 
Now it's time to test our setup. Direct your browser to http://192.168.0.100/flowplayertest.php or http://server1.example.com/flowplayertest.php, and your video should start to play in your browser (including sound):
 
 
 
Click to enlarge
 
 
 
This is how the native Flash 9 full screen mode looks:
 
 
 
Click to enlarge
 
 
 
 
9 Links
 
 
 
    * Lighttpd: http://www.lighttpd.net/
 
    * mod_flv_streaming: http://blog.lighttpd.net/articles/2006/03/09/flv-streaming-with-lighttpd
 
    * mod_secdownload: http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload
 
    * FlowPlayer: http://flowplayer.org/
 
    * ffmpeg: http://ffmpeg.mplayerhq.hu/
 
    * flvtool2: http://rubyforge.org/projects/flvtool2/
 
    * PHP: http://www.php.net/
 
    * Ubuntu: http://www.ubuntu.com/
 
  
 +
Click to enlarge
  
 +
==Referensi==
  
 +
* http://flowplayer.org/demos/installation/index.html.
 +
* Lighttpd: http://www.lighttpd.net/
 +
* mod_flv_streaming: http://blog.lighttpd.net/articles/2006/03/09/flv-streaming-with-lighttpd
 +
* mod_secdownload: http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload
 +
* FlowPlayer: http://flowplayer.org/
 +
* ffmpeg: http://ffmpeg.mplayerhq.hu/
 +
* flvtool2: http://rubyforge.org/projects/flvtool2/
 +
* PHP: http://www.php.net/
 +
* Ubuntu: http://www.ubuntu.com/
  
 
==Referensi==
 
==Referensi==
  
 
* http://www.howtoforge.com/build-your-own-video-community-with-lighttpd-and-flowplayer-ubuntu-9.10
 
* http://www.howtoforge.com/build-your-own-video-community-with-lighttpd-and-flowplayer-ubuntu-9.10
 +
* http://flowplayer.org/forum/5/14679
 +
* http://flowplayer.org/download/
 +
* http://flowplayer.org/
  
 
==Pranala Menarik==
 
==Pranala Menarik==
  
 +
* [[Membuat Sendiri TV Internet]]
 +
* [[Flowplayer]]
 +
* [[Instalasi Lighttpd]]
 +
* [[Flowplayer: Contoh BBCode]]
 +
* [[Flowplayer: Download]]
 +
* [[Flowplayer: Instalasi]]
 +
* [[Flowplayer: streamer php]]
 +
* [[Flowplayer: Konfigurasi]]
 
* [[Multimedia di Linux]]
 
* [[Multimedia di Linux]]
  
 
[[Category: Linux]]
 
[[Category: Linux]]
 
[[Category: Multimedia]]
 
[[Category: Multimedia]]

Latest revision as of 11:44, 7 April 2011

Sumber: http://www.howtoforge.com/build-your-own-video-community-with-lighttpd-and-flowplayer-ubuntu-9.10

Tulisan ini menjelaskan bagaimana kita dapat membuat sendiri streaming video komunitas menggunakan lighttpd menggunakan modul streaming mod_flv_streaming (untuk streaming video .flv, format yang digunakan oleh banyak video streaming komunitas seperti YouTube) dan modul mod_secdownload (untuk menghalangi hotlinking dari video) di Ubuntu. Kita akan menggunakan FlowPlayer video player, sebuah Flash video player yang mendukung modul lighttpd mod_flv_streaming. Kita juga akan memperlihatkan bagaimana meng-encode video (.mp4 .mov .mpg .3gp .mpeg .wmv .avi) ke format FLV yang di dukung oleh Adobe Flash.


Beberapa Catatan Awal

Dalam tutorial ini akan digunakan

hostname  server1.example.com
IP Address 192.168.0.9

Cara instalasi lighttpd di terangkan di

Kita menjalankan semua perintah di bawah sebagai root. Pastikan anda login sebagai root melalui perintah

sudo su


Instalasi

Instalasi menggunakan perintah

apt-get install ffmpeg flvtool2


Buat Directory untuk menyimpan video

Misalnya

mkdir -p /var/videos/incoming
mkdir -p /var/videos/flv


Encode Video menjadi FLV

Berikut akan di contohkan konversi video.avi di /var/videos/incoming (cara yang sama sebetulnya dapat juga dilakukan untuk extension .mp4 .mov .mpg .3gp .mpeg .wmv). Kita kan mengkonversikan file tersebut menjadi video.flv dan menyimpannya di directory /var/videos/flv. File video.flv dibuat untuk pixel 320x240 dengan frekuensi audio sampling 44100 Hz, dua kanal audio (stereo), dengan frame rate 12 fps. Caranya adalah sebagai berikut:

ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 -ac 2 /var/videos/flv/video.flv

Untuk melihat pilihan yang lain ada baiknya melihat perintah

man ffmpeg

Proses ini akan memerlukan beberapa waktu, keluaran / outputnya adalah sebagai berikut:

root@server1:~# ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 -ac 2 /var/videos/flv/video.flv
FFmpeg version SVN-r13582, Copyright (c) 2000-2008 Fabrice Bellard, et al.
  configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --bindir=${prefix}/bin --incdir=${prefix}/include /ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-libamr-nb --enable-libamr-wb --enable-x11grab --enable-libgsm --enable-libx264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscale --enable-libdc1394 --enable-nonfree --disable-mmx --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libschroedinger --disable-encoder=libschroedinger --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
  libavutil version: 49.7.0
  libavcodec version: 51.58.0
  libavformat version: 52.16.0
  libavdevice version: 52.0.0
  libavfilter version: 0.0.0
  built on May  3 2009 12:07:18, gcc: 4.3.2
Input #0, avi, from '/var/videos/incoming/video.avi':
  Duration: 00:10:53.82, start: 0.000000, bitrate: 5455 kb/s
    Stream #0.0: Video: mpeg4, yuv420p, 1024x576 [PAR 1:1 DAR 16:9], 24.00 tb(r)
    Stream #0.1: Audio: ac3, 48000 Hz, 5:1, 448 kb/s
Output #0, flv, to '/var/videos/flv/video.flv':
    Stream #0.0: Video: flv, yuv420p, 320x240 [PAR 4:3 DAR 16:9], q=2-31, 200 kb/s, 12.00 tb(c)
    Stream #0.1: Audio: libmp3lame, 44100 Hz, stereo, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Press [q] to stop encoding
[libmp3lame @ 0x7f983556f6c0]lame: output buffer too small (buffer index: 8359, free bytes: 281)
frame= 7847 fps= 13 q=2.0 Lsize=   21696kB time=653.92 bitrate= 271.8kbits/s
video:16067kB audio:5114kB global headers:0kB muxing overhead 2.428783%
root@server1:~#

Pastikan pada bagian output, kita melihat dua stream, satu untuk video, satu untuk audio. Jika kita hanya melihat video saja, maka artinya suaranya hilang.

Setelah melalukan konversi kita dapat menambahkan metadata ke video.flv menggunakan flvtool2:

cat /var/videos/flv/video.flv | flvtool2 -U stdin /var/videos/flv/video.flv


Konfigurasi Lighttpd

Selanjutnya kita perlu membuka file konfigurasi /etc/lighttpd/lighttpd.conf, dan add/enable module mod_secdownload dan modul mod_flv_streaming. Penting untuk di perhatikan agar mod_secdownload di tulis sebelum mod_flv_streaming dalam urutan server.modules. Jika kita melakukannya terbalik, tampaknya akan menyebabkan video fast-forwarding di FlowPlayer tidak jalan.

vi /etc/lighttpd/lighttpd.conf
[...]
server.modules              = (
            "mod_access",
            "mod_alias",
            "mod_accesslog",
            "mod_compress",
#           "mod_rewrite",
#           "mod_redirect",
#           "mod_evhost",
#           "mod_usertrack",
#           "mod_rrdtool",
#           "mod_webdav",
#           "mod_expire",
            "mod_secdownload",
            "mod_flv_streaming",
#           "mod_evasive"
)
[...]

Di file yang sama, kita dapat menambahkan konfigurasi berikut di akhir file /etc/lighttpd/lighttpd.conf:

[...]
flv-streaming.extensions = ( ".flv" )
secdownload.secret          = "somesecret"
secdownload.document-root   = "/var/videos/flv/"
secdownload.uri-prefix      = "/dl/"
secdownload.timeout         = 120 

Kita dapat mengganti somesecret dengan password yang kita inginkan.

Modul mod_secdownload akan melakukan hal berikut:

Sebuah aplikasi web misalnya sebuah PHP script dengan link dengan format sebagai berikut

<uri-prefix>/<token>/<timestamp-in-hex>/<rel-path>

contoh

/dl/d8a8cb150f7e5962f6a8443b0b6c6cc2/46c1d9f6/video.flv

Dimana <token> adalah MD5 dari

  1. password (yang diberikan user)
  2. <rel-path> (start dengan /)
  3. <timestamp-in-hex>

mod_secdownload akan memetakan link tersebut ke file yang benar di secdownload.document-root (yang berada di luar document root dari web) dan mengijinkan akses ke file tersebut untuk secdownload.timeout detik. Setelah secdownload.timeout detik, link tersebut menjadi tidak valid, akses akan di tolak.

Setelah kita menginstalasi FlowPlayer, kita akan menggunakan PHP script untuk menghasilkan video link yang benar untuk mod_secdownload.

Kita dapat memperoleh informasi tentang mod_secdownload di http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload

Jangan lupa untuk me-restart lighttpd sesudah kita melakukan perubahan di /etc/lighttpd/lighttpd.conf:

/etc/init.d/lighttpd restart


Instalasi FlowPlayer

Ambil FlowPlayer

Go to http://flowplayer.org/download and download the latest FlowPlayer version to your /tmp directory, e.g. like this:

apt-get install unzip
cp flowplayer-3.2.7.zip /usr/local/src
cd /usr/local/src
unzip flowplayer-3.2.7.zip
mv flowplayer /var/www/


Konfigurasi FlowPlayer

FlowPlayer telah di instalasi, selanjutnya kita perlu membuat file HTML yang memungkinkan kita untuk melihat video. Kita akan membuat file PHP sederhana dengan nama /var/www/flowplayertest.php yang berisis semua parameter untuk menjalankan FlowPlayer di browser dan membuat video link yang benar untuk mod_secdownload:

vi /var/www/flowplayertest.php

isi dengan

<?php

$secret = "somesecret";
$uri_prefix = "/dl/";

# filename
$f = "/video.flv";

# current timestamp
$t = time();

$t_hex = sprintf("%08x", $t);
$m = md5($secret.$f.$t_hex);

?>

<html>
<head>
<title>Flowplayer Test</title>

<script src="/flowplayer/example/flowplayer-3.2.6.min.js"></script> 

</head>
<body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">

<a
    href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
    style="display:block;width:320px;height:256px;"
    id="player">
</a> 

<script language="JavaScript">
flowplayer("player", "/flowplayer/flowplayer-3.2.7.swf");
</script>

</body>
</html>

Penting untuk memastikan bahwa nilai $secret sama dengan secdownload.secret di /etc/lighttpd/lighttpd.conf. Juga $uri_prefix dan secdownload.uri-prefix harus sama. Jika ini di penuhi, script di atas akan menghasilkan link yang benar. $f harus mempunyai nama file FLV video, di mulai dengan (/). (Dalam contoh di atas filename dibuat hard-coded, tentunya kita dapat dengan mudah membuatnya dinamik).

Bagian penting yang memanggil FlowPlayer adalah <script src="/flowplayer/example/flowplayer-3.2.6.min.js"></script> (yang mengacu pada script flowplayer-3.2.6.min.js di directory /var/www/flowplayer/example) di bagian <head></head> dan dua bagian <body></body>:

<a
    href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
    style="display:block;width:320px;height:256px;"
    id="player">
</a>

Bagian terpenting adalah parameter href yang di set pada script PHP di atas yang menentukan path ke file video FLV. Pada parameter style, kita dapat menset lebar dan tinggi layar video player.

dan

<script language="JavaScript">
flowplayer("player", "/flowplayer/flowplayer-3.1.5.swf");
</script>

Disini kita menset path ke file FlowPlayer .swf

Ubah owner & permission

chown -Rf www-data.www-data /var/www
chown -Rf www-data.www-data /var/videos
chmod -Rf 777 /var/www
chmod -Rf 777 /var/videos

Konfigurasi FlowPlayer ini di ambil dari http://flowplayer.org/demos/installation/index.html. Untuk mempelajari lebih lanjut bagaimana cara memanggil FlowPlayer ada baiknya melihat-lihat contoh di http://flowplayer.org/demos/index.html.

Sekarag mari kita test setup yang telah kita lakukan. Akses ke alamat http://192.168.0.9/flowplayertest.php atau http://server1.example.com/flowplayertest.php, video anda harusnya start di browser:

Click to enlarge

Berikut adalah tampilan native Flash 9 pada mode full screen:

Click to enlarge

Referensi

Referensi

Pranala Menarik