Archive

Posts Tagged ‘ubuntu’

Convert your MP3 bitrates via terminal

November 8, 2010 1 comment

Image courtesy of technabob.

I just had my machine reformatted for a new Ubuntu version and I spent hours the other night reorganizing my files.  I realized that among the ones taking up most of my disk space are my MP3 files.

MP3 is a lossy audio compression scheme, but you can actually take the option to reduce its bitrate (say for your small capacity MP3 player) without losing much of the quality.  Some music files are at 320kbps, but the standard rate is 128kbps.  You will realize that a file has a high bitrate if the size is too large for the song length.

You can calculate the size of an MP3 file using this:

z = (x * y) / 8

where
x = length of song (in seconds)
y = bitrate (in kilobits per second)
z = resultant file size (in kilobytes) – dividing by 8 gives the result in bytes

So let’s say you have an MP3 of length 3 minutes = 180 seconds.  At 128kbps, your file will be as big as:

z = (180*128)/8 = 2880kb = 2.880Mb

Compared to when you have it at 320kbps:

z = (180*320)/8 = 7200kb = 7.200Mb

Now that’s significant difference when you have thousands of MP3s in your disk.  Most people take the option to convert their MP3 files using a software (e.g. SoundConverter, another FOSS app).  But if you would like to keep things light on your machine, you would wish instead to install the library LAME (a recursive acronym meaning LAME Ain’t an MP3 Encoder).  For more information on this package, run: man lame.

So how does it work? To do the bitrate conversion, run on the terminal (as root):

 lame --mp3input -b <bitrate> <file.mp3> <destination.mp3> 

where the bitrate could range from 8 – 320, depending on your need.

If you have more than a handful of MP3 files, you can automate the conversion using the following shell script:

 for f in *.mp3 ; do lame --mp3input -b <bitrate> "$f" <path_to_destination>/"$f" ; done 

Note that leaving the destination parameter as null saves the file in the form file.mp3.mp3 while setting this parameter to your player’s location causes your file to land there.

———————————————————————————————–—————–————————————
References:
[1] Wikipedia, 2010. MP3.
[2] Jhollington, 2004. kbps ?. iLounge Forums.
[3] Ubuntu Packages, 2010. Package: lame.
[4] Ubuntu Development Team, 2010. “lame” package. Launchpad.
[5] Vanadium, 2007. Convert MP3 bitrate. Ubuntu Forums.

“GLX” missing on display

June 27, 2010 25 comments

I’ve recently upgraded to Ubuntu 10.04, and the first time I ran SciLab I got no graphics.  I’m using an Intel Corporation Mobile GM965/GL960 video card, and when I check the implementation this is what I get:

tisza@tisza-ubuntu:~$ sudo lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 0c)
tisza@tisza-ubuntu:~$ glxinfo
name of display: :0.0
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Error: couldn't find RGB GLX visual or fbconfig

Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
Xlib:  extension "GLX" missing on display ":0.0".
3 GLXFBConfigs:
visual  x  bf lv rg d st colorbuffer ax dp st accumbuffer  ms  cav
id dep cl sp sz l  ci b ro  r  g  b  a bf th cl  r  g  b  a ns b eat

After poking around a couple of forum pages, I finally got a workaround.  Thank you ~witekk for the fix.  So here’s how to do it. On the terminal (as root):

sudo apt-get purge nvidia*
sudo apt-get install --reinstall xserver-xorg-video-intel  libgl1-mesa-glx libgl1-mesa-dri xserver-xorg-core
sudo dpkg-reconfigure xserver-xorg
sudo update-alternatives --remove gl_conf /usr/lib/nvidia-current/ld.so.conf

Luckily, this solves the same problem with two other graphic controllers:

 

  • Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev 03)
  • Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)

There you have it. Enjoy!

Categories: Machine fix Tags: , , ,

2. SciLab Basics

June 22, 2010 Leave a comment

For the rest of the semester, I’d probably be using a couple of essential tools on my journey to learning image processing. One brilliant software I encountered is SciLab, an high-level cross-platform programming language very efficient for numerical computations and scientific visualizations. Many researchers choose SciLab for its vast capabilities on signal processing and image enhancement. Best of all, unlike other software, SciLab is non-proprietary and completely open-source. The product is in the public domain – freely downloadable online. Anyone can run, copy, modify and redistribute its packages. For the download location, click here.

