Commit 6571bac7 authored by conrad's avatar conrad

oggzinfo: use human-readable byte-length outputs (kB, MB, GB)


git-svn-id: http://svn.annodex.net/liboggz/trunk@1084 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent c825b51e
......@@ -183,6 +183,29 @@ ot_page_identify (const ogg_page * og, char ** info)
return ret;
}
/*
* Print a number of bytes to 3 significant figures
* using standard abbreviations (GB, MB, kB, byte[s])
*/
int
ot_print_bytes (long nr_bytes)
{
if (nr_bytes > (1L<<30)) {
return printf ("%0.3f GB",
(double)nr_bytes / (1024.0 * 1024.0 * 1024.0));
} else if (nr_bytes > (1L<<20)) {
return printf ("%0.3f MB",
(double)nr_bytes / (1024.0 * 1024.0));
} else if (nr_bytes > (1L<<10)) {
return printf ("%0.3f kB",
(double)nr_bytes / (1024.0));
} else if (nr_bytes == 1) {
return printf ("1 byte");
} else {
return printf ("%ld bytes", nr_bytes);
}
}
int
ot_print_time (double seconds)
{
......
......@@ -38,6 +38,12 @@
const char *
ot_page_identify (const ogg_page * og, char ** info);
/*
* Print a number of bytes to 3 significant figures
* using standard abbreviations (GB, MB, kB, byte[s])
*/
int ot_print_bytes (long nr_bytes);
int ot_print_time (double seconds);
#endif /* __OGGZ_TOOLS_H__ */
......@@ -155,6 +155,15 @@ oi_bitrate (long bytes, ogg_int64_t ms)
static void
oi_stats_print (OI_Info * info, OI_Stats * stats, char * label)
{
printf ("\t%s-Length-Maximum: ", label);
ot_print_bytes (stats->length_max);
putchar ('\n');
printf ("\t%s-Length-StdDev: ", label);
ot_print_bytes (stats->length_stddev);
putchar ('\n');
#if 0
printf ("\t%s-Length-Maximum: %ld bytes\n", label, stats->length_max);
/*printf ("\t%s-Length-Average: %ld bytes\n", label, stats->length_avg);*/
printf ("\t%s-Length-StdDev: %.0f bytes\n", label, stats->length_stddev);
......@@ -162,6 +171,7 @@ oi_stats_print (OI_Info * info, OI_Stats * stats, char * label)
printf ("\tRange: [%ld - %ld] bytes, Std.Dev. %.3f bytes\n",
stats->length_min, stats->length_max, stats->length_stddev);
*/
#endif
}
/* oggzinfo_trackinfo_print() */
......@@ -480,7 +490,9 @@ main (int argc, char ** argv)
putchar ('\n');
if (show_length) {
printf ("Content-Length: %ld bytes\n", info.length_total);
fputs ("Content-Length: ", stdout);
ot_print_bytes (info.length_total);
putchar ('\n');
}
if (show_bitrate) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment