[MPlayer-users] -identify

Vladimir Mosgalin mosgalin at VM10124.spb.edu
Sat Mar 8 15:36:29 CET 2003


On Sat, 7 Mar 2003, matt ittigson wrote:

mi>[Automatic answer: RTFM (read DOCS, FAQ), also read DOCS/bugreports.html]
mi>i'm interested in using mplayer as a means of gathering file
mi>attributes about movies.  the -identify flag is pretty much perfect
mi>for what i'm looking for.  my question relates to exactly what some of
mi>the fields mean.

Well, for a start, take this small script of mine. It uses mplayer to
gather info about file, but this version also depends on aviinfo from
gtktalog to get number of frames (missing in mplayer :() and plaympeg
from smpeg to get total time for mpeg1 files (no workaround for mpeg2,
unfortunately), but you can strip off this (or I can send you previous
version). This script is dependent on russian language output in some
parts, I'm to lazy to recompile mplayer, but you can fix this - please
send me updated version after that.

I use this script in lesspipe.sh, running it as "less video.file".

If you have any questions, ask (better stay in this list).

-- 

Vladimir
-------------- next part --------------
#!/bin/sh

# use parsed mplayer output to get info about avi/mpg/etc

mplayer -nocache -identify "$1" -noautosub 2>/dev/null | awk -v vidname="$1" -F = '
/^?????????/ {
				flag = 1;
				split($0, ftype, " ");
				info["ftype"] = ftype[2]
				next;
			 }
/ID_FILENAME=/ { info["filename"] = $2; next}
/ID_VIDEO_FORMAT=/ { info["vformat"] = $2; next}
/ID_VIDEO_BITRATE=/ { info["vbitrate"] = $2; next}
/ID_VIDEO_WIDTH=/ { info["vwidth"] = $2; next}
/ID_VIDEO_HEIGHT=/ { info["vheight"] = $2; next}
/ID_VIDEO_FPS=/ { info["vfps"] = $2; next}
/ID_VIDEO_ASPECT=/ { info["vaspect"] = $2; next}
/ID_AUDIO_CODEC=/ { info["acodec"] = $2; next}
/ID_AUDIO_FORMAT=/ { info["aformat"] = $2; next}
/ID_AUDIO_BITRATE=/ { info["abitrate"] = $2; next}
/ID_AUDIO_RATE=/ { info["arate"] = $2; next}
/ID_AUDIO_NCH=/ { info["anch"] = $2; next}
/ID_LENGTH=/ { info["length"] = $2; next}
/^$|^=*$|???????...|Exiting...|???????? ??????? ?????|^MP3lib/ {next}

{ if (flag) print $0 }
END {
	  print "Filename: " info["filename"]
	  print "File type: " info["ftype"]
	  print "Video format: " info["vformat"]
	  print "Video bitrate: " info["vbitrate"]/1000 " kbps"
	  print "Video resolution: " info["vwidth"] "x" info["vheight"]
	  print "Video fps: " info["vfps"] " fps"
	  if (info["ftype"] == "AVI") # get number of frames using aviinfo
		  {
			avinforun = "aviinfo \"" info["filename"] "\""
			avinforun | getline avinforesult
			close(avinforun)
			split(avinforesult, frames, " ")
			info["frames"] = frames[2]
			print "Video frames: " info["frames"]
		  }
	  print "Video aspect: " info["vaspect"]
	  print "Audio codec: " info["acodec"]
	  print "Audio format: " info["aformat"]
	  print "Audio bitrate: " info["abitrate"]/1000 " kbps"
	  print "Audio rate: " info["arate"] "Hz"
	  if (info["anch"] == 1)
		  info["achdesc"] = " (mono)"
	  else
		  if (info["anch"] == 2)
			  info["achdesc"] = " (stereo)"
	  print "Audio channels: " info["anch"] " ch" info["achdesc"]
	  if (info["vformat"] == "0x10000001") # mpeg1
		  {
# currently mplayer calculates incorrect total time for mpeg1/2 files
# for mpeg1, plaympeg shows correct time, but it hangs for mpeg2 :(
			plaympegrun = "plaympeg --novideo --nosound \"" info["filename"] "\" | grep time"
			#for (a = 0; a < 4; a++)
			plaympegrun | getline plaympegresult
			close(plaympegrun)
			split(plaympegresult, size, " ")
			info["length"] = int(size[3])
		  }
	  print "Stream length: " info["length"] " s (" int(info["length"] / 3600) \
		":" int(info["length"] / 60) - int(info["length"] / 3600) * 60 ":" \
		info["length"] - int(info["length"] / 60) * 60 ")"
	  print ""
	}
'

# vim: ft=awk


More information about the MPlayer-users mailing list