SciLab offers a good Integrated Development Environment (IDE) for the user for working with codes and figures. The following is a screenshot I have captured from my own desktop.

Figure 1. A snapshot of the SciLab IDE

The tool offers a console for easy preview of short one-liner codes, and an embedded test editor, called SciPad, for working with files.

My primary operating system is Linux (specializing in GNU-based applications).  Currently I am using the Ubuntu distribution.  For installing SciLab in Ubuntu, one can open the package list at:

System > Administration > Synaptic Package Manager

then mark SciLab* for installation.

Alternatively, simply open the terminal and enter (as root):

sudo apt-get install scilab

The image processing end of the software is referred as the SciLab Image and Video Processing Toolbox (SIVP), an equivalent of the SIP in Windows.  To install this extension, run:

sudo apt-get install sivp

This tool can be loaded from the SciLab console via:

Toolboxes > sivp

*Latest stable version as of article date: SciLab 5.2.1-8, compatible with SIVP 0.5.0-1.
———————————————————————————————–—————–————————————

For a good jumpstart, I used SciLab scripts to familiarize with the basic functionalities (and workarounds) of the imaging tool.  On a 2D canvass, I constructed basic shapes using binary matrices.  The initial scipt [1] reads:

nx = 500; ny = 500;      // defines the number of elements along x and y
x = linspace(-1, 1, nx); //defines the range
y = linspace(-1, 1, ny);
[X, Y] = ndgrid(x, y);   // creates two 2-D arrays of x and y coordinates
A = zeros(nx, ny);

This basically prepares a 500×500 matrix filled with zeroes (ready to be filled with data later).  The script to create a circle will be:

r = sqrt(X.^2 + Y.^2);   // element-per-element squaring of X and Y
A (find((r&lt;0.7))) = 1;  // values of r where r&lt;0.7

Modifying this code creates an annulus:

A (find((r &lt; 0.7) &amp; (r &gt; 0.4))) = 1; // values of r where  0.4&lt;r&lt;0.7

To view the figure, insert:

imshow(A);    // displays the 2D matrix A

Load the program into the console via:

Execute > Load into SciLab

or simply, Ctrl+L.  Figure 2A shows the output figure of the set of code.

Figure 2. A. annulus, B. square

In order to produce the square image (Figure 2B), the script would be:

A (find((abs(X) &lt; 0.5) &amp; (abs(Y) &lt; 0.5))) = 1; // values of x and y from -0.5 to 0.5

where abs() is a built-in function for taking absolute values.

Next up, would be to create a set of horizontal gratings, which can be created using loops:

for i=1:1:500
   for j=1:100:500       // 100 being the period for how the gratings repeat
      A(j:j+50, i) = 1;   // 50 being the width of every grating
   end
end

This script, when displayed, results to a fairly striped image (Figure 3A).

Figure 3. A. horizontal gratings, B. 2D sinusoid

Diverting from binary matrices, a smooth 2D sinusoidal function is created by:

freqc = 5*%pi;      // frequency of the sinusoidal
A = sin(X*freqc);

Lastly, to produce a 2D Gaussian distribution (Figure 4), we write:

r = sqrt(X.^2 + Y.^2); // note element-per-element squaring of X and Y
A = exp(-4*r);         // 2D Gaussian

Figure 4. 2D Gaussian

Saving the image into a file takes the one-liner:

imwrite(A, 'gaussian.bmp'); // also works with png, jpg, tif and gif

That wraps up my initial set of familiarization on SciLab.  This just marks the beginning of an exciting bunch of image processing ahead.  One final note, I believe it is always best to develop good coding habits.  For SciLab coding standards, let me share the Code Conventions for the SciLab Programming Language.

For this section, I would rate myself 10 for being able to comprehend the important ideas and produce the desired outputs.

——————————————————————————————————————-—————–—————-

[1] Soriano, M. (2010). A2 – Scilab Basics. Applied Physics 186.