sabato 26 settembre 2009

Video per Nokia N95 altro metodo




Ho trovato un'altro interessante programma per convertire i video: WINFF.
Questo non è altro che un'interfaccia grafica per il "convertitore" a linea di comando FFMPEG.
Il programma si può scaricare a questo indirizzo:
http://winff.org

oppure in versione "portatile" che quindi non necessita di installazione a questo indirizzo:
http://www.winpenpack.com/main/download.php?view.1093
su
www.winpenpack.com
un bellissimo sito contenente delle stupende raccolte di sofware "freeware portabile" cioè che si possono mettere comodamente su penne USB ed utilizzare senza installarle sul sistema


Il programma è semplicissimo da utilizzare, basta indicare il file da convertire, selezionare il preset desiderato, premere il bottone CONVERTI e fa tutto da solo.
E' anche molto veloce.

Volevo solo segnalare questo preset che ho provato sul mio nokia N95 e che funziona bene anche con il lettore freeware "DivX Mobile" che trovate a questo indirizzo.
http://labs.divx.com/MobileCommunity

Il formato in uscita è un XVID 320x240 con framerate 15 fps a 320 kbps e audio in mp3 96kbps stereo a 44100Hz, il volume in uscita è aumentato con il parametro

Riga di comando:
-f avi -r 15 -vcodec libxvid -s 320x240 -b 320kb -aspect 4:3 -acodec libmp3lame -ab 96kb -ar 44100 -ac 2 -vol 640


NOTE
Questo è quello che serve per convertire i video con FFMPEG le informazioni le ho trovate a questo LINK:
http://nothings.org/remote/ffmpeg.txt
What you actually need to know to use ffmpeg:

# convert "yoursourcefile" to "youroutputfile", using 4mbit/s xvid and 192kbit/s mp3
ffmpeg -i yoursourcefile -vcodec libxvid -b 4000000 -acodec libmp3lame -ab 192000 youroutputfile

# as above, but rescale it
ffmpeg -i yoursourcefile -s 640x480 -vcodec libxvid -b 4000000 -acodec libmp3lame -ab 192000 youroutputfile

# same as first, but use VBR with quality '8' (fixed quality setting, so bitrate varies to meet that quality setting)
ffmpeg -i yoursourcefile -vcodec libxvid -qscale 8 -acodec libmp3lame -ab 192000 youroutputfile

# same as first, but pass through the audio unchanged
ffmpeg -i yoursourcefile -vcodec libxvid -b 4000000 -acodec copy youroutputfile

# as above, but no audio
ffmpeg -i yoursourcefile -vcodec libxvid -b 4000000 -an youroutputfile

# similarly, audio but no video
ffmpeg -i yoursourcefile -vn -acodec libmp3lame -ab 192000 youroutputfile

# get a list of compression formats and output file types
ffmpeg -formats


Breaking it down with each option / set of options separately (this is what the ffmpeg usage should actually look like):

Command:
ffmpeg

Input file:
-i yoursourcefile

Optional rescaling
-s 640x480

Video conversion (choose one)
-vcodec libxvid -b 4000000 (CBR bitrate=4000Mb/s)
-vcodec libxvid -qscale 8 (VBR quality=8 -- arbitrary number, try different values)
-vcodec copy
-vn

Audio conversion (choose one)
-acodec libmp3lame -ab 192000
-acodec copy
-an

Output file (this name appears on the line without an option before it)

youroutputfile



Altre informazioni su FFMPEG
A questo link
http://electron.mit.edu/~gsteele/ffmpeg/


Making movies from image files using ffmpeg/mencoder

Motivation

In my research, I often generate a sequence of images from either my experiment or from a simulation that I want to put together into a movie. Since I use linux, I wanted to do this using free software in linux, and I wanted to be able to play the movie in linux. This webpage outlines what I've learned about how to do this in linux using mencoder or ffmpeg to create high quality files that are well compressed and the play well under all operating systems.

The movies are going to be non-standard size (usually square, around 200x200 pixels for me), and have a non-standard frame rate: typcially, my movies may only be 10 frames, so I don't want to run it at 30 fps.

The details

We want to encode to some kind of relatively portable movie format. ffmpeg and mencoder both do this using the libavcodec library developed as part of ffmpeg. The codec options from the mencoder man page include:

      vcodec=
Employ the specified codec (default: mpeg4).
mjpeg
Motion JPEG
ljpeg
Lossless JPEG
h263
H.263
h263p
H.263+
mpeg4
MPEG-4 (DivX 4/5)
msmpeg4
DivX 3
msmpeg4v2
MS MPEG4v2
wmv1
Windows Media Video, version 1 (AKA WMV7)
wmv2
Windows Media Video, version 2 (AKA WMV8)
rv10
an old RealVideo codec
mpeg1video
MPEG-1 video
mpeg2video
MPEG-2 video
huffyuv
HuffYUV
asv1
ASUS Video v1
asv2
ASUS Video v2
ffv1
FFmpeg's lossless video codec

ffmpeg supports an even larger list of output codecs and container formats.

MPEG-1 and MPEG-2 streams are no good, since the frame rate is locked to 29.97 or 25 FPS. For an excellent overview of some of the common open-standard compression methods, see this page.

(Note: "open" standard only means that the specifications aren't some undocumented industry secret. It does not mean, however, that the formats are not entrenched with patent issues, which mpeg4, and even mpeg1 and mpeg2, most certainly are...You take what you can get, though.)

MJPEG would seem to be a good option, except that the files that we get seem to be incompatible with windows media player for some reason (at least with files encoded with mencoder). MJPEG supports arbitrary frame rates, but the movies files could get large if you have a lot of frames since it doesn't use temporal coding.

MPEG-4 is the best option. The mpeg4 stream can be stored in either in the .avi or .mp4 (quicktime) container file: it can support high levels of lossy compression to keep file sizes small and also supports arbitrary frame rates. It is also translates much more easily to other platforms than wmv1 or wmv2.

mencoder only supports avi file containers, which is a pity since the quicktime widgets looks nicer, and the .mp4 container format has fewer issues with compatibility (there are some fourcc issues with .avi: this container file format issue is the only reason why the mpeg4 streams inside avi files from DiVX, xvid, ..., codecs are incompatible! How stupid is that?)

Note also that mencoder (at least version 1.0pre6-3.3.3 does) will barf if we use anything other than jpeg files as our input, so we should convert all our images to jpeg's with 100% quality to avoid any quantization loss at this stage:

 $ for f in *ppm ; do convert -quality 100 $f `basename $f ppm`jpg; done 

With mencoder, we can use the vbitrate option to set the degree of lossy compression. Note that the default mpeg4 option will add a "DivX" logo to the movie when playin in windows media player, so we prefer to use one of the other mpeg4 encoders, such as msmpeg4 or msmpeg4v2. The commmand line I've used is:

mencoder "mf://*.jpg" -mf fps=10 -o test.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800 

We can also use ffmpeg directly to encode the images files into a movie. If we start with files name 001.jpg, 002.jpg, ..., we can use:

ffmpeg -r 10 -b 1800 -i %03d.jpg test1800.mp4

This works very well, and is nice because ffmpeg is included in debian! My only complaint is that with ffmpeg is that you have to be careful that all the files are named sequentially. For example, for a long time, I was missing 015.jpg, which caused it to encode only 15 frames. To get it to work, I had to rename the files so that there were no gaps in the file numbers. The .mp4 files encoded this way will play fine with quicktime under windows, which I peronally prefer over media player, and which will never show the stupid DiVX logo, since it's doesn't use the braindead avi container. (see rant above...)

How do the file sizes compare?

Image files:

Initial ppms: 6.9 MB

Initial jpgs: 8.0 MB (100% quality)

Movies (10 frames per second): avi files are encoded using mspeg4v2, mp4 files are done using the ffmpeg default (mpeg4).

1500 test1800.avi
900 test800.avi
528 test400.avi

1748 test1800.mp4
860 test800.mp4
504 test400.mp4
324 test200.mp4
264 test100.mp4

At 1800 kbits/sec, the quality is excellent, with no noticeable motion artifacts. 800 is very good, but at 400, the motion artifacts become quite noticeable.

Other useful stuff:

  • Get a thumbnail from a movie using ffmpeg:

    ffmpeg -i test.mp4 -f singlejpeg -t 0.001 test.jpg
  • Movies can be embedded in pdf documents using latex! Use the style file movie15.sty. This is really cool!

    Check out this file for an example (latex source file is available here). More info about how to do this is avilable from this website.

    The movies will play fine under windows using acroread 7.0. Under linux, if you install acrobat reader 7.0 for linux, you can save the embedded movies to disk and play them form there.

giovedì 3 settembre 2009

Interfaccia utente in Python (GUI)




Le interfacce principali che si possono utilizzare con Python per creare una maschera utente sono:

Tkinter (integrato in Python)

WxPython
PyGtk
e
PyQT
che però non è freeware

Ho scelto di utilizzare PyGtk.
Di seguito i passi da seguire per installare Python e il necessario per compilare il primo script PyGtk in Windows XP

1) Scaricare da qui l'ultima versione di Active Python e installarlo:
http://www.activestate.com/activepython/downloads/
la versione Windows (x86)

