(FFmpeg) Installare OpenCV 2.3.1 su Debian

 

OpenCV è una libreria orientata alla computer vision.Originariamente è stata sviluppata da Intel, mentre attualmente è sotto licenza open source BSD. Mi sto interessando da poco ad OpenCV, partendo dall'integrazione con FFmpeg, e quindi poter provare i filtri erode,dilate e smooth., anche se ho notato che il meglio lo fa da solo. Per farla breve ho deciso d'installare OpenCV su Debian Sid, per poi ricompilare FFmpeg con l'opzione –enable=libopencv.

 

 

# apt-get install libavformat-dev libgtk2.0-dev pkg-config cmake libswscale-dev bzip2

Download OpenCV

$ tar -xvf OpenCV-2.3.1a.tar.bz2

$ cd OpenCV-2.3.1

$ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON .

 

alla fine del cmake se tutto è andato bene si avrà qualcosa del genere:

 

—   GUI:
—     GTK+ 2.x:                   YES
—     GThread:                    YES

—   Media I/O:
—     ZLib:                       YES
—     JPEG:                       TRUE
—     PNG:                        TRUE
—     TIFF:                       TRUE
—     JPEG 2000:                  TRUE
—     OpenEXR:                    YES
—     OpenNI:                     NO
—     OpenNI PrimeSensor Modules: NO
—     XIMEA:                      NO

—   Video I/O:
—     DC1394 1.x:                 NO
—     DC1394 2.x:                 YES
—     FFMPEG:                     YES
—       codec:                    YES
—       format:                   YES
—       util:                     YES
—       swscale:                  YES
—       gentoo-style:             YES
—     GStreamer:                  NO
—     UniCap:                     NO
—     PvAPI:                      NO
—     V4L/V4L2:                   FALSE/FALSE
—     Xine:                       NO

—   Other third-party libraries:
—     Use IPP:                    NO
—     Use TBB:                    NO
—     Use ThreadingFramework:     NO
—     Use Cuda:                   NO
—     Use Eigen:                  NO

—   Interfaces:
—     Python:                     YES
—     Python interpreter:         /usr/bin/python2.7 -B (ver 2.7)
—     Python numpy:               YES
—     Java:                       NO

—   Documentation:
—     Sphinx:                     NO
—     PdfLaTeX compiler:          /usr/bin/pdflatex
—     Build Documentation:        NO

—   Tests and samples:
—     Tests:                      YES
—     Examples:                   YES

—   Install path:                 /usr/local

—   cvconfig.h is in:             /home/edmond/OpenCV-2.3.1

 

dove si noterà la voce FFmpeg=YES …..continuando :

 

$ make

$ sudo make install

 

Configurare OpenCV:

 

$ sudo nano /etc/ld.so.conf.d/opencv.conf

 

ed incollare questo:

 

/usr/local/lib

 

poi:

 

$ sudo ldconfig

$ sudo gedit /etc/bash.bashrc

 

ed incollare alla fine questo:

 

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

 

ancora:

 

$ cd ~/OpenCV-2.3.1/samples/c

$ chmod +x build_all.sh

$ ./build_all.sh

 

adesso siamo pronti a ricompilare FFmpeg con l'aggiunta dell'opzione –enable=libopencv, ed usarlo con questa sintassi:

 

$ ffmpeg -i input.avi -vf ocv="dilate=5×5+2×2/cross:2" output.avi

 

per il filtro erode, vale quanto sopra.

 

$ ffmpeg -i input.avi -vf "ocv=smooth=blur_no_scale" -output.avi

 

smooth accetta "blur", "blur_no_scale", "median", "gaussian", "bilateral", di  default è "gaussian"

 

Questo è tutto per quanto riguarda OpenCV con FFmpeg.

 

 

enjoy 😉

(FFmpeg) Inserire un video in un video

 

Per ottenere un video come sopra entrano in gioco una serie di filtri con FFmpeg ( movie, scale, setpts, overlay ). La finestra con il video più piccolo ha un anticipo di 3.6 secondi sul video principale, settato dall' opzione seek_point. Le misure si riferiscono a questo video specifico. FFmpeg……J'Adore 🙂

 

$ ffmpeg -i input.avi -vf "movie=input.avi:seek_point=3.6, scale=120:-1, setpts=PTS-STARTPTS [movie]; [in] setpts=PTS-STARTPTS, [movie] overlay=330:220 [out]" output.avi

 

enjoy 😉

(Update) Ruotare video di 90-180-270 gradi con FFmpeg

 

Aggiornamento al post fatto qualche tempo fa, su come riuscire a ruotare un video di 90-180-270 gradi, usando FFmpeg. Nell'esempio precedente si usava il filtro rotate, che adesso non c'è più, ed al suo posto c'è transpose:

 

