Doxygen Source Code Documentation
sample2.c File Reference
#include <stdio.h>#include <stdlib.h>#include <inttypes.h>#include "mpeg2.h"#include "convert.h"#include <string.h>Go to the source code of this file.
Defines | |
| #define | BUFFER_SIZE 4096 |
Functions | |
| void | save_ppm (int width, int height, uint8_t *buf, int num) |
| void | sample2 (FILE *file) |
| int | main (int argc, char **argv) |
Variables | |
| char * | prefix = NULL |
| int | count = 0 |
| int | docount = 0 |
Define Documentation
|
|
|
Function Documentation
|
||||||||||||
|
Definition at line 93 of file sample2.c. References argc, count, docount, file, prefix, and sample2().
00094 {
00095 FILE * file;
00096 int iarg=1 ;
00097
00098 if( argc < 2 || strstr(argv[1],"-help") != NULL ){ /* RWCox */
00099 printf("Usage: mpegtoppm [-prefix ppp] file.mpg\n"
00100 "Writes files named 'ppp'000001.ppm, etc.\n" ) ;
00101 exit(0) ;
00102 }
00103
00104 while( iarg < argc && argv[iarg][0] == '-' ){ /* RWCox: options */
00105 if( strncmp(argv[iarg],"-c",2) == 0 ){
00106 docount = 1 ; ++iarg ; continue ;
00107 }
00108
00109 if( strncmp(argv[iarg],"-p",2) == 0 ){
00110 prefix = argv[++iarg] ; ++iarg ; continue ;
00111 }
00112 }
00113
00114 if( iarg < argc ){
00115 file = fopen (argv[iarg], "rb");
00116 if (!file) {
00117 fprintf (stderr, "Could not open file %s\n", argv[iarg]);
00118 exit (1);
00119 }
00120 } else
00121 file = stdin;
00122
00123 sample2 (file);
00124
00125 if( docount && count > 0 ){ /* RWCox */
00126 char filename[1000] = "\0" ;
00127 FILE *fp ;
00128 if( prefix != NULL ) strcpy(filename,prefix) ;
00129 strcat(filename,"COUNT") ;
00130 fp = fopen (filename, "wb");
00131 fprintf(fp,"%d\n",count) ;
00132 fclose(fp) ;
00133 }
00134
00135 return 0;
00136 }
|
|
|
Definition at line 55 of file sample2.c. References fbuf_t::buf, mpeg2_info_t::display_fbuf, file, sequence_t::height, mpeg2_buffer(), mpeg2_close(), mpeg2_convert(), mpeg2_info(), mpeg2_init(), mpeg2_parse(), save_ppm(), mpeg2_info_t::sequence, STATE_END, STATE_SEQUENCE, STATE_SLICE, uint8_t, and sequence_t::width. Referenced by main().
00056 {
00057 #define BUFFER_SIZE 4096
00058 uint8_t buffer[BUFFER_SIZE];
00059 mpeg2dec_t * mpeg2dec;
00060 const mpeg2_info_t * info;
00061 int state;
00062 int size;
00063 int framenum = 0;
00064
00065 mpeg2dec = mpeg2_init ();
00066 if (mpeg2dec == NULL)
00067 exit (1);
00068 info = mpeg2_info (mpeg2dec);
00069
00070 size = BUFFER_SIZE;
00071 do {
00072 state = mpeg2_parse (mpeg2dec);
00073 switch (state) {
00074 case -1:
00075 size = fread (buffer, 1, BUFFER_SIZE, file);
00076 mpeg2_buffer (mpeg2dec, buffer, buffer + size);
00077 break;
00078 case STATE_SEQUENCE:
00079 mpeg2_convert (mpeg2dec, convert_rgb24, NULL);
00080 break;
00081 case STATE_SLICE:
00082 case STATE_END:
00083 if (info->display_fbuf)
00084 save_ppm (info->sequence->width, info->sequence->height,
00085 info->display_fbuf->buf[0], framenum++);
00086 break;
00087 }
00088 } while (size);
00089
00090 mpeg2_close (mpeg2dec);
00091 }
|
|
||||||||||||||||||||
|
Definition at line 36 of file sample2.c. References count, prefix, and uint8_t. Referenced by sample2().
00037 {
00038 char filename[1000];
00039 FILE * ppmfile;
00040
00041 count++ ;
00042 if( docount ) return ;
00043
00044 if( prefix == NULL )
00045 sprintf (filename, "%06d.ppm", num);
00046 else
00047 sprintf (filename, "%s%06d.ppm", prefix,num);
00048 ppmfile = fopen (filename, "wb");
00049 if (!ppmfile) return;
00050 fprintf (ppmfile, "P6\n%d %d\n255\n", width, height);
00051 fwrite (buf, 3 * width, height, ppmfile);
00052 fclose (ppmfile);
00053 }
|
Variable Documentation
|
|
Definition at line 32 of file sample2.c. Referenced by main(), and save_ppm(). |
|
|
Definition at line 33 of file sample2.c. Referenced by main(). |
|
|
Definition at line 31 of file sample2.c. Referenced by main(), and save_ppm(). |