You could access this page securely.

API documentation for libmpg123, libout123, and libsyn123

Note: This API doc is automatically generated from the current development version that you can get via Subversion or as a daily snapshot from http://mpg123.org/snapshot. There may be differences (additions) compared to the latest stable release. See NEWS.libmpg123, NEWS.libout123, NEWS.libsyn123, and the overall NEWS file on libmpg123 versions and important changes between them.
Let me emphasize that the policy for the lib*123 family is to always stay backwards compatible -- only additions are planned (and it's not yet planned to change the plans;-).
extract_frames.c
Go to the documentation of this file.
1 /*
2  extract_frams: utlize the framebyframe API and mpg123_framedata to extract the MPEG frames out of a stream (strip off anything else).
3 
4  copyright 2011 by the mpg123 project - free software under the terms of the LGPL 2.1
5  see COPYING and AUTHORS files in distribution or http://mpg123.org
6  initially written by Thomas Orgis
7 */
8 
9 #include <mpg123.h>
10 
11 /* unistd.h is not available under MSVC,
12  io.h defines the read and write functions */
13 #ifndef _MSC_VER
14 #include <unistd.h>
15 #else
16 #include <io.h>
17 #endif
18 
19 #include <stdio.h>
20 #include <string.h>
21 
22 int do_work(mpg123_handle *m);
23 
24 int main(int argc, char **argv)
25 {
26  int ret = 0;
27  mpg123_handle *m;
28 
29  mpg123_init();
30  m = mpg123_new(NULL, &ret);
31 
32  if(m == NULL)
33  {
34  fprintf(stderr, "Cannot create handle: %s", mpg123_plain_strerror(ret));
35  }
36  else
37  {
38  fprintf(stderr, "I'll take your dirty MPEG audio from standard input and will write the extracted pure MPEG data to standard output.\n");
39  if(argc > 1 && strcmp(argv[1], "--noinfo") == 0)
40  {
41  fprintf(stderr, "Enabling parsing/consuming of the Info frame so that it will not appear in output.\n");
43  }
44  else
45  {
46  fprintf(stderr, "If you'd have given --noinfo as argument, I would omit a LAME/Xing info frame.\n");
48  }
49  if(ret == 0) ret = do_work(m);
50 
51  if(ret != 0) fprintf(stderr, "Some error occured: %s\n", mpg123_strerror(m));
52 
53 
54  mpg123_delete(m); /* Closes, too. */
55  }
56  mpg123_exit();
57 
58  return ret;
59 }
60 
61 int do_work(mpg123_handle *m)
62 {
63  int ret;
64  size_t count = 0;
65  ret = mpg123_open_fd(m, STDIN_FILENO);
66  if(ret != MPG123_OK) return ret;
67 
68  while( (ret = mpg123_framebyframe_next(m)) == MPG123_OK || ret == MPG123_NEW_FORMAT )
69  {
70  unsigned long header;
71  unsigned char *bodydata;
72  size_t bodybytes;
73  if(mpg123_framedata(m, &header, &bodydata, &bodybytes) == MPG123_OK)
74  {
75  /* Need to extract the 4 header bytes from the native storage in the correct order. */
76  unsigned char hbuf[4];
77  int i;
78  for(i=0; i<4; ++i) hbuf[i] = (unsigned char) ((header >> ((3-i)*8)) & 0xff);
79 
80  /* Now write out both header and data, fire and forget. */
81  write(STDOUT_FILENO, hbuf, 4);
82  write(STDOUT_FILENO, bodydata, bodybytes);
83  fprintf(stderr, "%zu: header 0x%08lx, %zu body bytes\n", ++count, header, bodybytes);
84  }
85  }
86 
87  if(ret != MPG123_DONE)
88  fprintf(stderr, "Some error occured (non-fatal?): %s\n", mpg123_strerror(m));
89 
90  fprintf(stderr, "Done with %zu MPEG frames.\n", count);
91 
92  return 0;
93 }
struct mpg123_handle_struct mpg123_handle
Definition: mpg123.h:132
MPG123_EXPORT int mpg123_framebyframe_next(mpg123_handle *mh)
MPG123_EXPORT void mpg123_exit(void)
MPG123_EXPORT int mpg123_framedata(mpg123_handle *mh, unsigned long *header, unsigned char **bodydata, size_t *bodybytes)
MPG123_EXPORT const char * mpg123_strerror(mpg123_handle *mh)
MPG123_EXPORT const char * mpg123_plain_strerror(int errcode)
MPG123_EXPORT int mpg123_init(void)
MPG123_EXPORT void mpg123_delete(mpg123_handle *mh)
MPG123_EXPORT int mpg123_param(mpg123_handle *mh, enum mpg123_parms type, long value, double fvalue)
MPG123_EXPORT int mpg123_open_fd(mpg123_handle *mh, int fd)
MPG123_EXPORT mpg123_handle * mpg123_new(const char *decoder, int *error)
Hopefully valid HTML! Valid CSS!