Easily convert MKV to MP4 (or M4V) for Apple TV

I have posted about this before here but I have recently found a better way to do this involving a little mac application called ‘subler’. It doesn’t convert the mkv, but just converts non-standard audio (DTS/AC-3 etc) and then recombines (muxes) the original video with the converted audio and places it in an m4v (or mp4) container. This means it takes about 5% of the time that a full video conversion would take. YES!

It’s also free (well, distributed on a GNU GPL v2 license), it can be found on google code and the app is so easy to use AND it fetches meta data and thumbnails from an online database too!

Before starting encoding, open the settings to set up the audio conversion. I convert to iTunes so I ticked ‘AC-3 audio to AAC’, downmix audio to ‘Dolby Pro Logic’, and 128kbps.

Now simply open the MKV and it asks you which tracks you would like to use and add the video and at least one audio track (multiple audio tracks, subtitles and chapters are supported too) and then hit ok. Press shift-cmd-m and search for the meta data, add it, then it asks you to choose a thumbnail image (your iTunes library is gonna look great (not to mention scrolling though it on Apple TV).

Now (and this is great) you can add the process to a queue (option under the file menu) – you should select ‘Video-MPEG4′ and tick 64 bits chunk offset on the addto queue dialogue. Once complete, just drag it in to iTunes (you could place a folder action on the destination folder so that this happens automatically).

There is also a command line version of the app which you can script, say, when a new file is detected it will automatically convert it, so in theory everything would be automatic, but the last time I tried this I found the CLI didn’t fully support DTS audio conversion unlike the GUI version.

Posted from Coppull, England, United Kingdom.

Wake On LAN REST service with PHP script

Trying to perform remote Wake On Lan to multiple machines over the web can be difficult without an expensive router. THe BT Home Hub 3 only supports forwarding the ‘magic-packet’ used for WOL on port 9 to one machine on your network, so if you want to wake others, you often need to log in to an existing powered-on machine and then run a program within the local network to wake the other machine(s) over the LAN.

Here is a script I use on my server (it’s a low-power, intel atom server which I leave on most of the day) which creates a simple rest service that would allow a page, when called in a browser, to prompt my server to send a WOL packet to another machine on the local network and wake it up. So you can wake any other machine on your network from anywhere with an internet connection.


flush();
function WakeOnLan($addr, $mac,$socket_number) {
$addr_byte = explode(':', $mac);
$hw_addr = '';
for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
$msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
// send it to the broadcast address using UDP
// SQL_BROADCAST option isn't help!!
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($s == false) {
echo "Error creating socket!\n";
echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
return FALSE;
}
else {
// setting a broadcast option to socket:
$opt_ret = socket_set_option($s, 1, 6, TRUE);
if($opt_ret <0) {
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
return FALSE;
}
if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
echo "Magic Packet sent successfully!";
socket_close($s);
return TRUE;
}
else {
echo "Magic packet failed!";
return FALSE;
}

}
}
// Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
$socket_number = "9";
// MAC Address of the listening computer's network device
$mac_addy = "11:11:11:11:11:11";
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
//$ip_addy = gethostbyname("myhomeserver.dynamicdns.org");
$ip_addy = '192.168.1.1';

WakeOnLan($ip_addy, $mac_addy,$socket_number)

Just change the IP and Mac address variables in the script to those of your target machine and as long as WOL is set in the bios then it should boot.

I'm not sure if you need the IP address, but since it worked I didn't mess with it. I've checked and this also works fine with mamp on the mac. I also chose to put a test in my script so it listens for a query string parameter for a little added obfuscation. Of course, you could go further and expand the script with some authentication. You could also amend the http response to a json response if you were calling this Wake On Lan REST service from another web service and needed to push back the confirmation or any errors that occur.

Due credit for the script must go to [this site].

Contact Form Spam

