Encoding videos for streaming on an Android device

I’ve been getting random hickups in playback when including a video in a webview on Android Kitkat (4.4.4). So I’ve been on this issue for quite some time now and couldn’t figure out why I was getting these messages in the verbose logcat: 2987-2998/com.xxx W/MediaPlayer﹕ info/warning (703, 38137) 2987-2987/com.xxx I/MediaPlayer﹕ Info (700,595) 2987-2998/com.xxx W/MediaPlayer﹕ info/warning (701, 0) 2987-2998/com.xxx W/MediaPlayer﹕ info/warning (702, 0) Especially the 700 error was what I focused on, cause it made no sense really. I’ve used Handbrake to encode the videos and selected the “android” preset. Unfortunately they’ve set the profile to ‘main’ instead of the suggested ‘baseline’ profile which is recommended. Took me a while to figure this out and including a lot of trial and error =/ Working now, anyways. Read more on the optimal settings here….

Serving files with access control (Apache/PHP)

When serving files over PHP often people end up using an incorrect implementation which is open to attacks or has really bad performance (especially with big files). Well you shouldn’t reinvent the wheel every time! When you are using Apache in the first place, why do you need to re-implement the feature, that Apache is best at? To avoid having to deal with complicated RFCs for HTTP Ranges and Caching use the Apache Module called xsendfile. Some apt magic and you are up an running: apt-get install libapache2-mod-xsendfile service apache2 restart Then add this to your vhost configuration: XSendFile on XSendFilePath /var/atis/Storage All set! To send a file via. PHP simply do this: header(‘X-Sendfile: ‘ . $file); header(‘Content-Type: ‘ . contentType($file)); header(‘Content-Disposition: inline;’); (Make sure you have a function to determine the contenttype of your file)    

PHP: Dump _ALL_ the data to the browser

Sometimes its useful to show data received / processed through PHP in the browser for debugging purposes. Yes you can use Firebug or some of those fancy debugging classes, but maybe you just want to view that damn array quickly 🙂 Use this: function dumpMe($arr) { echo str_replace(array(“\n”, ‘ ‘), array(‘ ‘, ‘ ‘), print_r($arr, true)) . ‘ ‘; }  

PHPs http_response_code – 5.3 compatibility snippet

The Api of PHP just rocks, easy to use for the things you need. Sometime compatibility is an issue though. Many webhosters didn’t upgrade yet from 5.3 to anything reasonable, so I might as well keep this snippet here for future reference: if (!function_exists(‘http_response_code’)) { function http_response_code($newcode = NULL) { static $code = 200; if ($newcode !== NULL) { header(‘X-PHP-Response-Code: ‘ . $newcode, true, $newcode); if (!headers_sent()) { $code = $newcode; } } return $code; } }  

Better SPAM protection with Postfix

In order to use RBL lists on your postfix setup to block spam replace this line in main.cf: smtpd_sender_restrictions = check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf   with: smtpd_sender_restrictions = reject_rbl_client sbl-xbl.spamhaus.org, reject_rbl_client cbl.abuseat.org, reject_non_fqdn_sender, reject_unknown_sender_domain, check_sender_access mysql:/etc/postfix/mysql-virtual_sender.cf   You can copy and paste the line with any ISPConfig setup. If you don’t use mysql to authenticate your users then you might need to adapt parts of this setting.

Degeneration der Spieleindustrie

Seit Farmville auf Facebook haben Spiele mit der Pay2Win (oder auch Free2Play gennant) einen regelrechten Boom hingelegt. Man wird durch einen stetigen Fluss an Lob und Erfolgsgefühle dazu getrieben, weiter in ein Spiel mit echtem Geld zu investieren. Als erstes weit verbreitetes Spiel hat dies vor einigen Jahren Farmville gemacht. Durch geschicktes einsetzen von Sperrzeiten, welche mit Spielwährungen verkürzt oder gar entfernt werden konnten, schaffte man Reize Geld auszugeben. Dies war erstmalig so Erfolgreich, weil man ja bekanntlich “mit seinen Freunden gemeinsam” gespielt hat und somit des Nachbars Neid einen noch mehr befriedigt hat. Durch die Umwandlung von echtem Geld in Spielgeld den Bezug zur Wertigkeit. Dies haben bereits viele andere Anbieter von digitalen Gütern kapiert, wie etwa Microsoft in deren Xbox Universum. Vor allem junge Leute sind durch Virtuelle Währungen eher dazu verleitet dieses auszugeben. Am Ende des Tages ist es der Spieler der draufzahlt. Waren Spiele früher noch durch deren Spielkomplexität und nicht durch deren Aussehen erfolgreich, reicht es heute einen Vogel nur einfaches Clicken/Berühren fliegen zu lassen. Verglichen mit Spielen wie Eve Online oder den frühen RPG Spielen, sind die heutigen neuen Spiele darauf optimiert, ein stetiges Gefühl von Erfolg zu vermitteln.    Was erzielt man mit […]

PHP: File uploads fail without any error

When handling uploads with PHP often it can happen, that the $_FILES array is simply empty. This can occur when one of the following things is true: Check php.ini for file_uploads = On, post_max_size, and upload_max_file_size. Make sure you’re editing the correct php.ini – use phpinfo() to verify your settings. Make sure your FORM tag has the enctype=”multipart/form-data” attribute. Do not use javascript to disable your form file input field on form submission! Make sure your directory has read+write permissions set for the tmp and upload directories. Make sure your FORM tag has method=”POST”. GET requests do not support multipart/form-data uploads. Make sure your file destination and tmp/upload directories do not have spaces in them. Make sure all FORMs on your page have /FORM close tags. Make sure your file input tag has a NAME attribute. An ID attribute is NOT sufficient! ID attributes are for use in the DOM, not for POST payloads. Your /tmp folder is full Hope this helps!