[Gllug] Command line tool to find video dimensions?

Nix nix at esperi.org.uk
Fri Jun 1 21:08:36 UTC 2007


On 1 Jun 2007, Tethys spake thusly:
> Nix writes:
>
>>Perl does support pipes you know, and grep, and stuff, natively; no need
>>for temporary files
>
> In fact, no need for perl...

I know, and I'd normally do it in the shell, but the perl was just bad
for my eyes.

> 	#!/bin/bash
>
> 	if [ $# -eq 0 ]; then

[[ ]] preferred.

> 		echo usage: $(basename "$0") "filename [...]"

>&2 there.

> 		exit 1
> 	fi
>
> 	for file in "$@"
> 	do

Ah. Different strokes. I'd use `; do' instead of a linefeed, and would probably
prefer a while $# loop with a shift in it.

> 		output=$(mplayer -identify -vo null -ao null -frames 0 "$file" 2>&1)

Quote that!

> 		width=
> 		height=
> 		[[ "$output" =~ "ID_VIDEO_WIDTH=([0-9]+)" ]] && width=${BASH_REMATCH[1]}
> 		[[ "$output" =~ "ID_VIDEO_HEIGHT=([0-9]+)" ]] && height=${BASH_REMATCH[1]}

? ... oooh, regexes! (It's not in POSIX so I forgot about it.)

Useful!

>
> 		if [ -z "$width" -o -z "$height" ]; then

I'd use [[ ]] and || personally. But that's just stylistic.

> 			echo "$file: unknown size"
> 		else
> 			echo "$file: ${width}x$height"

>&2 here as well.

> 		fi
> 	done
>
> Tet

-- 
`On a scale of one to ten of usefulness, BBC BASIC was several points ahead
 of the competition, scoring a relatively respectable zero.' --- Peter Corlett
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list