media – Sam & Max http://sametmax.com Du code, du cul Tue, 10 Sep 2019 09:14:50 +0000 en-US hourly 1 https://wordpress.org/?v=4.9.7 32490438 Obtenir les infos d’une video avec ffmpeg http://sametmax.com/obtenir-les-infos-dune-video-avec-ffmpeg/ http://sametmax.com/obtenir-les-infos-dune-video-avec-ffmpeg/#comments Sun, 15 Apr 2012 10:36:46 +0000 http://sametmax.com/?p=394 Des fois il arrive qu’on ai besoin de savoir à quel type de vidéo on a affaire, ses codec videos, audio, sa résolution ou encore sa durée.

Avec ffmpeg on peut obtenir tout ça très simplement à l’aide de l’option “i”:

ffmpeg -i 1.mp4
ffmpeg version N-39738-g8274b21 Copyright (c) 2000-2012 the FFmpeg developers
  built on Apr 13 2012 13:46:48 with gcc 4.1.2 20080704 (Red Hat 4.1.2-51)
  configuration: --enable-gpl --enable-postproc 
--enable-swscale --enable-avfilter 
--enable-libmp3lame --enable-libvorbis 
--enable-libdirac --enable-libfaac 
--enable-libx264 --enable-nonfree 
--mandir=/opt/local/share/man --enable-shared --enable-pthreads
  libavutil      51. 46.100 / 51. 46.100
  libavcodec     54. 14.101 / 54. 14.101
  libavformat    54.  3.100 / 54.  3.100
  libavdevice    53.  4.100 / 53.  4.100
  libavfilter     2. 67.101 /  2. 67.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 11.100 /  0. 11.100
  libpostproc    52.  0.100 / 52.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2011-10-30 14:03:08
    encoder         : Lavf54.3.100
  Duration: 00:03:02.50, start: 0.000000, bitrate: 617 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 481 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc
    Metadata:
      creation_time   : 2011-10-30 14:03:08
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 127 kb/s
    Metadata:
      creation_time   : 2011-10-30 14:03:08
      handler_name    : SoundHandler

Si l’on veut récupérer juste une partie des infos comme la durée on peut faire comme ceci:

ffmpeg -i 1.mp4 2>&1 | gawk 'match($0, /Duration: (.[^,]*)/, matches) {print matches[1]}' 
00:03:02.50
]]>
http://sametmax.com/obtenir-les-infos-dune-video-avec-ffmpeg/feed/ 3 394