I recently stumbled upon a bunch of FLV files that I would like my daughter to be able to watch on our Xbox 360. Unfortunately, Xbox does not support these files, so I had to figure out how to convert them.
There are several commercial tools available for the job and I’m sure many of them can pull this off nicely but I wanted to check whether any of the free alternatives could do it.
The tool I successfully used is FFMPEG command line tool. You may download the latest binaries for Windows here: http://ffmpeg.zeranoe.com/builds/ I used the static 64-bit package.
Ffmpeg has a huge selection of command line options to select different codecs and standards for video. With trial and error I figured the following works to convert Video.FLV to Video.MOV.
ffmpeg -i Video.flv -y -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq ‘blurCplx^(1-qComp)’ -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -refs 3 -bf 3 -trellis 1 -ab 128k -b:v 1321k -f mov Video.mov
Note that Xbox does not recognize files with MOV-extension. You first need to rename it to AVI in order for it to work! That’s right: rename the MOV file as AVI and it works on Xbox! Xbox does not even show MOV-files on the list but plays them happily. Go figure…
Now, the command above converts just one file, but I had 100+ FLV files and finally used the following PowerShell script to convert them all from the current directory to MOV-files that were renamed to AVI files:
dir *.flv | foreach-object {$fn = $_.Name.split(‘.’)[0]; ffmpeg -i $fn”.flv” -y -vcodec libx264 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -subq 5 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq ‘blurCplx^(1-qComp)’ -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -refs 3 -bf 3 -trellis 1 -ab 128k -b:v 1321k -f mov $fn”.avi”}
Ffmpeg is a powerful tool and uses multicore processors effectively but it still might take several hours to convert dozens of files. Luckily the quality of the resulting video files is sufficiently high.
On my Xbox, the player did not immediately start playing the MOV file. It first had to download additional codecs from Microsoft.
WCF service unhandled exception handling
When an exception occurs in a WCF service, it is handled automatically by the framework and the client channel is terminated. This is the default behaviour.
But how to catch the exceptions without try-catch blocks in each and every service method?
The solution is to implement the IErrorHandler interface and make it your service’s service behavior. Typically we just want to know what exception was thrown and perhaps log it somewhere. At least, that was what I needed. What follows is a super-minimal but complete example:
There are two steps. First, implement an ErrorHandlerAttribute -class:
The code above just traces the exception but you may want to modify the generated exception to the client etc.
public class ErrorHandlerAttribute : Attribute, IErrorHandler, IServiceBehavior
{
public ErrorHandlerAttribute()
{
}
public bool HandleError(Exception error)
{
Trace.TraceInformation("Unhandled exception occured: {0}\nStack trace:\n{1}\nSource\n{2}", error.Message, error.StackTrace, error.Source);
return false;
}
public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
{
fault = null;
}
public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
}
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
foreach (ChannelDispatcher disp in serviceHostBase.ChannelDispatchers)
{
disp.ErrorHandlers.Add(this);
}
}
public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
}
}
To enable the Errorhandler in your service class, just use it as an attribute as follows:
[ErrorHandler]
public class ClientConnectionService : IClientConnection
{
// ...
}
Windows Mobile GPS tracker with Virtual Earth integration
I mainly exercise by making bike trips around the neighbourhoods I live in. The trips rarely have the same route and I thought it might be interesting to know afterwards where I have been. Having used a Windows Mobile phone for nearly a year now, I’d been looking for an opportunity to experiment with .NET Compact Framework and other Microsoft technologies.
I quickly drafted an architecture for the system consisting of the following components:
- Windows Mobile application to gather the GPS positions on the phone and send them to a Web service running on my server.
- Web service APIs to store GPS locations to a database and to let clients browse the paths I have travelled.
- A browser based application to visualize the paths by overlaying the GPS points on a Virtual Earth map
Let’s look at some of the details on how to implement all this.
Web service to store and browse GPS locations
Let’s start with the central component of the system: the storage. I started by creating a SQL Server 2005 database called gps to store GPS locations. The database has two tables:
- Session, stores starting time for a session which is defined as group of GPS position points (bike trip in my use).
- Gpsdata, stores the actual GPS measurements for a given session: timestamp, latitude, longitude, speed, heading
Next, I created an empty Web project in Visual Studio 2008 and added a simple Web service to the project as follows.

