Wednesday, 17 December 2008

Cannot restore segment prot after reloc: Permiss

Occured when attempting to load the libphp5.so module into Apache using RedHat linux.

Fixed by running:

system-config-securitylevel

and setting SELinux to Permissive

Tuesday, 9 December 2008

Creating flash video (flv) files with ffmpeg

First, install Lame., to access the mp3 codec.
Second, install ffmpeg. Ensuring that you run the configure script with the --enable-libmp3lame option.
(I used ./configure --disable-vhook --enable-x11grab --enable-gpl --disable-bzlib --enable-libx264 --enable-libmp3lame).

Thirdly, use ffmpeg thus:
ffmpeg -i myinputfile.mpeg -ar 22050 -ab 56000 -b 200000 -acodec libmp3lame -ac 1 myoutputfile.flv

Friday, 5 December 2008

Flash files won't work in any old directory?

Flash player 9 (and presumably all subsequent releases) have security features that limit where data and files can be accessed from.
Check the following directory (under windows):

c:\Documents and Settings\\Application Data\Macromedia\Flash Player\#Security\FlashPlayerTrust

Within will be some .cfg files, each specifying permitted directories for playing Flash (SWF) files.
Feel free to add your own,
i.e. file: mydir.cfg
contents: C:\temp

Will allow you to play swf files in your c:\temp directory

Tuesday, 28 October 2008

Calculating field of view from focal length

From wikipedia article.

a = 2 atan (d/2f)

where:

a = angle of view,
d = sensor size in direction that angle is required,
f = focal length

Friday, 10 October 2008

How to check the architecture for which a Linux app is compiled.

readelf -a

Will give all the details of the compiled code.

Tuesday, 23 September 2008

Storing a procedure in mySQL

Simple alias for a more complex command...


create procedure nameofmyprocedure () select * from mytable;


To use within mySQL

call nameofmyprocedure();



This assumes that no arguments are required (empty argument list () ).

Fixing undefined reference to vtable errors in QT3

Assuming that you have added the Q_OBJECT macro to your class definition then the problem is that you are not generating and referencing the moc file for that class.
Easiest way to fix is to run qmake on your src.pro file (if you are using kdevelop, making sure that qmake is the correct one for your version, QT3 and QT4 qmake are not the same.)

Alternatively, run

moc -o myheader.moc myheader.h

and include the myheader.moc file in your project. It will need to be updated every time you change your SIGNALS or SLOTS in that class, so you may want to automate its creation.

Friday, 12 September 2008

Linux library types

Copied from yolinux.

.a Static library, the contents become part of the compiled executable.

.so Dynamically linked shared object library. Do not become part of the executable but must be present at run-time.


How to generate a static library (.a)
Compile: cc -Wall -c ctest1.c ctest2.c

Compiler options:
-Wall: include warnings. See man page for warnings specified.

Create library "libctest.a": ar -cvq libctest.a ctest1.o ctest2.o

List files in library: ar -t libctest.a

Linking with the library:
cc -o executable-name prog.c libctest.a
cc -o executable-name prog.c -L/path/to/library-directory -lctest


How to generate a dynamically linked shared object library: .so

Create object code

gcc -Wall -fPIC -c *.c


Create library

gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o


Optional: create default version using symbolic link

mv libctest.so.1.0 /usr/lib
ln -sf /usr/lib/libctest.so.1.0 /usr/lib/libctest.so
ln -sf /usr/lib/libctest.so.1.0 /usr/lib/libctest.so.1


Compiler options:

-Wall: include warnings. See man page for warnings specified.

-fPIC: Compiler directive to output position independent code, a characteristic required by shared libraries. Also see "-fpic".

-shared: Produce a shared object which can then be linked with other objects to form an executable.

-W1: Pass options to linker.
In this example the options to be passed on to the linker are: "-soname libctest.so.1". The name passed with the "-o" option is passed to gcc.

Option -o: Output of operation. In this case the name of the shared object to be output will be "libctest.so.1.0"


Library Links:

