[MPlayer-dev-eng] [RFC][PATCH] New option -identify

Tobias Diedrich td at sim.uni-hannover.de
Fri Oct 18 23:57:07 CEST 2002


I use mplayer in two scripts to get file information (wxh, samplerate,
etc.). Until now I used awk to extract that data from normal mplayer
messages, but because they change every now and then, I thought it would
be nice to have an "-identify" option, which would output this
information in shell-compatible format. So here is a patch.

After applying this,
mplayer -identify <file>
will produce output similar to the following:

|Using GNU internationalization
|Original domain: messages
|Original dirname: /usr/share/locale
|Current domain: mplayer
|Current dirname: /usr/local/share/locale
|
|
|MPlayer CVS-021018-23:00-2.95.4 (C) 2000-2002 Arpad Gereoffy (see DOCS)
[...]
|Detected AVI file format!
|VIDEO:  [DIV3]  640x480  24bpp  23.98 fps  500.9 kbps (61.1 kbyte/s)
|Clip info: 
| Software: Nandub v1.0rc2
|==========================================================================
|Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
|AUDIO: 48000 Hz, 2 ch, 16 bit (0x10), ratio: 16000->192000 (128.0 kbit)
|Selected audio codec: [mp3] afm:mp3lib (mp3lib MPEG layer-2, layer-3)
|==========================================================================
|ID_VIDEO_WIDTH=640
|ID_VIDEO_HEIGHT=480
|ID_VIDEO_FPS=23.98
|ID_VIDEO_ASPECT=0.00
|ID_AUDIO_RATE=48000
|ID_AUDIO_NCH=2
|
|Exiting... (End of file)

I prefixed the lines with ID_ to make them easyly extractable with grep,
e.g. "eval `mplayer -identify <file> 2>/dev/null | grep "^ID_"`" will
set shell variables for the file's parameters.

The patch itself is really simple.

Any suggestions to make this better or in a different way ?

-- 
Tobias								PGP: 0x9AC7E0BC
This mail is made of 100% recycled bits
Now playing: Okui Masami: S-mode #1 15 - LOVE IS FIRE
-------------- next part --------------
Index: main/mplayer.c
===================================================================
RCS file: /cvsroot/mplayer/main/mplayer.c,v
retrieving revision 1.596
diff -u -r1.596 mplayer.c
--- main/mplayer.c	17 Oct 2002 15:44:41 -0000	1.596
+++ main/mplayer.c	18 Oct 2002 22:15:07 -0000
@@ -67,6 +67,7 @@
 
 int slave_mode=0;
 int verbose=0;
+int identify=0;
 static int quiet=0;
 
 #define ABS(x) (((x)>=0)?(x):(-(x)))
@@ -1146,6 +1147,20 @@
   } else
     inited_flags|=INITED_ACODEC;
   mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
+}
+
+if(identify){
+  if (sh_video) {
+    mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_WIDTH=%d\n", sh_video->disp_w);
+    mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_HEIGHT=%d\n", sh_video->disp_h);
+    mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_FPS=%5.2f\n", sh_video->fps);
+    mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_VIDEO_ASPECT=%1.2f\n", sh_video->aspect);
+  }
+  if (sh_audio) {
+    mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_RATE=%d\n", sh_audio->samplerate);
+    mp_msg(MSGT_GLOBAL,MSGL_INFO,"ID_AUDIO_NCH=%d\n", sh_audio->channels);
+  }
+  goto goto_next_file;
 }
 
 if(!sh_video) goto main; // audio-only
Index: main/cfg-mplayer.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mplayer.h,v
retrieving revision 1.173
diff -u -r1.173 cfg-mplayer.h
--- main/cfg-mplayer.h	9 Oct 2002 01:13:40 -0000	1.173
+++ main/cfg-mplayer.h	18 Oct 2002 22:15:08 -0000
@@ -378,6 +378,7 @@
 #include "cfg-common.h"
 #undef MAIN_CONF
         
+	{"identify", &identify, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
 	{"quiet", &quiet, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
 	{"noquiet", &quiet, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
 	{"verbose", &verbose, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 0, 100, NULL},
Index: main/DOCS/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/mplayer.1,v
retrieving revision 1.249
diff -u -r1.249 mplayer.1
--- main/DOCS/mplayer.1	17 Oct 2002 22:51:35 -0000	1.249
+++ main/DOCS/mplayer.1	18 Oct 2002 22:15:09 -0000
@@ -217,6 +217,9 @@
 More intense frame dropping (breaks decoding).
 Leads to image distortion!
 .TP
+.B \-identify
+Show file parameters in easy parsable format.
+.TP
 .B \-input <commands>
 This option can be used to configure certain parts of the input system.
 Paths are relative to ~/\:.mplayer/.
Index: main/DOCS/German/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/German/mplayer.1,v
retrieving revision 1.17
diff -u -r1.17 mplayer.1
--- main/DOCS/German/mplayer.1	24 Aug 2002 14:22:46 -0000	1.17
+++ main/DOCS/German/mplayer.1	18 Oct 2002 22:15:11 -0000
@@ -937,6 +937,9 @@
 .B \-hardframedrop (siehe auch \-framedrop Option)
 Intensiveres Framedropping (unterbricht die Dekodierung). F?hrt zu Bildverzerrungen!
 .TP
+.B \-identify
+Zeigt die Dateiparameter in einem leicht weiter zu verarbeitendem Format an.
+.TP
 .B \-include <Konfigurationsdatei>
 Gibt eine Konfigurationsdatei an, welche nach der normalen ausgewertet werden soll.
 .TP
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20021018/11e97cac/attachment.pgp>


More information about the MPlayer-dev-eng mailing list