Filters:
aconvert         Convert the input audio to sample_fmt:channel_layout:packed_fmt.
aformat          Convert the input audio to one of the specified formats.
anull            Pass the source unchanged to the output.
aresample        Resample audio data.
ashowinfo        Show textual information for each audio frame.
earwax           Widen the stereo image.
pan              Remix channels with coefficients (panning)
volume           Change input volume.
abuffer          Buffer audio frames, and make them accessible to the filterchain.
aevalsrc         Generate an audio signal generated by an expression.
amovie           Read audio from a movie source.
anullsrc         Null audio source, return empty audio frames.
abuffersink      Buffer audio frames, and make them available to the end of the filter graph.
anullsink        Do absolutely nothing with the input audio.
blackframe       Detect frames that are (almost) black.
boxblur          Blur the input.
copy             Copy the input video unchanged to the output.
crop             Crop the input video to width:height:x:y.
cropdetect       Auto-detect crop size.
delogo           Remove logo from input video.
deshake          Stabilize shaky video.
drawbox          Draw a colored box on the input video.
drawtext         Draw text on top of video frames using libfreetype library.
fade             Fade in/out input video
fieldorder       Set the field order.
fifo             Buffer input images and send them when they are requested.
format           Convert the input video to one of the specified pixel formats.
frei0r           Apply a frei0r effect.
gradfun          Debands video quickly using gradients.
hflip            Horizontally flip the input video.
hqdn3d           Apply a High Quality 3D Denoiser.
lut              Compute and apply a lookup table to the RGB/YUV input video.
lutrgb           Compute and apply a lookup table to the RGB input video.
lutyuv           Compute and apply a lookup table to the YUV input video.
mp               libmpcodecs wrapper.
negate           Negate input video.
noformat         Force libavfilter not to use any of the specified pixel formats for the input to the next filter.
null             Pass the source unchanged to the output.
overlay          Overlay a video source on top of the input.
pad              Pad input image to width:height[:x:y[:color]] (default x and y: 0, default color: black).
pixdesctest      Test pixel format definitions.
scale            Scale the input video to width:height size and/or convert the image format.
select           Select frames to pass in output.
setdar           Set the frame display aspect ratio.
setpts           Set PTS for the output video frame.
setsar           Set the pixel sample aspect ratio.
settb            Set timebase for the output link.
showinfo         Show textual information for each video frame.
slicify          Pass the images of input video on to next video filter as multiple slices.
split            Pass on the input to two outputs.
transpose        Transpose input video.
unsharp          Sharpen or blur the input video.
vflip            Flip the input video vertically.
yadif            Deinterlace the input image
buffer           Buffer video frames, and make them accessible to the filterchain.
color            Provide an uniformly colored input, syntax is: [color[:size[:rate]]]
frei0r_src       Generate a frei0r source.
mandelbrot       Mandelbrot fractal renderer
movie            Read from a movie source.
mptestsrc        Generate various test pattern.
nullsrc          Null video source, return unprocessed video frames.
rgbtestsrc       Generate RGB test pattern.
testsrc          Generate test pattern.
buffersink       Buffer video frames, and make them available to the end of the filter graph.
nullsink         Do absolutely nothing with the input video.
 

 

Ruotare video a sinistra:

 

$ ffmpeg -i input.avi -vf "transpose=2" -sameq -y output.avi

 

Ruotare video verso destra:



$ ffmpeg -i input.avi -vf "transpose=3" -sameq -y output.avi

 

Ruotare sotto sopra:

 

$ ffmpeg -i input.avi -vf vflip -y output.avi

 

oppure:

 

$ avconv -i input.avi -vf "vflip" output.avi

 

enjoy 😉

(FFmpeg) Screencast seguendo solo il mouse

 

 

Modi per fare Screencast con FFmpeg, ce ne sono molti, e si possono trovare nella categoria dedicata a FFmpeg. Questo è diverso dal solito, in quanto, lo screencast viene fatto nella zona del mouse, con un'ampiezza che noi possiamo chiaramente indicare. Di seguito 2 comandi, il primo si riferisce al video sopra, il secondo invece crea una specie di box visivo intorno al mouse.

 

$ ffmpeg -f x11grab -follow_mouse 100 -r 25 -s vga -i :0.0 output.mpg

$ ffmpeg -f x11grab -follow_mouse centered -show_region 1 -r 25 -s vga -i :0.0 output.mpg

enjoy 😉
 

(FFmpeg + Filtri) Deb per Debian Squeeze/Sid

 

 

 

Condivido pacchetti deb i386 e amd64, per Debian Squeeze/Sid, di FFmpeg compilato con l'aggiunta di molti filtri. Avendo fatto alcune guide, ed altre ne farò, sui filtri di FFmpeg, mi è sembrato giusto condividerli, con quei pochi che mi leggono 🙂

 

Debian Squeeze:

nella cartella ffmpeg-squeeze si trovano i 2 pacchetti, i386 ed amd64. Leggere il file README all'interno.

 