2) Scaricare da qui l'ultima versione di GTK+ bundle
http://ftp.gnome.org/pub/GNOME/binaries/win32/gtk+/
- entrare nella directory (ad esempio 2.16)
- scaricare la versione "gtk+-bundle 2.16.....zip")
- creare una cartella "c:\gtk"
- scompattare li dentro il contenuto del file "gtk+-bundle 2.16.....zip"
- impostare la path di sistema in modo che punti a "c:\gtk\bin"
-- click destro sull'icona "risorse del computer"
-- proprietà
-- scegliere il tab "Avanzate"
-- bottone "Variabili d'ambiente"
-- aggiungere in fondo alla variabile di sistema "path" il percorso "c:\gtk\bin" separandolo da precedente con un ";" = ";c:\gtk\bin"

3) Installare PyGtk
da questo link
http://www.pygtk.org/downloads.html
scaricare e installare l'ultima versione adatta al Python precedentemente installato di
- PyCairo
- PyGObject
- PyGtk

Ora possiamo scrivere il nostro primo script Python Gtk che chiamiamo TestPyGtk.py
import gtk

# This function will be called whenever you click on your button:
def click_handler(widget) :
# quit the application:
gtk.main_quit()

# Create the main window:
win = gtk.Window()

# Organize widgets in a vertical box:
vbox = gtk.VBox()
win.add(vbox)

# Make a pushbutton:
button = gtk.Button("Push me!")

# When it's clicked, call our handler:
button.connect("clicked", click_handler)

# Add it to the window:
vbox.pack_start(button)
button.show()

# Obey the window manager quit signal:
win.connect("destroy", gtk.main_quit)

vbox.show()
win.show()
gtk.main()
Salvando il file in una cartella e clicckano due volte su di esso apparirà il bottone "Push Me".

Si può anche provare il seguente script per Tkinter che dovrebbe funzionare solo installando ActivePython.

from Tkinter import * # importo il modulo
# costruisco una mia classe che gestisce la finestra
class Application(Frame):
# metodo che scrive un messaggio a video
def scrivi_messaggio(self):
self.mess["text"] = "Ciao a tutti!",
# metodo che pulisce il messaggio a video
def cancella_messaggio(self):
self.mess["text"] = "",
# metodo costruttore che crea gli oggetti grafici
def __init__(self, master=None):
f = Frame(master)
f.pack()
# crea il bottone di uscita (di colore rosso)
self.esci = Button(f)
self.esci["text"] = "QUIT"
self.esci["fg"] = "red"
self.esci["command"] = f.quit
self.esci.pack({"side": "left"})
# crea il bottone che permette di scrivere il messaggio
self.butt_mess = Button(f)
self.butt_mess["text"] = "Scrivi",
self.butt_mess["command"] = self.scrivi_messaggio
self.butt_mess.pack({"side": "left"})
# crea il bottone che permette di pulire il messaggio
self.butt_canc_mess = Button(f)
self.butt_canc_mess["text"] = "Cancella",
self.butt_canc_mess["command"] = self.cancella_messaggio
self.butt_canc_mess.pack({"side": "left"})
# crea l'oggetto grafico che contiene il messaggio
self.mess = Message(f)
self.mess["text"] = "",
self.mess.pack({"side": "left"})

# corpo principale del programma
finestra = Tk()
app = Application(finestra)
finestra.mainloop()

Di seguito alcuni i link da cui ho estratto questa documentazione e altri con informazioni utili.

http://programmazione.html.it/guide/lezione/1302/gui/
http://wiki.python.org/moin/GuiProgramming
http://boa-constructor.sourceforge.net/#wxWindows
http://www.learningpython.com/2006/05/07/creating-a-gui-using-pygtk-and-glade/
http://zetcode.com/wxpython/
http://zetcode.com/tutorials/pygtktutorial/
http://www.linuxjournal.com/article/4702
http://faq.pygtk.org/index.py?req=show&file=faq21.001.htp
http://www.python-it.org/forum/index.php?topic=2412.0
http://www.linuxplanet.com/linuxplanet/tutorials/6750/

http://ubuntuforums.org/showthread.php?t=453419
http://hackerforum.devil.it/viewtopic.php?p=90196&sid=d0f60e8467754534c42185d30c707343

http://www.python-it.org/forum/index.php?topic=809.0
http://www.swf2go.com/wiki/Default.aspx?Page=PyS60Sample_BeMyLips&AspxAutoDetectCookieSupport=1
http://www.programmazione.it/index.php?entity=eitem&idItem=40982