Our Blog

JQUERY version 1.5

by sly February 14, 2011 08:45

La nouvelle version 1.5 de Jquery est disponible.  Grace à l'option Deferred on peut maintenant faire des "callbacks" consécutifs..woohoo

Tags:

Coding | Français

JQUERY 1.5

by sly February 14, 2011 08:43

Just released : Jquery 1.5 , with the new Deferred option for multiple callback...woohoo

http://blog.jquery.com/2011/02/07/jqcommunity-updates-feb2011/#jqreleased 

Plus a preview of the official Jquery UI Grid.

Tags:

Coding | English

CSV Strings in SQL

by BillyTheKid August 18, 2010 06:35

I’m working on a webservice that will receive a comma separated list of ID’s and return XML and was concerned about the performance of the function I had been using in SQL to split a string into a table to join and select records.

I have been using a pretty basic iterative function that uses CHARINDEX and SUBSTRING, acceptable for small strings, but it was not going to work for this project.

Thankfully I found a CLR function in c# which has amazing performance.  Credits to Adam Machanic over at SQLBlog.  Find the code in his post here

http://sqlblog.com/blogs/adam_machanic/archive/2009/04/28/sqlclr-string-splitting-part-2-even-faster-even-more-scalable.aspx

To use his code, the first thing you will need to do is copy the class into a .cs file and compile it:

csc /target:exe sql_split_clr.cs

If the c sharp compiler is not in your path, add it.  For SQL 2005 you want to use the framework version 2.

set path=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;%PATH%

CLR functions and procedures are disabled by default in SQL 2005.  If you have not yet enabled it, use the following

sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO

 

You will then need to create the assembly and functions in SQL like this:

CREATE ASSEMBLY SQL_Split
FROM 'c:\clr\sql_split_clr.dll'
GO

CREATE FUNCTION string_to_list(@list nvarchar(MAX),@delim nchar(1) = N',')
RETURNS TABLE (item nvarchar(4000))
AS EXTERNAL NAME SQL_Split.UserDefinedFunctions.SplitString_Multi
GO

Now the new CLR function should be ready to use

SELECT * FROM dbo.string_to_list('a,b,c,d,e',DEFAULT)

As a final aside, what’s with having to specify the DEFAULT keyword to use the default parameter value on functions.  You don’t have to with stored procedures.

Tags: , ,

Coding | English

More on Videos and HTML 5

by BillyTheKid June 15, 2010 08:37

After my last blog post on videos Encoding H264 for the iPhone I ran into a little issue with the videos I was encoding when trying to stream to the iPhone it would say "Movie could not be played".   The only difference I could see between one that I found that would play and mine was the codec, which was set to ISOM, instead of mp42 for one that worked.

It was quite a simple fix actually, just changing -f mp4 to -f ipod in the ffmpeg command line changes the format to M4V which the iPhone will stream without issue.  FFMpeg makes a minor complaint about using a .mp4 extension with m4v format, but it all works fine.  Credits to the Metal Toad Media blog for the fix.

Now we have H264 encoded .mp4 files which can be streamed to Safari or Chrome, as well as the iPhone.  Here is a very simple example of the HTML 5 video tag.

<html>
<head>
<title>Video Testing</title>
</head>
<body style="background-color:#FFFFFF; ">
<center>
<video controls>
<source src="http://www.technoponics.com/media/expo67.mp4" type="video/mp4">
</video>
</center>
</body>
</html>

Encoding H264 video for iPhone streaming with ffmpeg

by BillyTheKid May 21, 2010 05:43

The first thing you need to know is that to stream a video to the iPhone using progressive downloading you will need to use 2 pass encoding.  There is something called the MOOV atom which needs to be at the beginning of the file, but can't be created until after the encoder has been through the entire source file at least once.  Pres umably bitrates, metadata etc, need to be pre-calculated, but that's just a guess.  If you come across something called qt-quickstart which will move the MOOV atom, avoid it, just take the time/cpu cycles to do a 2 pass encoding, the videos look better anyway.

Make sure you have a recent build of ffmpeg which has the ffpresets directory.  I'm currently using Rev 18639 from Tripp's unofficial win32 builds.  One thing to note, on Windows, you have to specify the full path to the preset file, in the -vpre parameter, and put it in double quotes, like in my example below. 

On the first pass ffmpeg will create a log file in the current directory that it uses during the second pass.  You will see examples on the internet for 2 pass encoding that have an output file for the first pass, but it is unnecessary, we only need the log file so you should specify NUL to save the hard drive I/O.  On Linux you’d use /dev/null.