./configure –enable-libdc1394 –prefix=/usr –enable-shared –enable-libmp3lame –enable-gpl –enable-libvorbis –enable-pthreads –enable-libfaac –enable-libxvid –enable-postproc –enable-x11grab –enable-libgsm –enable-libtheora –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libx264 –enable-libspeex –enable-nonfree –disable-stripping –enable-avfilter –enable-libdirac –disable-decoder=libdirac –enable-libschroedinger –disable-encoder=libschroedinger –enable-version3 –enable-libopenjpeg –enable-libvpx –disable-altivec –disable-armv5te –disable-armv6 –disable-vis –enable-vdpau –enable-bzlib –enable-frei0r –enable-libfreetype –enable-libvo-aacenc –enable-libaacplus –enable-filter=delogo –enable-filter=boxblur –enable-filter=frei0r –enable-filter=drawtext –enable-filter=gradfun

 

Debian Sid:

nella cartella ffmpeg-sid, si trova solo il pacchetto per i386

 

configuration: –prefix=/usr –enable-vdpau –enable-bzlib –enable-libmp3lame –enable-gpl –enable-nonfree –enable-libdirac –disable-decoder=libdirac –enable-libvorbis –enable-pthreads –enable-libfaac –enable-libxvid –enable-postproc –enable-x11grab –enable-libgsm –enable-libtheora –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libx264 –enable-libspeex –enable-nonfree –disable-stripping –enable-libschroedinger –disable-encoder=libschroedinger –enable-version3 –enable-libopenjpeg –enable-libvpx –enable-librtmp –enable-avfilter –enable-frei0r –enable-libfreetype –enable-libvo-aacenc –disable-decoder=amrnb –enable-libvo-amrwbenc –enable-libaacplus –enable-libdc1394 –disable-altivec –disable-armv5te –disable-armv6 –disable-vis –enable-filter=delogo –enable-filter=boxblur –enable-filter=frei0r –enable-filter=drawtext –enable-filter=gradfun
  libavutil    51. 30. 0 / 51. 30. 0
  libavcodec   53. 40. 0 / 53. 40. 0
  libavformat  53. 24. 0 / 53. 24. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 50. 0 /  2. 50. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…
 

(FFmpeg) e filtro drawbox

 

 

Continuando con FFmpeg ed i suoi filtri, oggi tocca a drawbox, che serve ad inserire un box colorato in un video. Di seguito il comando che ho usato per il video sopra, da usare come base di partenza.

 

$ ffmpeg -i input.mp4 -vf "drawbox=150:90:320:180:red@0.8" -sameq -y output.mp4

 

ps: il video scelto serve come stimolo…..all'apprendimento 🙂

 

enjoy 😉

(FFmpeg) Applicare filtri drawtext + fade in un solo comando

 

           

   

 

Un altro filtro che si può usare con FFmpeg oltre a quelli gia visti, è l'effetto dissolvenza (fade). Nel secondo  video ho unito in un solo comando il filtro drawtext e fade.

 

$ ffmpeg -i input.avi -vf drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='TESTO':fontcolor=white@0.8:, fade=in:0:80" -y output.avi

 

enjoy 😉

(FFmpeg) Inserire testo in un video

 

Per inserire un testo in un video usando il solito FFmpeg, bisogna avere  il filtro drawtext:

$ ffmpeg -filters | grep drawtext

 

edmond@Debianbox:~$ ffmpeg -filters | grep drawtext
ffmpeg version 0.8.7, Copyright (c) 2000-2011 the FFmpeg developers
  built on Nov 22 2011 07:59:05 with gcc 4.6.2
  configuration: –prefix=/usr –extra-cflags='-Wall -g ' –cc='ccache cc' –enable-shared –enable-libmp3lame –enable-gpl –enable-nonfree –enable-libdirac –disable-decoder=libdirac –enable-libvorbis –enable-pthreads –enable-libfaac –enable-libxvid –enable-postproc –enable-x11grab –enable-libgsm –enable-libtheora –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libx264 –enable-libspeex –enable-nonfree –disable-stripping –enable-libschroedinger –disable-encoder=libschroedinger –enable-version3 –enable-libopenjpeg –enable-libvpx –enable-librtmp –enable-avfilter –enable-frei0r –enable-libopencv –enable-libfreetype –enable-libvo-aacenc –disable-decoder=amrnb –enable-libvo-amrwbenc –enable-libaacplus –libdir=/usr/lib/i386-linux-gnu –enable-libdc1394 –disable-altivec –disable-armv5te –disable-armv6 –disable-vis –shlibdir=/usr/lib/i386-linux-gnu
  libavutil    51.  9. 1 / 51.  9. 1
  libavcodec   53.  8. 0 / 53.  8. 0
  libavformat  53.  5. 0 / 53.  5. 0
  libavdevice  53.  1. 1 / 53.  1. 1
  libavfilter   2. 23. 0 /  2. 23. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  51.  2. 0 / 51.  2. 0
drawtext         Draw text on top of video frames using libfreetype library.

il comando usato nel video è stato questo:

$ ffmpeg -i input.mp4 -vf drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='TESTO':fontcolor=white@1.0:fontsize=12:x=00: y=10" -y output.mp4

quella sopra è una buona base di partenza, poi si possono fare anche altre cose con il testo, ma quello sarà un capitolo a parte.

enjoy 😉