Tuesday, 6 July 2010

OBJ model fails to load in Away3D

Error contains:
Error #1009: Cannot access a property or method of a null object reference
away3d.loaders::Obj/parseMtl()...


Seems to affect OBJ files that contain mtl file references that have been created on a Linux PC.

Solution is to open the obj file in wordpad in Windows and just resave it.
I suspect that this changes the line endings to Windows native format.

Thursday, 22 April 2010

using printf in libavcodec

Although av_log is preferred, you can use printf statements for your own personal debugging processes by adding

#undef printf

before any of your own code.

Thursday, 11 March 2010

Actionscript 3: Error: Call to possibly undefined method addEventListener through a reference with a static type class

If you have been following Gustavo Kawamoto's instructions for making a Actionscript 3 static, singleton class you might be have received the undefined method addEventListener error when trying to set up an event listener for your static object.

The thing to remember is that you must add an event listener on an object instance, so try the following:

MyStaticClass.getInstance().addEventListener(MyEvent.BLAH, myHandler);


This works since the getInstance() method returns the instance of your static singleton.

Tuesday, 5 January 2010

Firefox slow in Ubuntu. DNS lookup fix.

Problem: Firefox takes an age to resolve host addresses in Ubuntu.

Solution:
Open Firefox,
type about:config into the address bar, press return,
Scroll down to the entry network.dns.disableIPv6 and set it to TRUE (with a right mouse click).
Surf away.


With thanks to http://www.craigmayhew.com/blog/2009/11/slow-dns-lookups-in-firefox-on-ubuntu-9-10-karmic-koala/

Wednesday, 25 November 2009

/usr/include/qt4/QtCore/qtconcurrentfilter.h:227: error: expected nested-name-specifier before numeric constant and other errors compiling Qt4

If you see a load of compile errors from Qt4 classes when doing a compile, this is sometimes caused by your #include statements.
To fix it, replace all the #include <qwhatever>with a single

#include <QtGui>

instead. (For GUI elements anyway. See /usr/include/qt4/Qt directory for other default includes like QtNetwork etc etc)
You should be using that anyway, but QT3 habits die hard.

Friday, 11 September 2009

Subversion hangs on commit

If you find that your subversion commands such as commit are hanging before they complete (usually requiring a kill -9 to exit from) and you are using Apache as the webserver, make sure that the Apache KeepAlive directive is on.

Thursday, 28 May 2009

.infig.status: error: cannot find input file

Seen when running ./configure before building an application from sourcecode.

Cause: Seems to be caused (under Linux) by having DOS style line endings in the configure script.

Solution: Open 'configure' in a Linux text editor (like kwrite), small change, undo the change and save the file so that it writes in all the correct line endings.


Alternative is to use tr to do the conversion:

tr -d "\15\32" < configure > configure.new

./configure.new

Monday, 26 January 2009

Setting monitor powersaving on eeepc

To prevent the eeepc going to sleep when shutting the lid.