Not seen that before: This morning I received some spam through a web page. However, this was contact form spam that was promoting software to spam contact forms. ffs… I suppose at least I’m convinced the product works, unlike most of the contact form spam I receive. Not sure I’ll be following it up though.

Posted from London, England, United Kingdom.

Mobile Friendly Sites = User Unfriendly

Many agencies love mobile ‘friendly’ sites because it’s another item to bill a client for. Personally, I can’t stand mobile versions of websites. Very few are done well and consumers don’t buy modern smartphones (with fully capable browsers) just to be redirected to a crippled, impotent, information-shy version of the web.

The worst and most frustrating experience is clicking on the deep link in an email or social media, only to be redirected to the home page of the mobile site with either crap search features and no clear path to the content you wanted, or where you have no idea of what it was that you were supposed to be looking at anyway.

Mobile friendly sites are not an extra or add on. If you are going to do it (and I don’t really see the point as most smart phones can render and zoom in to display the content if built properly) then it needs to be built in to the design from the start, with UX firmly at the core of the whole process.

Posted from London, England, United Kingdom.

Muxing MKV to MP4 file container without converting the video (for Apple / Samsung TV)

I was trying to find a way to easily get MKV’s on to my TV, either by converting them to MP4/M4v and putting them in iTunes and out via the Apple TV or by streaming them directly to my Samsung TV. I did find a pretty good solution to this… but I recently wrote a new post on an easier way to do this which also adds meta data and thumbnails (only for macs though): easily converting (muxing) MKV to MP4 with ‘Subler’.

Ok, so you could use handbrake to convert entire files (both the audio and video streams), but there will be some loss of quality and even with a fast machine this could take a while, use lots of power and may slow your machine down. Sucks if you have lots of files to convert…

Now, most MKV files come with DTS audio and this is not compatible with the built in media player of network connected Samsung TV’s – it won’t play when accessing the file over your home network (it will however play them off a locally attached USB stick – fickle!). The Apple TV also requires the audio to be of a different codec – you can not just swap to a compatible mp4/m4v file container.

So, a simple and FAST method to play these files via a Samsung TV or bung them in to iTunes so you can play them via an Apple TV: Download MP4tools 3 – it lets you passthrough the video file and transcode just the audio to either; 2 channel AAC, AAC 5.1 or AC3 5.1 – choose the format you need (you can also pass through the audio if the mkv is already in your desired format).

It only takes a few minutes and you have your file ready to go. MP4Tools will ‘mux’ the audio and video streams together and output an m4v/mp4 file for you to add to your media library. You may need to experiment with the correct audio type for your particular needs.

If you just want to play your file through a device that accepts MKV’s (not the Apple TV), but you just need to change the audio stream format, you will find MKVtools 3 a little bit faster as it doesn’t need to spend time remuxing the files – only a straight conversion of the audio stream is needed before it spits out your MKV. (There is no option for saving an MP4 with MKVtools, that’s what MP4tools is for).

Posted from London, England, United Kingdom.

Mod Rewrite – Redirect a request URI from subfolder to a higher folder on the webserver

I googled this for ages but I could not find the answer – all the posts I found were about how to just re-write how urls were displayed, because you would usually use the redirect command in .htaccess in order to redirect the browser request to a different resource on the server. You wouldn’t usually use mod re-write.

However, if you are redirecting requests for content from a sub folder to a higher level folder on the server, then you could get stuck in a circular redirect. You may also confuse visitors by displaying a url that they didn’t type in; so you need something a bit more special.

redirect 301 /directory/ /directory/article/
the above code would result in a circular reference!

The mod re-write command uses regex to define how you want apache to behave. For example, you have content currently being server from here: ‘/directory/article/page-name‘ but you want it to be seen to be seen to be ‘served’ from here: '/directory/page-name'.

To do this you need to enter the following in to your .htaccess file at the root of your site directory:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^directory/(((?!article).)*)/$ /directory/article/$1/index.html [NC,L]