Visual Studio automatically generates the class for me with a Hello World -method that is accessible as a web service. I made some modifications to the class, beginning by adding [ScriptService] attribute to the class to make it accessible from the Javascript code in the browser. Also, I defined a database connection and a WebMethod to store location info for a selected Session ID. I might be a good idea to put the connection string into web.config file. I didn’t do it though.

Testing the web service is easy, just run the site by pressing F5 and Visual Studio opens up a browser to access the web service documentation. And since it is running on localhost, you can actually test that the call to the newly created method works.
The above method will be used by the Windows Mobile application to send GPS data to the server, but before we start hacking that together, let’s implement another call to fetch GPS locations from the database. The API is simple enough:

Now that we have all the services in place to store and retrieve GPS location data from the web, let’s implement the two clients.
Windows Mobile GPS tracker client
I based my demo on the GpsSample included in the Windows Mobile 6 SDK samples. The sample program implements a useful C# class to abstract the native GPS API. The existing functionality just opens up the GPS device and starts to print the current GPS data on the application window each time GPS location changes (once per second on my phone).
The idea is to extend the functionality of this sample program by integrating it into my newly created web service. I quickly found out it is extremely easy to do this. To access our web service, we need to add a Web Reference into the GpsSample project as follows:

This opens up a dialog to select the access point for the web service we like to add to the project. I selected to search web service in my solution and Visual Studio offered the only one: GpsStoreService. Selecting that allowed me to add the reference to my project by clicking the Add Reference -button:
Having a web reference in your project really means that Visual Studio has generated a proxy class complete with the needed types to access your web service of choise. What we need to access the web service, is an instance of the web service proxy object. I modified the gpssample to create the proxy object in the Form constructor. Also, I updated the URL of the service since I was going to access it from the internet.
![]()
After this, accessing the web service in Visual Studio C# code is just too easy, complete with IntelliSense:

The sample program has a function to update the screen when new GPS data is received from the HW. I added a line of code to send the data to my web service by using the store proxy object:

Deploying this to my phone and testing it on a quick walk around the house confirmed that it works: my database was inserted with some valid GPS coordinates. If only I could visualize them some how…
Visualizing GPS locations in web browser with Virtual Earth SDK
Virtual Earth SDK is a wonderful package to exploit the technology behind Live Maps. I recommend first time users to simply take a good look at the Interactive SDK, which shows you interactively in a couple of minutes what the SDK is capable of.
My idea for a demo was to study how easy it is to consume my web service and have the GPS coordinates visualized on an interactive Virtual Earth map. The goal was first simple: have the GPS coordinates for one session (one bike trip) be plotter on the map.
I started by creating a ASP.NET AJAX enabled web page (MapDemo.aspx) in my project. I’m using ASP.NET so that I can utilize the ASP.NET AJAX browser components which are quite handy.
After the page is set up, let’s see how easy it is to embed Virtual Earth on the page. First, let’s define the map control’s location and dimensions on the page by creating a DIV-element with a suitable id (‘myMap’):

To embed the map into the defined location above, we need to include the mapcontrol JavaScript source code, create a new Map object and load it with some initial settings. In this example, we shall open a map into a location near my home with some initial settings (see image below).

This brings the fully interactive map control on the page when we load it up in the browser. Easy, huh?

Now let’s continue with integrating the web services created earlier on the page. The component I needed was the ASP.NET AJAX ScriptManager which automatically generates JavaScript proxy code against my web service. The following definition did the trick in the aspx file. Note also the reference to my web service.