Open a terminal (ctrl-alt-t)
Login as root (su)
edit the file (using pico or some other editor) /etc/acpi/lidbtn.sh
comment out (with a #) the line

/etc/acpi/suspend2ram.sh

Save the file.

eeepc should now remain awake when lid is shut.



To prevent external monitor going to sleep after timeout

xset -dpms

This deactivates Energy Star

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.

stdout over IP

Linux: use netcat (or nc) to send stdout over a network. The '-l' switch listens at a port for a connection. Use pipes to send the data to an application.

Friday, 18 July 2008

mkfifo

The Linux command mkfifo creates a file that can be accessed by multiple processes simultaneously.

Wednesday, 16 July 2008

Streaming raw image data into Flash

As an alternative to using flv video in Flash, it is possible to stream raw image data across a socket to be used to fill a BitmapData object provided that each pixel is transferred as a 32-bit ARGB value.
By streaming from a socket (running in an external application) on the localhost, this displays about 9fps (820x640 pixels). Of course, there is no audio.



package
{
import flash.display.*;
import flash.geom.Rectangle;
import flash.net.*;
import flash.events.*;
import flash.utils.ByteArray;
import flash.errors.EOFError;


/**
* ...
*
*
* Open a socket
* read an image
* display
* repeat
*/
public class Main extends Sprite
{

private var imageSocket:Socket;
private var response:String;
private var imageBytes:ByteArray;
private var byteArrayOffset:Number;
private var myBitmap:Bitmap;
private var myBitmapData:BitmapData;

public function Main()
{

response = new String("");
imageBytes = new ByteArray();
byteArrayOffset = new Number();
byteArrayOffset = 0;

stage.stageWidth = 820;
stage.stageHeight = 640;

myBitmapData = new BitmapData(820, 640, true, 0xFFFFFF00);
myBitmap = new Bitmap(myBitmapData);

stage.addChild(myBitmap);



imageSocket = new Socket("localhost", 4242);

imageSocket.addEventListener(Event.CLOSE, closeHandler);
imageSocket.addEventListener(Event.CONNECT, connectHandler);
imageSocket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
imageSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
imageSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);




}

private function closeHandler(event:Event):void
{
imageSocket.flush();
trace("closeHandler: " + event);
trace(response.toString());
}

private function connectHandler(event:Event):void
{
trace("connectHandler: " + event);
}

private function ioErrorHandler(event:IOErrorEvent):void
{
trace("ioErrorHandler: " + event);
}

private function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
}

private function socketDataHandler(event:ProgressEvent):void
{

//trace("socketDataHandler: " + event);
//this bit reads the stuff in the socket into a ByteArray object,
//note that it comes in chunks, so you need to add up the bytesloaded
//property each time the event is called until your message is the size
//you expect.

imageSocket.readBytes(imageBytes, byteArrayOffset, event.bytesLoaded);

byteArrayOffset = byteArrayOffset + event.bytesLoaded;


if (byteArrayOffset >= 820*640*4) //image is loaded
{
//do stuff with image

byteArrayOffset = 0;

//need to reset the position pointer in the ByteArray so that
//subsequent functions read from the start of the array

imageBytes.position = 0;


this.drawImage();

}

}

private function drawImage():void
{
try
{
var rect:Rectangle = new Rectangle(0, 0, 820, 640);

//this bit sets the pixel values in the BitmapData object to the values in the ByteArray

myBitmapData.setPixels(rect, imageBytes);
}
catch (e:EOFError)
{
trace(e);
}
}
}
}

Monday, 7 July 2008

BitmapData.copyChannel

In the flash.display.bitmapData class the channels are numbered as follows:

1 (red)
2 (green)
4 (blue)
8 (alpha)

This is important to know when using the copyChannel method.

Improving Z depth rendering in Away3D

Away3D seems to use a mean Z-position algorithm for sorting Z-depth when rendering. i.e. It calculates the mean Z of the vertices in each triangle and uses that value to determine the Z depth of the triangle when rendering. To improve the accuracy of the rendering, increases the number of triangles in the object (at the cost of render speed).


i.e. For a plane use

myPlane.segmentsH = x;
myPlane.segmentsW = x;


where x is greater than 1 (the default).

Friday, 4 July 2008

Mapping flv video to geometry in Actionscript

To avoid having to use SWF encapsulated video files to map video to geometry in Flash 9, use the flash.media.Video class instead. The following extends the Plane class in the open source Away3D flash library to have a plane with a texture mapped video (flv). The constructor takes the location of the flv file (either a path to the file or as a URL).

This version of the class should now work with Away3D 3.0.0

