martedì 29 ottobre 2013

Compressione video

Il video originale dell'intervento al Linux Day 2013 e' stato ripreso con una micro camera Go Pro a risoluzione Full HD. Il risultato e' che l'intervento della durata di circa 16 minuti corrisponde ad una occupazione su disco di circa 3.7 Gb... un po' troppo per pensare di effettuare l'upload su Youtube



Ho quindi provato a comprimere il file mediante il software ffmpeg e la seguente stringa

ffmpeg -i luca.mp4 -s 720x480 -acodec copy luca.mkv

al termine della compressione il file e' risultato essere di circa 30 Mb con una compressione di oltre un fattore 1000. La conversione e' stata fatta su un IBM T61 dual core con 2 Giga di Ram e per ogni secondo di video erano necessari circa 3-4 secondi di calcolo

Ecco l'output del programma per verificare i settaggi
-----------------------------------------------------------------
n Oct  3 2013 05:43:15 with gcc 4.8 (Debian 4.8.1-10)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --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-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libpulse --disable-mips32r2 --disable-mipsdspr1 --dis  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GOPR1892.MP4':
  Metadata:
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    creation_time   : 2013-10-26 11:49:18
  Duration: 00:16:32.17, start: 0.000000, bitrate: 30117 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], 29972 kb/s, 47.95 fps, 47.95 tbr, 720k tbn, 95.90 tbc
    Metadata:
      creation_time   : 2013-10-26 11:49:18
      handler_name    :  GoPro AVC
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:
      creation_time   : 2013-10-26 11:49:18
      handler_name    :  GoPro AAC
[libx264 @ 0x18fe4e0] using SAR=32/27
[libx264 @ 0x18fe4e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 @ 0x18fe4e0] profile High, level 3.1
[libx264 @ 0x18fe4e0] 264 - core 138 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'output.mkv':
  Metadata:
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    encoder         : Lavf54.63.104
    Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuvj420p, 720x480 [SAR 32:27 DAR 16:9], q=-1--1, 1k tbn, 47.95 tbc
    Metadata:
      creation_time   : 2013-10-26 11:49:18
      handler_name    :  GoPro AVC
    Stream #0:1(eng): Audio: aac ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, 128 kb/s
    Metadata:
      creation_time   : 2013-10-26 11:49:18
      handler_name    :  GoPro AAC
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> libx264)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=47576 fps= 27 q=-1.0 Lsize=   30650kB time=00:16:32.17 bitrate= 253.1kbits/s    
video:14525kB audio:15503kB subtitle:0 global headers:0kB muxing overhead 2.075269%
[libx264 @ 0x18fe4e0] frame I:192   Avg QP:20.59  size: 32206
[libx264 @ 0x18fe4e0] frame P:12016 Avg QP:23.02  size:   477
[libx264 @ 0x18fe4e0] frame B:35368 Avg QP:27.74  size:    84
[libx264 @ 0x18fe4e0] consecutive B-frames:  0.8%  0.1%  0.1% 99.0%
[libx264 @ 0x18fe4e0] mb I  I16..4: 13.8% 42.8% 43.4%
[libx264 @ 0x18fe4e0] mb P  I16..4:  0.1%  0.1%  0.0%  P16..4:  6.7%  1.0%  1.1%  0.0%  0.0%    skip:91.0%
[libx264 @ 0x18fe4e0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  3.7%  0.1%  0.0%  direct: 0.0%  skip:96.2%  L0:23.5% L1:75.9% BI: 0.6%
[libx264 @ 0x18fe4e0] 8x8 transform intra:42.1% inter:67.2%
[libx264 @ 0x18fe4e0] coded y,uvDC,uvAC intra: 62.6% 71.2% 40.6% inter: 0.4% 1.1% 0.0%
[libx264 @ 0x18fe4e0] i16 v,h,dc,p: 11% 23%  5% 61%
[libx264 @ 0x18fe4e0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 23% 19%  4%  6%  5%  8%  5%  6%
[libx264 @ 0x18fe4e0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 22% 11%  5%  5%  6%  6%  6%  6%
[libx264 @ 0x18fe4e0] i8c dc,h,v,p: 48% 24% 23%  5%
[libx264 @ 0x18fe4e0] Weighted P-Frames: Y:3.1% UV:0.3%
[libx264 @ 0x18fe4e0] ref P L0: 78.7%  9.0%  9.8%  2.3%  0.2%
[libx264 @ 0x18fe4e0] ref B L0: 82.7% 16.4%  0.9%
[libx264 @ 0x18fe4e0] ref B L1: 96.7%  3.3%
[libx264 @ 0x18fe4e0] kb/s:119.92
luca@debian-T61:~/Desktop$ ls
100_PANA  envi4.7.1     GOPR1892.MP4  Libri             linux_day.odp  Moddingstudio.pdf  netbeans-7.3.desktop  Nido_2013   problemi.txt~
asw-380   GOPR1891.MP4  landsat       linux blue angel  linux_day.pdf  mondiali           netbeans-c++.desktop  output.mkv  test.desktop
luca@debian-T61:~/Desktop$ ffmpeg -i GOPR1891.MP4 -s 720x480 -acodec copy output1.mkv
ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct  3 2013 05:43:15 with gcc 4.8 (Debian 4.8.1-10)
  configuration: --prefix=/usr --extra-cflags='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security ' --extra-ldflags='-Wl,-z,relro' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-nonfree --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-libvpx --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-librtmp --enable-avfilter --enable-libfreetype --enable-libvo-aacenc --disable-decoder=amrnb --enable-libvo-amrwbenc --enable-libaacplus --libdir=/usr/lib/x86_64-linux-gnu --disable-vda --enable-libbluray --enable-libcdio --enable-gnutls --enable-frei0r --enable-openssl --enable-libass --enable-libopus --enable-fontconfig --enable-libpulse --disable-mips32r2 --disable-mipsdspr1 --dis  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'GOPR1891.MP4':
  Metadata:
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    creation_time   : 2013-10-26 11:39:26
  Duration: 00:09:46.22, start: 0.000000, bitrate: 30126 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], 29975 kb/s, 47.95 fps, 47.95 tbr, 720k tbn, 95.90 tbc
    Metadata:
      creation_time   : 2013-10-26 11:39:26
      handler_name    :  GoPro AVC
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s
    Metadata:
      creation_time   : 2013-10-26 11:39:26
      handler_name    :  GoPro AAC
[libx264 @ 0x1a9e4e0] using SAR=32/27
[libx264 @ 0x1a9e4e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 @ 0x1a9e4e0] profile High, level 3.1
[libx264 @ 0x1a9e4e0] 264 - core 138 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, matroska, to 'output1.mkv':
  Metadata:
    major_brand     : avc1
    minor_version   : 0
    compatible_brands: avc1isom
    encoder         : Lavf54.63.104
    Stream #0:0(eng): Video: h264 (H264 / 0x34363248), yuvj420p, 720x480 [SAR 32:27 DAR 16:9], q=-1--1, 1k tbn, 47.95 tbc
    Metadata:
      creation_time   : 2013-10-26 11:39:26
      handler_name    :  GoPro AVC
    Stream #0:1(eng): Audio: aac ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, 127 kb/s
    Metadata:
      creation_time   : 2013-10-26 11:39:26
      handler_name    :  GoPro AAC
Stream mapping:
  Stream #0:0 -> #0:0 (h264 -> libx264)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=25277 fps= 27 q=31.0 size=   19809kB time=00:08:47.21 bitrate= 307.8kbits/s