For this little test, I have downloaded a 60 second public domain newsreel clip from 1967 discussing the opening of the world expo held in Montreal that year.  Head on over to the National Film Board (NFB) website to get any number of videos you can try converting.  The NFB video was 720x480, but the iPhone supports only 640x480 video up to 1500k bitrate.  In my example I’m scaling the video down to 640x428 and padding the top and bottom with 26 pixels. 

Here is the command for pass 1:

ffmpeg -y -i Expo67.mpg -f ipod -pass 1 -vcodec libx264 -s 640x428 -padtop 26 -padbottom 26 -r 30000/1001 -vpre "D:\utils\ffmpeg\ffpresets\libx264-fastfirstpass.ffpreset" -vpre "D:\utils\ffmpeg\ffpresets\libx264-ipod640.ffpreset" -b 250k -bt 50k -bf 0 -an -threads 0 NUL

The b and bt parameters are bitrate and bitrate tolerance, which you might want to increase for your video.  The –bf 0 parameter turns b-frames off, the iPhone does not support H.264 b-frames.  Adding it here prevents an error when encoding the 2nd pass.  The –an parameter turns audio off, which we won’t encode until the second pass.

Here is the command for pass 2:

ffmpeg -y -i Expo67.mpg -f ipod -pass 2 -vcodec libx264 -s 640x428 -padtop 26 -padbottom 26 -r 30000/1001 -vpre "D:\utils\ffmpeg\ffpresets\libx264-hq.ffpreset" -vpre "D:\utils\ffmpeg\ffpresets\libx264-ipod640.ffpreset" -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -ar 22050 -async 1 -threads 0 Expo67.mp4

The trick here is to use two ffmpeg presets at the same time, fastfirstpass/ipod640 then hq/ipod640 for the second pass, always specifying the ipod640 preset second.

Here is a link to the Expo67.mp4 video, which should stream directly to your iPhone using progressive download.

Mono-Touch : C# pour le iPhone

by sly August 25, 2009 07:08

J’adore mon iPhone. Depuis un an, ce petit bijoux est presque toujours à mes cotés. C’est la première chose que je vois le matin (réveille matin) et la dernière lumière que je ferme (en mode lampe de poche) avant de me coucher. Seulement la télécommande de la télévision lui fait compétition. 

Mais en tant que programmeur, j’ai toujours trouvé l’iPhone inaccessible. ChezTechnoponics on essaie de limiter le nombre de langage de programmation pour ne pas diluer notre expertise. Nous avons fait le choix de C# , Javascript et ActionScript ce qui nous permet de tout faire (web, application ,etc) sauf programmer l’iPhone. Jusqu'à maintenant…

Grâce aux talentueux programmeurs du projet Mono, la version Open Source de C#, nous allons bientôt pouvoir développer des applications en C# pour le iPhone grâce au tout nouveaux Mono-Touch. Mono-Touch promet de prendre le code C# et le convertir en application native Objective-C avec sa technologie ‘Ahead of Time Compilation’.  

Nous croyons que Mono-Touch créera un tsunami d’applications internes pour les iPhone et iPod touch quel que soit le type d’entreprise. La plateforme iPhone est fiable, l’équipement résistant et surtout abordable à moins de 300$. 

Pour plus d’information,aller sur le site Internet de Mono-Touch : http://www.mono-project.com/MonoTouch

.Net remoting, interesting and frustrating

by BillyTheKid July 08, 2009 09:33

Well I've been testing out .Net remoting and so far it is pretty frustrating.  There is very little good examples anywhere on the net, the error messages it generates are cryptic, and I think there are a few known framework bugs that are pretty easy to run into.  Basically what I'm trying to build is a service on a machine that executes long running processes in a queue, specifically ffmpeg, mencoder, possibly flvtool2 or others.

My project has 3 parts, server, client, and shared interfaces library.  There are two interfaces defined, one for the task service queue, the other a custom task object, and for the purposes of this example, I've kept only the taskId field on the object.

Initially I had exposed the custom task object using RegisterWellKnownServiceType and although I could add multiple tasks to the queue, they all seemed to be shallow copies of the same object, changing a property on one changed them all.  I then decided to go with the factory pattern and added a CreateTask method to my task service which returned a full value object copy of an ITask.

One thing to note, when passing a complex object back and forth using remoting, you have to set the TypeFilterLevel to Full or you will get serialization errors.  The complex object needs to be marked as [Serializable] and should NOT inherit from MarshalByRefObject, whereas the main task service absolutely must. 

More...

Using FFMpeg with c#

by BillyTheKid April 08, 2009 07:14

Video is becoming more pervasive on the web and any of you that have been asked to work with video, have probably looked at FFMpeg.  For those who don’t know, it’s a command line video (and audio) conversion tool, and it’s open source.

