[Gllug] Command line tool to find video dimensions?

Tethys sta296 at astradyne.co.uk
Sat Jun 2 16:52:02 UTC 2007


Nix writes:

>> 	if [ $# -eq 0 ]; then
>
>[[ ]] preferred.

Why? Looks like two unnecessary extra characters to me...

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

What for? The output of $(command) preserves whitespace without quoting.

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

Yep. That's one of the few occasions when starting your script with
#!/bin/bash is the right thing to do.

>> 			echo "$file: unknown size"
>> 		else
>> 			echo "$file: ${width}x$height"
>
>>&2 here as well.

Huh? No. I want my output on stdout. You could argue for using stderr
when it's unable to determine the size, though.

Besides, you could always just use sed instead:

for file in "$@"
do
	echo -n "$file: "
	mplayer -identify -vo null -ao null -frames 0 "$file" 2>&1 | \
		sed -rn -e '/^ID_VIDEO_(WIDTH|HEIGHT)/ {s/.*=//;N;s/\n.*=/x/p;h}' \
				-e '$ {g;s/^$/unknown size/;T;p}'
done

Tet :-)
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list