Tag Archives: flash

Convert a video (avi, mpg, wmv, …) to flv with ffmpeg on Linux

If you want to publish a video on the Internet you will probably want to reduce the size of your video.
A full HD video in avi format will be too heavy and totally inappropriate for streaming, this is where the Flash technology shows its power.

Flash is used all over the place on the Internet for audio & video streaming, you keep good video quality and a significant reduce on files’ size. Of course you will need a tool or a software to convert your video. If you are a GNU/Linux user you will most likely end up using FFmpeg.

FFmpeg is a command-line program who gives you the ability to record, stream, encode audio & video. You have a large amount of options to perfectly match your needs (consult the man for that).

The first step is to install FFmpeg. It will depend of your operating system, if you are running a Debian based distribution you can use the apt command line:

# apt-get install ffmpeg

If you are on Archlinux (my current distribution) use the pacman tool an so on:

# pacman -S ffmpeg

Now you need a simple command to encode your video into a Flash video (.flv extension), here is an example:

$ ffmpeg -i my-video.avi -f flv -b 768 -ar 22050 -ab 96 -s 720x576 my-video.flv

Lets take a look at the options:

-i it is the input file, the video we want to convert in another format
-f the output format of our video
-b it defines the bit rate of the output video (768kbit/s in our case)
-ar the audio frequency of the output video 22050 Hz in this example
-ab the audio bit rate of the output video
-s the dimension of our output video

Yes it is that simple, after the execution of the command you have your .flv video.

Of course, you can use this tool to convert video or audio in other formats (wmv to avi, avi to mpeg, whatever you want). I choose the .flv because it is such a lost of time to find a reliable solution to encode it properly.

Flash game: Sonic falldown

This is a project I worked on for a couple of months to learn more about Flash programming and it was quiet interesting.

The game is very simple and addictive (well it is all about breaking your own high score), you have to keep moving if you do not want to get caught by the boxes. The speed may seems slow at the very beginning but the longer you play, the harder it will be, trust me on that.

I also implements bonus for the game to make the experience more attractive and less linear.

  • First of all, if you are in big trouble you can break the box right under your feet and have a chance to survive. Keep in mind that you will not be able to do so all over again (I thought that would be too easy for gamers like you ^^), you start with three break box bonus. Once you have completed five levels, you will gain a new break box bonus but you cannot keep more than three break box bonus so use them wisely.
  • You also have a speed bonus which will allow you to move faster for a few seconds and get you out of a nasty situation. You have three speed boost bonus for the whole game, do not waste them.

Here is a short snippet of the game loop which manages the rendering of the character:

/* Determine the state of the character and display the associate sprite. */
_state = "fall";
if(collision == true)
	_state = "stand";
	/* If the user press the right/left key the character is walking.
         * If the speed bonus is active a special sprite is display. */
	if(Key.isDown(Key.LEFT) == true || Key.isDown(Key.RIGHT) == true)
		_state = (speedBonusEnable == true) ? "speed" : "walk";
		/* If the character as reach the limit of the animation he is stuck. */
		if(this._x-(this._width/2) <= 0+PADDING || this._x+(this._width/2) >= WIDTH_GAME-PADDING)
			_state = "stuck";

There are some stuff to finish (bugs collisions, a pre-loader or a high-score handler).
Still, it is good enough for you if you want to have a good idea on how to develop games with Flash. Here is an archive with all the files of the project (sources files, images, sfx, etc).