This will work unless one of your page names has the same name as the folder that it is located (in this case ‘article’) as we are excluding this name from the URI re-write with the following code: (((?!article).)*)

Posted from London, England, United Kingdom.

Configuring SSL in MAMP 2.0.5 (the free version)

I’ve been trying to configure my MAMP installation (NOT the paid version) to accept SSL for a recent project that I am working on. A lot of MAMP SSL tutorials are out dated and do not work for MAMP v2+ (2.0.5) and some just don’t seem to work so I had to do a lot of digging around.

Non-SSL traffic results in 400 error

My main problem was that all traffic was forced via SSL – http traffic was met with a 400 error. I only wanted part of my project to run on SSL.

Setting up MAMP for SSL – the basics

I found this site that helped with the bulk of the task of how to implement MAMP SSL:

It covers the following steps:

  • Back up your MAMP install, or at least your config files
  • Generate a self signed certificate to use in your dev environment
  • Uncomment the required lines in the httpd.conf
  • Define your SSL site in httpd-ssl.conf

It also covers editing your hosts file and setting up virtual hosts – useful if you are a first timer at this and something I have previously covered.

I won’t cover these parts again, but I will add some important extra info that solved some key issues that I ran into:

MAMP SSL Problems

First, uncommenting and using the httpd-vhosts.conf file does not seem to work for me. For some reason apache would not start despite much fettling with the virtual host declarations in the file. Not a problem, you don’t need it – just leave this line commented and define your virtual hosts at the bottom of the httpd.conf file.

Fixing MAMP config: non-SSL http 400 error

The big issue for me is that enabling SSL results in only SSL traffic being accepted by the server, so if you try to access your site using http://.. you will receive a 400 ‘bad request’ http error message. To enable non-http traffic to work, you must do the following:

In httpd.conf, instead of:

<VirtualHost *:80>
ServerName test-site.co.uk
DocumentRoot "/Applications/MAMP/htdocs/sitedocs"
</VirtualHost>

You have to be explicit in the site you are defining in the <VirtualHost> tag. You also need to declare ‘SSLDisable’.

Use this:

<VirtualHost test-site.co.uk:80>
SSLDisable
ServerName test-site.co.uk
DocumentRoot "/Applications/MAMP/htdocs/shop2"
</VirtualHost>

This allows your test site to accept both ssl and non-SSL traffic.

Other Stuff

One other interesting point that may be important if you want to run multiple SSL sites on MAMP:

In the Apache docs it states that name based virtual hosts do not work for SSL. You can have one SSL site and multiple non-SSL sites defined via virtual hosts, but for multiple SSL sits you must use IP-based virtual hosts – so you would have to configure the machine with multiple IPs. Probably not worth bothering with!.

Helpful docs

Key to finding out how to solve my 404 issue was this example settings page that shows how to set up a site on ssl and another, differently addressed non-SSL site, but the principles are largely the same.

Posted from London, England, United Kingdom.

Delivering web video to mobile devices..

Lately I’ve been trying to get Video on to mobile devices and it’s a maze of techniques, settings, programs and codecs for every device and device model so below I’ll try to clear up some missunderstandings and include codecs, settings and techniques for delivering web video on to some of the most popular devices of Read the rest of this entry »

Posted from Lambeth, England, United Kingdom.

Load Balancing WordPress

When we moved to WordPress, we ran into an issue with our load balanced servers – you can’t add a post to each server individually because of the unique post number added by wordpress when you publish – the post will have a different URL on each server which, because traffic could go to any server, will result in Read the rest of this entry »

Posted from High Wycombe, England, United Kingdom.

Controlling multiple machines..

If you have more than one machine on your desk, then Synergy might be the answer. It allows you to control multiple machines, with different operating systems (Win or Mac/Unix based) with just one keyboard and mouse. As you move the mouse off the edge of one screen, it appears on the screen of the machine next to it. Clever eh?

Posted from London, England, United Kingdom.