Wednesday, September 1, 2010

gst-launch examples

1. read and display YUV
gst-launch filesrc location=movie.yuv ! videoparse framerate=20 width=640 height=480 ! xvimagesink
OR
gst-launch filesrc location=movie.yuv blocksize=460800 ! video/x-raw-yuv,format=\(fourcc\)I420,width=640,height=480,framerate=5/1 ! ffmpegcolorspace ! xvimagesink
but here framerate setting does not work.

Thursday, August 12, 2010

Gnome problems

1. gnome-panel 2.28.0 has a bug in Karmic Koala. When you set it up to auto-hide it starts looping and takes almost all CPU. And auto-hiding does not work. One cannot even get back to the access to panel settings to disable auto-hide. You can start gconf-editor and under panel->toplevels->top_panel_screen_0 disable auto-hide option.

Tuesday, June 22, 2010

memset speed vs memcpy speed

Below i post some piece of code I wrote for memset testing. It's C.
Memset can be 4-5 times faster then an ordinary loop.
There is also one feature which should be pointed out.
When loop and memset operate on the same array and loop is first in order (memset follows the loop), memset can be 10 times faster (probably due to cache usage). It does not work the opposite way. If memset goes first and loop goes second the memset speedup is 4-5 times again.
The array is one dimension - why the compiler does not take advantage of cache. Or maybe the cause of speed up when memset goes after loop is better vectorization?
If arrays are totally different memory areas, the speedup for memset is again 4-5 times.

Try it yourself if you wish and please comment. I have used gcc 4.4.1


#include
#include "time.h"
int main()
{

unsigned int val = 253,val2=223;
const int size = 7000;

//unsigned int test[size][size];
unsigned int *test,*testloop;
test=(int*)malloc(size*size*sizeof(unsigned int));
testloop=(int*)malloc(size*size*sizeof(unsigned int));
if (test == NULL)
{
printf("cannot allocate so much memory, size: %d ", size);
return;
}

int i,j;
double loop_time,memset_time;

double old_time = (double)clock();///CLOCKS_PER_SEC;
// printf("took %5.3f seconds \n", total_time);

for (i=0;ifor (j=0;jloop_time=(double)clock() - old_time;
memset_time = (double)clock()- old_time - loop_time;
printf("Loop took %5.3f ticks \n", loop_time);
printf("memcpy took %5.3f ticks \n", memset_time);
free(test);
free(testloop);
free(struct_array);
free(struct_array2);
free(struct_array3);
}//main

Memcpy works slower than assignment
I had to check it and it is truth. The assignment runs faster then explicit memcpy. All tests were done using gcc and g++ 4.4.1. Here is the code for struct copy. I tested memcpy and loop in separate executions (that's why memcpy is commented out)

#include
#include "time.h"
#include
int main()
{

unsigned int val = 253,val2=223;
const int size = 7000;
class test_struct
{
int a;
int b;
float dupa;
double s;
public:
test_struct() {};
};

unsigned int *test,*testloop;

test_struct *struct_array = new test_struct[size*size];
test_struct *struct_array2 = new test_struct[size*size];

test = new unsigned int[size*size];
testloop = new unsigned int[size*size];

int i,j;
double loop_time,memset_time;

double old_time = (double)clock();///CLOCKS_PER_SEC;
// printf("took %5.3f seconds \n", total_time);

for (i=0;i for(j=0;j struct_array[i*size + j] = struct_array2[i*size + j];

//memcpy(struct_array2,struct_array,size*size*sizeof(test_struct));
loop_time = (double)clock() - old_time;

memset_time = (double)clock()- old_time - loop_time;
printf("Loop took %5.3f ticks \n", loop_time);
printf("memcpy took %5.3f ticks \n", memset_time);
//delete(test);
//delete(testloop);
delete [] struct_array;
delete [] struct_array2;
delete [] test;
delete [] testloop;
}

Saturday, June 19, 2010

ffmpeg examples

1. cropping from avi:
ffmpeg -i input.avi -croptop 44 -cropbottom 46 -cropleft 56 -cropright 36 -sameq -s 640x480 cropped.yuv
2. cropping yuv:
ffmpeg -s 640x360 -i source.yuv -cropleft 120 -cropright 120 -croptop 60 -cropbottom 60 target.yuv

Thursday, May 27, 2010

IEEE 1394 camera tricks

1. reset the bus
dc1394_reset_bus
2. Showing the capabilities of the camera
cd /sys/bus/ieee1394/devices/[node]
(you can check nodes number using dc1394_reset_bus)
grep . *

Automake - conditional compilation

I want to compile some part of the code only when library (OpenCV) is detected:
In configure.ac
dnl check if opencv is installed
PKG_CHECK_MODULES(OPENCV,
opencv >= 2.1.0,
HAVE_OPENCV=yes, HAVE_OPENCV=no)
if test "x$HAVE_OPENCV" = "xno"; then
AC_MSG_NOTICE(no OpenCV library with version >= 2.1.0 found - rectify plugin will not be available)
elseif
dnl if yes set flags and libs
AC_SUBST(OPENCV_CFLAGS)
AC_SUBST(OPENCV_LIBS)
fi
dnl set the variable for makefile
AM_CONDITIONAL(I_HAVE_OPENCV, test "x$HAVE_OPENCV" = "xyes")
---------------
In Makefile.am
if I_HAVE_OPENCV
"do smth"
else
"do smth else"
endif

A bit more about conditionals in makefiles is here

Tuesday, May 18, 2010

Firefox plugin does not work with the newest Firefox version

The problem comes when the plugin version is not updated on addons.mozilla.org and firefox claims it is not compatible with current version. Steps to solve this issue:

1. Donwload .xpi file (right click on "Add to Firefox" button.
2. Change extension to .zip
3. edit install.rdf file so that maxversion matches the current version of your firefox
4. save changes
5. change .zip back to xpi
6. Drag and drop .xpi on firefox.

More on this can be found here