With that in place, I can access my web service asynchronously on the page as follows:

GetLocationSucceeded is the final JavaScript-function that gets called when the web service call returns with a list of GPS locations. The remaining bit of the implementation is to render a line on the map visualizing the GPS locations and my bike trip. The Virtual Earth MapControl implements an API that allow several layers of graphical elements be drawn on top of the map. These elements are based on points that have GPS coordinates. The following JavaScript function does the trick by creating a VEShape with a type of PolyLine:

The final map with the path rendered using the Web Service data looks the this. Pretty neat, huh? Some random ideas for next experiments: Passport authentication, SQL Server 2008 spacial data type support and perhaps GeoRSS.

Fixing WHS backup
I’ve been trying to back up my main PC with Windows Home Server but Win XP on my PC gives an error in the event log: Volume Shadow Copy Service error: Error creating the Shadow Copy Provider COM class with CLSID {65ee1dba-8ff4-4a58-ac1c-3470ee2f376a}. I found some instructions to fix this problem and the culprit seemed to be swprv.dll. However, re-registering it with “regsvr32 /i swprv.dll” failed with an odd error code. Opening Component Services from Admin tools revealed that my COM+ catalog was corrupted. These were finally the steps needed:
- Reinstall COM+ by first removing the registry key as instructed here.
- Register swprv.dll as above.
- Re-run backup.
The latest additions to Half-life 2 seem to be more suspectible to certain network monitor programs and firewalls behaving badly. I recently purchaced Episode 2 extension for Half-life 2 and immediately noticed that something was wrong with the game. Right in the main menu, the background animation and sound stuttered so fiercely that it was impossible to even start the game. Funny thing was, none of the other games had any problems starting (HL2 or Episode 1), so I quickly concluded that this probably wasn’t a hardware or driver problem.
Search from the Web revealed that similar stuttering-problems had been noticed by other users as well but the solutions didn’t apply to my situation. I didn’t have any Nvidia firewalls or network monitors running. Or so I thought.
Having recently attended Mark Russinovich‘s session about using Sysinternals Process Monitor to troubleshoot various issues with applications and drivers, I decided to give it a try.
Rather quickly I noticed some weird behaviour by HL2.exe while the game stuttered in the main menu. The process was continuously accessing certain registry key, namely HKLM\SOFTWARE\XUEBROTHERS\. This is how it looked like:

