scan.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. scan: Estimate length (sample count) of a mpeg file and compare to length from exact scan.
  3. copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
  4. see COPYING and AUTHORS files in distribution or http://mpg123.org
  5. initially written by Thomas Orgis
  6. */
  7. /* Note the lack of error checking here.
  8. While it would be nicer to inform the user about troubles, libmpg123 is designed _not_ to bite you on operations with invalid handles , etc.
  9. You just jet invalid results on invalid operations... */
  10. #include <mpg123.h>
  11. #include <stdio.h>
  12. int main(int argc, char **argv)
  13. {
  14. mpg123_handle *m;
  15. int i;
  16. if(argc < 2)
  17. {
  18. fprintf(stderr, "\nI will give you the estimated and exact sample lengths of MPEG audio files.\n");
  19. fprintf(stderr, "\nUsage: %s <mpeg audio file list>\n\n", argv[0]);
  20. return -1;
  21. }
  22. mpg123_init();
  23. m = mpg123_new(NULL, NULL);
  24. mpg123_param(m, MPG123_RESYNC_LIMIT, -1, 0); /* New in library version 0.0.1 . */
  25. for(i = 1; i < argc; ++i)
  26. {
  27. off_t a, b;
  28. mpg123_open(m, argv[i]);
  29. a = mpg123_length(m);
  30. mpg123_scan(m);
  31. b = mpg123_length(m);
  32. mpg123_close(m);
  33. printf("File %i: estimated %li vs. scanned %li\n", i, (long)a, (long)b);
  34. }
  35. mpg123_delete(m);
  36. mpg123_exit();
  37. return 0;
  38. }