I had a problem where my mp4 videos were not played by video.js player until the video was fully downloaded by the browser. after some searching I found out it was because mp4 file metadata ( moov atom) is on the end of the file and the player cannot locate it for streaming when initially played.
I was saved by this small php library http://code.google.com/p/moovrelocator/
This will read a video and move MOOV-Atom to the front of the mp4 file.
there is a demo in _demo folder. if you get errors finding the paths, try giving direct paths like this in index.php
$inFile = '../../videos/'.$tempv;
// output (processed file)
$outFile = '../../new_videos/'.$tempv;
if you get zend errors try giving direct paths in Moovrelocator.class.php
// atom poc class
require_once 'atom/Atom.class.php';
// bytearray to operate direct on bytes in memory just to simulate Adobe's AS3 Bytearray
require_once 'bytes/Bytearray.class.php';
// transform (taken from php-reader)
require_once 'bytes/Transform.class.php';
you may also want to change your php.ini max execute time and memory use if you are looping through lot of videos in a folder.
Monday, April 1, 2013
Sunday, October 28, 2012
php file upload error messages in a php array
Hope this will be useful to someone, all the php file upload error codes and messages in an array.
<?php $error_codes = array( 0=>"There is no error, the file uploaded with success", 1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini", 2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 3=>"The uploaded file was only partially uploaded", 4=>"No file was uploaded", 6=>"Missing a temporary folder", 7=>"Failed to write file to disk", 8=>"A PHP extension stopped the file upload" ); /* Posssible Usage */ if($_FILES["userfile"]["error"] > 0){ $code = $_FILES["userfile"]["error"]; echo $error_codes[$code]; } else{ //do the processing } ?>
Tuesday, October 23, 2012
How to change default timezone in Ubuntu command-line
In a Ubuntu / Debian based Linux system you can use the following command to run the timezone setup to change the default timezone
dpkg-reconfigure tzdata
Monday, October 22, 2012
High Swapping On Linode 512 - KeepAliveTimeout
I thought of sharing my experience on handling the high swapping issue I faced recently. There is nothing wrong with Linode service, its just my dumb Apache configurations.
Linode is a great hosting service but for a Linux administration newbie it can be a challenging place.
Swapping problem was a nightmare, I tried adding another 512MB to the Linode box and still it goes into full swap. Then I get to know about the Apache KeepAliveTimeout.
KeepAliveTimeout - Amount of time the server will wait for subsequent requests on a persistent connection.
Unfortunately for me the default value was 15 which is a super high value. After changing the value to 4 all was smooth again.
Swapping can occur for many reasons like bad scripting but KeepAliveTimeout value can be a main suspect :)
Linode is a great hosting service but for a Linux administration newbie it can be a challenging place.
Swapping problem was a nightmare, I tried adding another 512MB to the Linode box and still it goes into full swap. Then I get to know about the Apache KeepAliveTimeout.
KeepAliveTimeout - Amount of time the server will wait for subsequent requests on a persistent connection.
Unfortunately for me the default value was 15 which is a super high value. After changing the value to 4 all was smooth again.
Swapping can occur for many reasons like bad scripting but KeepAliveTimeout value can be a main suspect :)
Tuesday, October 16, 2012
How to check and fix Domain Canonicalization (www)
It's a common configuration in web servers to point both urls of www.example.com and example.com to same content. This is a bad practice in terms of SEO because they regarded as duplicate content. If you have access to the .htaccess and assuming your Apache server has mod_rewrite enabled, you can add following lines to redirect traffic and issue a 301 (Moved Permanently).
I prefer my site addresses without www
If you like to have your addresses with www use the following
If you have any sub domains like blog.example.com do not use the above code.
I prefer my site addresses without www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
If you like to have your addresses with www use the following
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
If you have any sub domains like blog.example.com do not use the above code.
Tuesday, August 7, 2012
How to find MPM mode of Apache - Prefork or Worker
to find the Apache MPM mode you can simply run following command.
in Ubuntu u can try
in CentOS type of linux u can try
in Ubuntu u can try
apache2 -V
in CentOS type of linux u can try
httpd -V
Thursday, February 10, 2011
How to fix gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
Sometimes php will through a error when using the imagecreatefromjpeg() for some jpge images saved by cameras and photo editing softwares. When I search the internet for a solution I found this great article which fix the problem http://worcesterwideweb.com/2008/03/17/php-5-and-imagecreatefromjpeg-recoverable-error-premature-end-of-jpeg-file/
Thursday, January 13, 2011
How to loop A-Z in php
Just like counting numbers :)
$letter = "A";
for($i = 1; $i<= 26; $i++)
{
$letter++;
echo $letter;
}
Subscribe to:
Posts (Atom)