Visualizzazione post con etichetta video. Mostra tutti i post
Visualizzazione post con etichetta video. Mostra tutti i post

mercoledì 4 settembre 2013

MekakuCityDays project - A rhythmic game

In the last three days I got bored and I started to develop a new rhythmic game with Unity that can work both on pc or android.
Since I'm a fan of kagerou project, a series of japanese songs made by Jin, I decided to make a little fan game.
I'm open for suggestion and I really need someone who can test it. I don't know how much more free time I'll have to spend on it, for now here a pre-alpha: DOWNLOAD
In the .rar there is an .apk if you want to play it on your device.


Featured songs are: Konoha's State of The World, Headphone Actor, Shounen Brave.
UPDATE: Blindfoded Code, Night Talk Deceive
Gameplay: Use they buttons - >
  • A or left arrow : for the left trigger
  • G or down arrow: for the middle trigger
  • L or right arrow: for the right trigger
  • Esc : for the menu/pause
ITA: I tasti da usare sono A,G,L. Il tasto Esc mette in pausa/menu.
Il gioco si ispira alla serie sopra citata in inglese.

UPDATE: Seems like so many people downloaded my game that dropbox decided to lock my public account. Don't worry tough, in the next few days I'll come with a new update featuring one more "hidden" song, so please, stay tuned!
Also, if someone know how to contact Jin regarding this project, please let me know.
See this.

domenica 25 agosto 2013

Converting video with JAVE

JAVE is a java library developed by sauronsoftware, it's a wrapper of FFmpeg and it's an easy way to converting video from a format to another. The main class of jave is it.sauronsoftware.jave.Encoder, Encoder objects have methods that transcode multimedia files.
First thing to do is adding JAVE to your CLASSPATH, if you are using eclipse simply import jave-1.0.jar in your project. Now in your code create an object of Encoder:
Encoder encoder = new Encoder();
Now you just call encode() to do the work, let's see it's signature:
public void encode(java.io.File source,
                   java.io.File target,
                   it.sauronsoftware.jave.EncodingAttributes attributes)
            throws java.lang.IllegalArgumentException,
                   it.sauronsoftware.jave.InputFormatException,
                   it.sauronsoftware.jave.EncoderException
the first argument (source) is the file you want to transcode, the second one (target) is the file you want to create on the machine. The argument attributes of type it.sauronsoftware.jave.EncodingAttributes is a structure that has all the propriety we want to give to our video. Attention: the method is syn, it returns after the video transcoding. Let's see how it's possible to convert a video by setting VideoAttributes and AudioAttributes:
 public static void convertVideo(String videoInput, String videoName) throws IllegalArgumentException, InputFormatException, EncoderException
 {
  String videoOutput = videoName + ".flv";
  Encoder encoder = new Encoder();
  
  File source = new File(videoInput);
  File target = new File(videoOutput);
  AudioAttributes audio = new AudioAttributes();
  audio.setCodec("libmp3lame");
  audio.setBitRate(new Integer(Config.AUDIO_BITRATE * 1000));
  audio.setChannels(new Integer(Config.AUDIO_CHANNELS));
  audio.setSamplingRate(new Integer(Config.AUDIO_SAMPLINGRATE));
  VideoAttributes video = new VideoAttributes();
  video.setCodec("flv");
  video.setBitRate(new Integer(Config.VIDEO_BITRATE*10000));
  video.setFrameRate(new Integer(Config.VIDEO_FRAMERATE));
  video.setSize(new VideoSize(Config.VIDEO_WIDTH, Config.VIDEO_HEIGHT));
  EncodingAttributes attrs = new EncodingAttributes();
  attrs.setFormat("flv");
  
  attrs.setAudioAttributes(audio);
  attrs.setVideoAttributes(video);
  
  encoder.encode(source, target, attrs);
 }
The video is converted in .flv format with given framerate, width, height and bitrate. The audio is transcoded in libmp3lame with given samplingrate. The values I've used to make a not so heavy .flv file are the following:
public class Config {
 public static int VIDEO_WIDTH = 640;
 public static int VIDEO_HEIGHT = 360;
 public static int VIDEO_FRAMERATE = 15;
 public static int VIDEO_BITRATE = 128;
 
