Setting up Cakephp for Application Development
Posted on | July 5, 2009 | No Comments
I like to keep the CAKPHP ROOT files (/cake/) in a folder of its own and my /app in the working folders. This way, the CAKEPHP ROOT files are not SVNed and that keeps my repos smaller.
My folder structure:
D:\www\cakephp_1_2
D:\www\video_tutorial\app
D:\www\video_tutorial\vendors
D:\www\project 1\app
D:\www\project 1\vendors
All my vendors files for all projects are stored in D:\www\cakephp_1_2\vendors. If it is project specific, it goes to the project’s own folder.
In the project’s folder, index.php in webroot folder, change the CAKE_CORE_INCLUDE_PATH constant to allow the app to locate the CAKEPHP ROOT files and include them.
D:\www\video_tutorial\app\webroot\index.php
/**
* The full path to the directory which holds "app", WITHOUT a trailing DS.
*
*/
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(dirname(__FILE__)))));
}
/**
* The actual directory name for the "app".
*
*/
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(dirname(__FILE__)))).DS.'app');
}
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT.DS.'cakephp_1_2');
}
Video Sharing Website Part 2 : Converting the uploaded video to FLV
Posted on | June 30, 2009 | 2 Comments
This series of blog post will talk about how to setup a Video Sharing Website.
Converting the uploaded video to FLV
This is a ‘on the fly’ conversion example, using Cakephp Framework. I am using the ffmpeg library for the transcoding in my example. The ffmpeg converter supports FLV, MP4 and many more.
ffmpeg supported formats: http://ffmpeg.org/general.html#SEC8
For the most basic video sharing, the user will upload a video, enter a title and a description. The VideoConvertorComponent will take the uploaded video, extract a thumbnail and convert it to FLV. Other users can view the FLV in the flash player.
VideoConvertorComponent:: flv_import() is called in the controller. FLV and thumbnail image is created.
Video Sharing Website Part 1 : Introduction to Video Streaming
Posted on | June 30, 2009 | 1 Comment
This series of blog post will talk about how to setup a Video Sharing Website.
Definition to various methods of video downloads and video format
- Streaming
- HTTP Download
- HTTP Streaming – A combination of Streaming and HTTP Download
Streaming
Use of Video Stream Application servers. Examples of Video Stream Application servers include: Video Desk, Adobe Flash Media Server. To use a Streaming Application Server, you need to have a dedicated server with dedicated bandwidth. Such setups are expensive and can run up to a few thousand dollars per month. This is not for the average user. But more suited for the needs of content delivery network. Like news streaming, on demand TV or Movies. Requires a lot of specialized server setup and maintenance knowledge.
HTTP Download
The usual way files are downloaded completely before you can view them. Longer waiting time. This method would require user to have the plugin that supports the playback installed.
HTTP Streaming
A flash player will play part of the video when it is downloaded. With this method, you can fast forward to any segment you want to watch before the video is downloaded fully. The player will send a request to the server for the seeked segment of the video and the start playing from there. This is call pseudo streaming.
This streaming setup uses three components:
- A Flash Player
- A server side script for the transcoding of uploaded video to different formats, and the pseudo streaming of the video
- An FLV video
The server side script needs to take care of bandwidth throttling, securing the video to prevent leeching, detection of bandwidth to if variable bandwidth video is supported. This will be covered in further posts.
Video Formats Suitable for Online Stream
- FLV (H.263/MP3) – 320px in width
- MP4 (H.264/AAC) – 320px in width ~500kbps
- A TV conversion (720px wide, H.264/AAC, ~1000kbps)
- An HD conversion (1280px wide, H.264/AAC, ~2000kbps)
Higher bitrates or bigger file size will result in longer transcoding time. Since this is the case, the transcoding process has to be ‘behind the scenes’ to avoid letting users wait for a long time. The FLV version is the most commonly used format.
Network Architecture

New Release : CakePHP 1.2.3.8166
Posted on | May 6, 2009 | No Comments
CakePHP 1.2.3.8166 is out.
Important Security Fix.
See http://bakery.cakephp.org/articles/view/release-cakephp-1-2-3-8166
Rounding down to the nearest $0.05
Posted on | February 9, 2009 | No Comments
Updated: Found a shortcut to round down to the nearest $0.05.
round(20 * $amount, 0) / 20 will give you the amount round to the nearest $0.05
More rounding functions can be found at Microsoft Access tips: Rounding numbers in Access.
Singapore has decided not to mint anymore 1 cent coins. Likely the reason is because minting 1 cent coins is more costly than the surface value of the coin. So what happen when we have to pay for something costing $1.09? It is round down to nearest 5 cents. $1.05 should be tendered. What about $1.04? It should be rounded down to $1.00
This is how it will be calculated in PHP.
<?php
$amount_due = $payment['Payment']['amount'] + $payment['Payment']['gst'];
$rounded = round($amount_due, 1) - round($amount_due, 2);
if($rounded > 0.05) {
$amount_due = $amount_due - ($rounded - 0.05);
}
if($rounded > 0.01 &amp;&amp; $rounded < 0.05) {
$amount_due = $amount_due - ($rounded);
}
$round_down = $rounded - 0.05;
echo $number->currency($round_down, '$')
?>
This is just the calculation process if I would to do it mentally, it is NOT tested for all possible mathematical errors. Note that I am not an accountant




