package
{
import away3d.core.math.Number3D;
import away3d.primitives.Plane;
import away3d.materials.BitmapMaterial;
import away3d.materials.VideoMaterial;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.media.Video;


public class videoPlane extends Plane
{
private var video: DisplayObject;
private var videoURL:String;
private var videoBitmapData: BitmapData;
private var videomaterial: BitmapMaterial;

private var alphaMap:BitmapData;

private var vidConnection:NetConnection;
private var vidStream:NetStream;
private var vid:Video;
private var infoClient:Object;
private var alphax:Number;
private var alphay:Number;
private var asset:String;
private var alphaBool:Boolean;


private var aspectRatio:Number;



public function videoPlane(assetLocation:String)
{

asset = assetLocation;
this.ownCanvas = true;
alphaBool = true;

trace("videoPlane()");
this.segmentsH = 8; //increases the number of triangles in the plane, and hence improves the accuracy of
this.segmentsW = 8; //the mean z algorithm used to determine Z-depth when rendering


vidConnection = new NetConnection();
vidConnection.addEventListener(NetStatusEvent.NET_STATUS, NetStatusHandler);
vidConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, SecurityErrorHandler);
vidConnection.connect(null);


this.bothsides = true;
aspectRatio = 1024 / 576;

this.height = 50;

this.width = this.height * aspectRatio;




}

private function NetStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
vidStream = new NetStream(vidConnection);
infoClient = new Object();
vidStream.client = infoClient;
vid = new Video();
vid.attachNetStream(vidStream);
vidStream.play(asset);
this.videoBitmapData = new BitmapData(vid.width, vid.height, true, 0xFF00ce);
videomaterial = new BitmapMaterial(this.videoBitmapData);
videomaterial.precision = 5;
this.material = videomaterial;
this.bothsides = true;
this.videoBitmapData.draw(vid);
alphaMap = new BitmapData(vid.width, vid.height, true, 0x7F000000);
vidStream.addEventListener(NetStatusEvent.NET_STATUS, vidStreamCompleteHandler);
//connectStream();
break;
case "NetStream.Play.StreamNotFound":
dispatchEvent(new StatusEvent(StatusEvent.STATUS, true, false, event.info.code, "Status"));
break;
}


}

private function SecurityErrorHandler(event:SecurityErrorEvent):void
{
dispatchEvent(new StatusEvent(StatusEvent.STATUS, true, false, event.type, "Status"));
}


private function vidStreamCompleteHandler(ns:NetStatusEvent):void
{

if (ns.info.code == "NetStream.Play.Stop")
{
vidStream.seek(0);
vidStream.resume();
}

}


public function updateVideo():void
{

//trace("updateVideo");

if(vid != null)
{

videomaterial = new BitmapMaterial(this.videoBitmapData);

this.material = videomaterial;

this.videoBitmapData.draw(vid);


}


}

public function pausePlayback():void
{
vidStream.pause();
}
public function resumePlayback():void
{
vidStream.resume();
}

}

}

Tuesday, 1 July 2008

Correcting texture distortion in Away3D

Use the precision attribute of the material.

i.e

var videomaterial: BitmapMaterial = new BitmapMaterial(this.myBitmapData);

videomaterial.precision = 2;


This will slow rendering down, but remove perspective distortion from the textures. Increasing the value improves render speed at the price of quality.

Javascript

The Document Object Model (DOM) uses the script

tag to bracket Javascript code within an HTML document.

Wednesday, 25 June 2008

Remote Desktop Connection

Linux equivalent: rdesktop

Monday, 23 June 2008

Accessing ftp

Sometimes necessary to use socksify ftp
if proxy server is in the way.

Also, go via dpgate since it has socksify installed.

To remove "500 Illegal PORT command" error. Type: passive

Thursday, 19 June 2008

Streaming webcam across the internet

Content of file ffserver.conf

Port 8090
# bind to all IPs aliased or not
BindAddress 0.0.0.0
# max number of simultaneous clients
MaxClients 1000
# max bandwidth per-client (kb/s)
MaxBandwidth 10000
# Suppress that if you want to launch ffserver as a daemon.
NoDaemon


File /tmp/feed1.ffm
FileMaxSize 5M


# FLV output - good for streaming