I didn’t know I had any software by XueBrothers installed but by searching from the web about WS2LSPX I realized I had the “WIMS” IP & Socket Monitor installed and running. It was trying to monitor the traffic of HL2.exe and probably due to a bug decided to read the registry a little too frequently.
Uninstall of the WIMS fixed my Episode 2 problem completely.
Distributed UDDI install on SQL Server 2005 (cluster)
Windows Server 2003 ships with UDDI server that is out-of-the-box compatible with SQL Server 2000 as a storage engine. If you don’t have any databases, the installer can also install local MSDE engine for you.
I was recently involved in a CSF deployment that utilized clustered SQL Server 2005 instance as a storage for all CSF and application databases and we decided to study whether it was possible to configure it for UDDI as well making the installation distributed.
Microsoft has a knowledgebase article that refers to the case where you need to install on a local SQL Server 2005. However, in our case, the UDDI installer did not allow us to select the SQL cluster that we had sitting in the network, so we needed to take matters into our own hands.
So let’s describe the servers we had:
UDDI Server: This should be the host of the UDDI.
Sql Server: The SQL Server 2005 cluster
Here are the high-level steps we had to take in order to install UDDI on SQL2005 or to move the database to SQL 2005:
-
Install UDDI normally with MSDE. If it fails, see below for tips.
-
Test that UDDI is accessible with a browser (http://localhost/uddi).
-
Stop MSDE UDDI instance service.
-
Copy UDDI database files from the UDDI data folder to SQL Server machine’s appropriate data folder. If you have a clustered instance, you may need to place log files on a different shared disc etc.
-
If needed, create an AD account that the UDDI service will use to access the database. We’ll call it UDDIService here.
-
Attach the database files to SQL Server. Set access rights for UDDIService account for this database.
-
On UDDI server, modify registry values at key LOCAL MACHINE\Software\Microsoft\Uddi\Database to point to the SQL Server instance instead of local machine instance.
-
Modify IIS UDDI application pool and set the Identity that the pool will run under as UDDIService account created earlier.
-
Add UDDIService account into the local IIS_WPG group.
-
Restart IIS (iisreset)
-
Use browser to test that UDDI is up and running
-
You may then proceed and uninstall the MSDE instance from the UDDI server.
If UDDI installation fails with an error in MSDE setup, you may need to install a temporary, local SQL Server instance on UDDI server. For this to succeed, refer to this Microsoft knowledge base article first.
The method described here also applies to the case where you want to load-balance (NLB) the UDDI server and keep the data in one place. That we did as well.
Run-time code generation in Symbian OS
I was experimenting with a software that generates ARM code at run-time (a JIT compiler). I wanted to run the code also on my Symbian/S60 phone and for this I needed to study the details of Symbian memory management from user-mode perspective as my earlier experiences in writing kernel mode code for didn’t come handy here.
Three things were needed:
- A method of allocating a chunk of virtual memory that is both writable by my threads and can contain executable code
- A method of committing pages of physical memory to the virtual memory chunk for my process
- Some portable way to flush the data and instruction caches for particular data areas when code is modified in this area
I was a little bit worried that Symbian OS Platform Security might limit the applications capabilities in this regards but luckily all this possible using the following APIs:
- RChunk::CreateLocalCode() – Creates a user writable chunk that is marked by the kernel as containing code. The chunk has a maximum size and a committed size.
- UserHeap::ChunkHeap() – Creates a heap in a local chunk that is compatible with the Chunk API.
- User::IMB_Range() – Does the necessary preparations to guarantee correct execution of code in the specified virtual address range. Symbian OS EKA2 kernel can operate in different MMU architectures (ARM4/5) and this API makes handling user mode generated code portable.
All this wasn’t that easy to find since the functionality was fragmented to three classes.
I might post a more complete sample program later.
One small step for dialog designer…
Nokia released a new version of PC Suite awhile ago with a small version number upgrade. I installed it today and immediately found a small but quite significant user interface change.
In previous versions, the sis file installer has first brought a query “Do you want to install the application? [Yes/No]” where the user had been able to just press enter to continue the installation. The next dialog has previously been “Please finish the installation… [Ok]” but this has been changed to “Please finish… [Cancel]“. I’ve now canceled the installation of my application under development roughly 10 times already. Aargh. ;(
NetBSD on SGI O2
Some time ago I installed NetBSD on an SGI O2 (R10000). I’ve made a page about that for anyone interested in reviving their old workhorse.
Disappointed in PHP
Lately I’ve seen a lot of good things implemented in PHP, including the blog pages you’re reading. Not that I consider PHP itself as new technology, I just haven’t been using it extensively for anything useful.
To install WordPress on my own server, I decided to give PHP a try in Windows XP environment. It all looked pretty good when the PHP download site offered Windows installers and all. Unfortunately it wasn’t quite plug’n'play as it seemed. After many frustrating hours of configuring it still doesn’t run giving the infamous “The specified module could not be found” -error that seems to be a common error with no specific fix.
The questions is: why would they offer an installer that does not work out-of-the-box? It should be quite possible. In addition, all bug-reports reporting this issue are ignored by the PGP developers because “it is not a bug in PHP”. I disagree: it is a bug in the PHP installer! Make the world a better and more interoperable place and fix it!
I know, the optimum platform would have been a LAMP capable server. Perhaps I’ll try it on one of those running in my VMWare. Meanwhile, let’s try this hosted solution, which by the way, seems to work brilliantly.