For this example, I’m going to write a small class in c# which will use the System.Diagnostics.Process class to run ffmpeg and parse the video size, duration and frame rate from the output.  I’ll run ffmpeg like this “ffmpeg –i myvideo.avi” without specifying an output file and redirect the error stream to get the info I want.  Here is what the output looks like on the command line.

ffmpeg_out

To use the class, first we pass the file name of the video in the constructor:

Technoponics.Video.FFMpeg v = new Technoponics.Video.FFMpeg("myvideo.avi");

Then you call the CheckVideo method, which will then fill in the Width, Height, Fps and Duration public properties.

v.CheckVideo();
Console.WriteLine("Video Size: "+v.Width+"x"+v.Height);

Here is the code for the FFMpeg class (ffmpeg.cs file):

More...




Tags: ,

Coding | English

Asterisk PBX

by BillyTheKid March 30, 2009 09:28

Well I have finally finished installing the new phone system at the office.  We purchased a 4 port analog phone line card by Dialogic, and are using Asterisk for our phone system.

I went with an analog card so I could use standard old POTS phone lines.  We had only 1 line on our main number before, and it was just easiest to get them to add a second line and cascade it from the main number.  Probably many of you use BRI or T1 interfaces for your lines, Dialogic (or the others) have cards for your setup.  Probably the main reason why I went with a Dialogic card over Sangoma or Digium was because I had an opportunity to purchase one for half price.  Like everyone else, I first tried one of those twenty dollar wildcard fxo single port cards, which gave me nothing but major echo problems and headaches.  If you are going to put together an Asterisk system, save yourself some trouble and buy a good card for your phone lines.

The Dialogic cards use a CAPI interface (the ISDN standard), even for their POTS analog cards.  You need to have libcapi20 installed and the kernel sources to build the dialogic drivers as a kernel module.   I installed a somewhat never version of libcapi than they mentioned in their instructions, libcapi20-3.0.5-cm.tar.gz, works fine, grab the latest from melware.org

I first tried a plain install of Asterisk on Ubuntu 8.0.4, created my own extensions.conf and started on my dialplan.  Once I realized how much work that was going to be I tried FreePBX.  After the 3rd time I was reinstalling the box, getting Apache, MySQL and everything running for FreePBX and Asterisk, I decided to give Trixbox a try.  It’s a CentOS distribution with Asterisk and FreePBX already setup and configured.  Although I’d never used CentOS before, it is based on Red Hat and is pretty easy to find your way around.  Actually I haven’t used Red Hat since around version 7.2.    I’m using Trixbox 2.6.2, which has Asterisk 1.4 integrated.

I used “yum” to install a few extra thing needed to get the Dialogic drivers to compile and install.  Use “yum install [packagename]”.  I needed to install kernel-devel, gcc, gcc-c++, ncurses-devel and asterisk-devel.

Once installed FreePBX is pretty easy to add extensions and configure your phone system.  We have a couple of Linksys SPA-942 telephones, but I hate them and would not recommend them.  I am using a cheap $9 GE telephone and grandstream ATA (analog telephone adapter) on my desk and get better sound quality.

To get my Dialogic card to work in FreePBX all I had to do was add a custom trunk with the text DIALOGICDIVA/contr1/$OUTNUM$/b.  contr1 is the first controller in my system, $OUTNUM$ is a variable FreePBX will replace in the dial plans, and the lower case B is for early B3 connects.  See dialogic instructions for options.  To receive calls from the Dialogic adapter, the most important thing to set is the call context in the dialogicdiva.conf file for your installation.  I used the context “from-trunk” which will get FreePBX to route it correctly when it comes in.

For now, rather than when you dial instead of having an IVR (… if you know your party’s extension …), we created a ring/pickup group and set everybody’s phone to ring when a call comes in from the outside.  The first person to answer their phone picks up the call and says hi, and then can transfer the call to another desk if needed.  And with caller id, we usually know who the call is for anyway.

Dialogic Diva Analog 4P Card

Trixbox CE (Community Edition) Download Page

BlogEngine.Net custom control

by BillyTheKid March 11, 2009 18:45

Well, Sly installed BlogEngine.Net and he was pretty impressed with it so I though I would take a stab at creating a custom theme and copying the new skin from our site to see if I could get it to work.  Long story short it was pretty easy and only took me a few hours to do.

Most of the BlogEngine themes had a top nav with home,archive,subscribe,login/logout.  I wanted to put those links into a box in the right column and have our sites nav there.  Not satisfied with just putting  bit of HTML in the master file for the theme, I decided to make my own custom control for it. 

More...

Tags: ,

Coding | English