Thursday, June 26, 2008

Debugging C/C++ under Linux

This article is a cool one for that. But don't get bored from the shell or the command prompt environment, there are alternative user friendly IDEs such as NetBeans which do the same mission but this article just show you what is behind and it is just an ABC debugging lesson under Linux, So I think that the XYZ lesson is NetBeans IDE for C/C++

Saturday, May 24, 2008

FFmpeg: An open source video codec

First of all this may be considered a research post but I think that you may find something interesting in this post as a developer.

Have you ever watched a movie…oh yeah…ok have you ever imagined that won’t be able to watch this movie without a video codec?!

Yeah… imagine that you have a movie with these features indicated in the figure bellow and suppose that this move is stored in your HD without any codec as just raw image frames in RGB format? Do you know how much space it will take from HD? It will take about 120 Giga Bytes



Yes its true; verify [720*300*3*25*(60*(60*2+13) +7)]/2^30 = 120.5 GB

But actually the file is stored at my PC using only 742 MB and so it seems that the codec made a compression ratio 1 : 166, isn’t great?

What does this means? This means that you could never store more than a single movie at your 160 GB HD, It also means that you could never burn a movie on a DVD and shares it with your friends, Ask yourself another question…What if this video was stored in the original desktop digestions e.g.; 800 X 600 pixels..It will overflow your weak HD :P.

But thanks God … this scenario doesn’t happen and the favor returns to video codec

For a second trial imagine that you view this movie on the internet for a 10 minutes, then your internet connection needs to transfer [425*355*3*25*10*60]/2^30 = 6.2 GB in a raw RGB video format

You may need to buffer for many weeks or even months to be able to view it on your strong ADSL link…What a disaster if the internet congested by millions of users like you…Internet might die.

But actually this live movie is about 20-30 MB only

So in simple definitions a video codec is a lossy compression technique used to compress/decompress multimedia to be suitable for storage and transmission

Video codec consist of encoder and decoder and there are many of them some are commercial and others are open source and a lot of them are under progress, for more information you can visit the multimedia home page.

As an example of a codec is the MPEG-4 which is implemented in the open source project ffmpeg, MPEG-4 codec has the facility that it can produce different quality stream output from the same original video for different quantizer scales, In MPEG-4, the valid quantizer scale values are in the range 1 to 31, with 1 producing the highest quality and bit rate

So let’s encode a video file with different quantizer scales (1-31) and compare the visual appearance and output stream size

You can see in the image bellow that the left half of the lady is after using Fair & Lovely lotion and the right is not.




This is not true; the left half is the output of the encoded video file after using a quantizer scale = 1, and the right is using 31…So which quality or appearance you prefer? I know the left… but to be fair who specify that is not your wish, but it depends for example on the available resources … you can’t view a live movie with the good quality one a dialup network connection instead for low speed connection you should use less good quality one

By numbers, let’s see the compression ratio for each quality value (1-32), Original raw file size is 44550 KB

Quality value from best to worst

1

2

3

15

16

30

31

Decoded steam size in KB

995

992

627

135

129

83

83

Compression ratio to raw file 1 :

44

44

71

330

345

536

536

Isn’t amazing to compress a file with a compression ratio of 44 for best quality with tha same appearance like the original file and 536 for worst quality?

You can transfer this 10 seconds file over any network starting from 995 KB ~= 1 MB for high speed network or 135 KB for medium speed network or 83 KB for slow Dial Up connection

Let’s take a running example using ffmpeg :

Download demo 2MB on Windows ; Just run the encode.bat & decode.bat after downloading akiyo_cif300.yuv into your working folder

Download demo 2MB on Linux ; Just run the encode.sh & decode.sh after downloading akiyo_cif300.yuv into your working folder

Download demo output raw video file click here (44 MB) and to play YUV file please refer to my previous post

Also you can download coded video files High 995 KB, Medium 135 KB, Low 83 KB Quality, You may need k-Lite codec to play these files or run the decoder to return them to YUV format

It is very interesting that ffmpeg source code is available for public, it is cross-platform and this another advantage, you can also enhance it and build over what the community did, and your product will be used by Video LAN or a lot of other projects

Tuesday, May 20, 2008

Geany: A lightweight IDE for C++ under Linux

Geany is a lightweight integrated development environment IDE, which run under Linux.

Geany is available through the official Debian archives.

sudo apt-get install geany

The problem with Geany is that it doesn't have debugging and import/export options :'( so it may be good IDE for beginner programmer @ level 1

Tuesday, May 6, 2008

Zemanta...We are making blogging fun again

Zemanta is a plugin that lets your browser understand what you are blogging about and suggest pictures, links, articles and tags to make your posts more vibrant.



Thursday, May 1, 2008

Remote Desktop at your Ubuntu from your Windows and versa

Remote Desktop is a great service offered by most operating systems, many times we used it at our work for example when the network administrator or the DB administrator needs to give you some privileges at the server while he is sitting at your machine

In all the past cases there was the same scenario where a Windows machine needs to remote access another Windows machine which is simple and needn't setup stuff

The problem here is that now I spend my time among my own apartment in which I can carry my portable PC there and my family apartment in which my desktop "shared resource" is sitting there . While I have to work with my stuff at my Ubuntu desktop PC?!

There are two available solutions for this conflict:

Solution # 1:Every time I go to my apartment I can carry my desktop (case + monitor + table + chair) ... great.. isn't it? but this may explode other problems
Solution # 2:Is to access my Ubuntu desktop remotely with only one click and LAN connection between us ... very interesting ... isn't it?

So to summarize solution # 2

To configure Remote Desktop at your Ubuntu

You need to go to System -> Preferences -> Remote Desktop and check options there for sharing and security


To connect from Windows machine

You need to install vncviewer and simply run it to access your Ubuntu

Enjoy Remoting @ Linux :)


You may ask how can i do the reverse operation of connecting to your Windows machine from your Linux?

The steps is very easy to connect remotely @ your Windows OS from your Ubuntu:

To configure Remote Desktop at your Windows

1- Install TigntVNC Server then run it and assign the client connection password

To connect from Ubuntu machine

2 -Open Applications -> Internet -> Terminal Server Client and connect using Computer, Protocol, User Name fields

3- Then you will be notified to enter the client password set in step 1

Enjoy Remoting @ Vista :)

For more information you can follow these links:

Share your Ubuntu Desktop Using Remote Desktop

TightVNC downloads