The link to /usr/lib/libctest.so allows the naming convention for the compile flag -lctest to work.
The link to /usr/lib/libctest.so.1 allows the run time binding to work. See dependency below.


Compiling for runtime linking with a dynamically linked libctest.so.1.0:

gcc -Wall -I/path/to/include-files -L/path/to/libraries prog.c -lctest -o prog

Use:
gcc -Wall -L/opt/lib prog.c -lctest -o prog
Where the name of the library is libctest.so. (This is why you must create the symbolic links or you will get the error "/usr/bin/ld: cannot find -lctest".)
The libraries will NOT be included in the executable but will be dynamically linked during runtime execution.


The shared library dependencies of the executable can be listed with the command: ldd name-of-executable

Monday, 8 September 2008

Automating FTP transfer with linux

edit file ~/.netrc to contain

machine sample.ftpsite.com
login anonymous (or user name)
password mymail@mydomain.com (or user's password)



Make sure you:
chmod 600 ~/.netrc

To keep your passwords secure.

The ftp client will check the contents of this file when performing an ftp connection and will use the login and password when the machine matches one of the entries in the file. This is useful when writing a script to automate file transfer (as part of a cronjob for example) as no user intervention is necessary.


The FTP script itself might look like:



open sample.ftpsite.com
cd backupdir
lcd mylocalbackups
put backupfile.log



That script (remember to chmod +x scriptname) can be added to the cron daemon.

Pipe into gzip

cat myfile.txt | gzip -f > myfile.txt.gz

Friday, 29 August 2008

Linux: Check if a system service is running...

As root:

chkconfig [name of service]


i.e.

chkconfig sendmail

Wednesday, 20 August 2008

Backing up MySQL databases

Backup...

> mysqldump mydatabase > mydatabase.sql


Restore...

> mysql < mydatabase.sql


Options:

-X : outputs database info as XML.
--all-databases : dumps all databases to stdio
-p : to add a password

Monday, 18 August 2008

Finding Linux xwindow size

xwininfo -stats -root

will return info including the width and height of your screen.

Capturing the screen to video with ffmpeg

Using ffmpeg...

ffmpeg -f x11grab -s 1280x1024 -r 25 -i :0.0 /tmp/out.mpg


Assumes that --enable-x11grab switch was used during configuration.

Adding H264 to ffmpeg and libraries

In the configuration command add --enable-libx264

In any code using libavcodec, link to /usr/lib64/libx264

Friday, 1 August 2008

Using subversion through a proxy

Linux:
In the file ~/.subversion/servers
under the [global] section, uncomment the http-proxy-host entry and make sure it points to your proxy server address.

http-proxy-host = myproxy.address.com

Check that the port is correct as well.

Thursday, 31 July 2008

To create a continuous pipe to stream a real-time video

At the server:


> mkfifo fifo.flv
> APPTOMAKEFLVFILE fifo.flv &
> netcat -l -p 1234 < fifo.flv

At the client

> netcat SERVERADDRESS 1234 | ffplay pipe:


In this case, the APPTOMAKEFLVFILE is compiled from the output_example.c file that comes with the ffmpeg download from http://ffmpeg.mplayerhq.hu/

To pipe data into ffplay over a network

Server: netcat -l -p 1234 < test.mpg

Client: netcat SERVERADDRESS 1234 | ffplay pipe:

Tuesday, 29 July 2008

Compiling against libavcodec

When using the libraries supplied with ffmpeg (such as libavcodec, libavfilter etc etc) you must link to the libraries in the following order..

-lavformat -lavcodec -lavdevice -lavutil -lm -lswscale -lavfilter

If you see the error
undefined reference to `BZ2_bzDecompressInit'
Then you must reconfigure and make ffmpeg, adding

--disable-bzlib

to the configuration line.

In this case, the configuration for ffmpeg was...

./configure --disable-vhook --enable-x11grab --enable-gpl --disable-bzlib


Also, remember to bracket the libavcodec header files in extern "C" tags if you are using C++. i.e.

extern "C" {
#include
#include
}

Friday, 25 July 2008

Blender real-time engine

Blender contains a real time engine with a physics engine and definable game logic.
'p' to launch.