# the source feed
Feed feed1.ffm
# the output stream format - FLV = FLash Video
Format flv
VideoCodec flv
# this must match the ffmpeg -r argument
VideoFrameRate 15
# generally leave this is a large number
VideoBufferSize 80000
# another quality tweak
VideoBitRate 200
# quality ranges - 1-31 (1 = best, 31 = worst)
VideoQMin 1
VideoQMax 5
VideoSize 352x288
# this sets how many seconds in past to start
PreRoll 0
# wecams don't have audio
Noaudio


# ASF output - for windows media player

# the source feed
Feed feed1.ffm
# the output stream format - ASF
Format asf
VideoCodec msmpeg4
# this must match the ffmpeg -r argument
VideoFrameRate 15
# generally leave this is a large number
VideoBufferSize 80000
# another quality tweak
VideoBitRate 200
# quality ranges - 1-31 (1 = best, 31 = worst)
VideoQMin 1
VideoQMax 5
VideoSize 352x288
# this sets how many seconds in past to start
PreRoll 0
# wecams don't have audio
Noaudio




on local PC run

> ./ffserver -f /PATH/TO/ffserver.conf &

> ffmpeg -r 15 -s 352x288 -f video4linux -i /dev/video0 http://localhost:8090/feed1.ffm


On remote PC, point web browser at

http://IPADDRESSOFFFMPEGMACHINE:8090/test.asf

or

http://IPADDRESSOFFFMPEGMACHINE:8090/test.flv


depending on which format stream you wish to access.

ffserver errors

The error that is received after attempting to insert a ffmpeg stream into an ffserver feed "Could not find input stream matching output stream #0.0" can be caused if no audio is present in the captured stream.

It can be fixed by changing the "AudioBitRate X" setting to NoAudio in the stream descriptor in the ffserver.conf file.

Friday, 13 June 2008

Capturing from a webcam with ffmpeg

ffmpeg -f video4linux2 -s 384x288 -r 10 -i /dev/video0 /tmp/out.avi

Will capture from the device at /dev/video0 and save to /tmp/out.avi

Capture can be viewed using

ffplay /tmp/out.avi

Thursday, 12 June 2008

WG111v3 wireless modem and SuSE Linux 10.2

After using following these instructions and installing ndiswrapper, I managed to get the wireless connection working on my SuSE 10.2 box only when I disabled all encryption in the wireless router. Before that, it was hanging while waiting to recieve its IP info from the DHCP server.

Wednesday, 11 June 2008

Netstat

Linux:
netstat -natq will show you current network connections

Monday, 9 June 2008

Searching for strings in Linux

Forward slash '/' in man/more/etc will allow you to search for a string. 'n' will search for the next instance.

Searching for strings in Linux

Forward slash '/' in man/more/etc will allow you to search for a string. 'n' will search for the next instance.

if statement in Linux scripts

When comparing two strings, if the strings contain spaces then you must have a dollar sign at each end of the variable name...

if [ $IP$ = $OLDIP$ ]
then
blah
blah
fi


Note also the spaces between the variable names and the '=' symbol...

IP address lookup from Linux

use:
host
or
nslookup

How to fix Error 1327: Invalid Drive f:

Another one of those tiresome bugs that pop up from time to time...


If you try to install or uninstall a program in Windows, and get this:

Error 1327. Invalid drive f:\

where f is a drive you’ve never heard of, then run regedit and find HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders. Change any instance of f: to %USERPROFILE%.




Seems to do the job.

Friday, 6 June 2008

VideoLAN VLC....

....can capture video via DirectShow (on Windows at least) and write it out as an H264 MPG transport stream.

Thursday, 5 June 2008

PHP

PHP can support sockets, making it much easier to suck data from other processes.

Wednesday, 4 June 2008

Flash...

To stream HD-SDI, live to a Flash scene:
SDI -> Flash Encoder -> Flash Server (possible Red5?)

Blender texturing

To add a UV texture to a Blender model so that it will be rendered, go into object mode, select the object with the previously assigned UV texture, press F5 to edit Material and select TexFace from the Material Tab. For some objects (Planes) it may be necessary to select Mat from the Material window.