 public static int AUDIO_SAMPLINGRATE = 22050;
 public static int AUDIO_CHANNELS = 1;
 public static int AUDIO_BITRATE = 64;
}
That's all, for media manipulation I suggest you to see FFmpeg and my previous post to give you the idea of how to do it in java. --------------------------------------------------------------------
ITA
La documentazione di JAVE è disponibile in italiano sul sito, il mio esempio si occupa di codificare un video da un formato input compatibile a .flv con le configurazioni date nella classe Config.

martedì 20 agosto 2013

Transcoding and Media Modification > Java - FFmpeg

Nel corso di un lavoro mi è capitato di dover scrivere del codice che permettesse di effettuare delle veloci modifiche ad un filmato, quali conversioni tra formati e tagli. Dopo aver guardato diverse librerie mi sono accorto che la migliore soluzione è quella di utilizzare ffmpeg.exe, un eseguibile che permette di effettuare semplici operazioni su file multimediali, tagli, merge, cattura di un immagine.

Per effettuare delle elaborazioni video è necessario richiamare ffmpeg.exe da linea di comando, passati i corretti parametri, ad esmpio:
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo.jpeg
Questa riga permette di ottenere un immagine .jpeg di dimensioni WxH del primo frame del filmato.
La documentazione di ffmpeg può essere trovata a questo indirizzo, tra i comandi più importanti voglio citare:

  • -r fps -> specifica il frame rate in output
  • -s size -> specifica la dimensione del filmato con sintassi LarghezzaxAltezza
  • -vcodec codec -> specifica il codec in output
Una volta capito come funziona l'eseguibile è facile creare un wrapper in Java, basta utilizzare la classe Runtime per ottenere il runtime di sistema. Di seguito vediamo da codice una funzione che presi in input due istanti di tempo, il percorso del video in input e in output utilizza ffmpeg per creare un video tagliato.


	public static void singleCut(double start, double end,String videoPathIn, String videoPathOut) throws IllegalArgumentException, InputFormatException, EncoderException, IOException, InterruptedException
	{
		String cmd = Config.FFMPEG+" -i "+ videoPathIn +" -q 5 -ss "+ start +" -to "+ end +" -y "+videoPathOut;
		//System.out.print(cmd);
		Runtime runtime = Runtime.getRuntime();
		Process p = runtime.exec(cmd);
		p.waitFor();
	}
Nel codice sovrastante Config.FFMPEG non è altro che una variabile statica con il percorso relativo al nostro file ffmpeg.exe .
Per effettuare delle conversioni ai filmati via codice vorrei anche segnalare questa libreria sviluppata da un italiano chiamata JAVE.
----------------------------------------------------------------------
ENG:
To transcode and execute single tasks on multimedia files by code the best way I found myself using is to create a wrapper around FFmpeg.exe. As you can see by the documentation this tool permits to do anything on video and audio files, things like extrapolate images or perform single cuts, are really easy and only require to read how to do it. For example the following line permits to take an image from the first frame in the video with width and height as WxH:
ffmpeg -i foo.avi -r 1 -s WxH -f image2 foo.jpeg
To easily call FFmpeg in Java simply use Runtime class to perform what you usually do in the command line.

	public static void singleCut(double start, double end,String videoPathIn, String videoPathOut) throws IllegalArgumentException, InputFormatException, EncoderException, IOException, InterruptedException
	{
		String cmd = Config.FFMPEG+" -i "+ videoPathIn +" -q 5 -ss "+ start +" -to "+ end +" -y "+videoPathOut;
		//System.out.print(cmd);
		Runtime runtime = Runtime.getRuntime();
		Process p = runtime.exec(cmd);
		p.waitFor();
	}
The string cmd is the line we want the code to execute by doing runtime.exec(cmd), Config.FFMPEG is just a static string with the absolute path of FFmpeg.exe.
I would recommend to take a look at JAVE if you just want to do simple video trascoding, it's quite nice and fast to use.