Doxygen Source Code Documentation
mri_read_mpeg.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Defines | |
#define | TDIR "m2pAFNI/" |
#define | TSIZ 6666666 |
Functions | |
void | mpeg_setup (void) |
MRI_IMARR * | mri_read_mpeg (char *fname) |
int | mri_imcount_mpeg (char *fname) |
Variables | |
int | first = 1 |
char * | tmpdir = NULL |
char * | mpeg_filter = NULL |
Define Documentation
|
Definition at line 4 of file mri_read_mpeg.c. Referenced by mpeg_setup(). |
|
Definition at line 11 of file mri_read_mpeg.c. Referenced by mri_read_mpeg(). |
Function Documentation
|
Setup mpeg reading stuff. Definition at line 16 of file mri_read_mpeg.c. References AFMALL, first, getenv(), mpeg_filter, TDIR, THD_find_executable(), THD_is_directory(), and tmpdir. Referenced by mri_imcount_mpeg(), and mri_read_mpeg().
00017 { 00018 char *pg ; 00019 if( !first ) return ; 00020 00021 first = 0 ; 00022 00023 /* get a temporary directory name */ 00024 00025 pg = getenv( "TMPDIR" ) ; 00026 if( pg == NULL || *pg == '\0' ) pg = getenv( "TEMPDIR" ) ; 00027 if( pg == NULL || *pg == '\0' ) pg = "/tmp" ; 00028 if( !THD_is_directory(pg) ) pg = "." ; 00029 tmpdir = AFMALL( char, strlen(pg)+16) ; 00030 sprintf( tmpdir , "%s/%s" , pg , TDIR ) ; 00031 00032 /* find the mpegtoppm executable */ 00033 00034 pg = THD_find_executable( "mpegtoppm" ) ; 00035 if( pg != NULL ){ 00036 mpeg_filter = AFMALL( char, strlen(pg)+strlen(tmpdir)+64 ) ; 00037 sprintf( mpeg_filter , "%s -prefix %s %%s" , pg , tmpdir ) ; 00038 } 00039 } |
|
Count number of images in an MPEG file. Must have program mpegtoppm in the path. [03 Dec 2003] Definition at line 112 of file mri_read_mpeg.c. References AFMALL, ENTRY, free, mpeg_filter, mpeg_setup(), mri_filesize(), RETURN, THD_is_directory(), THD_mkdir(), and tmpdir. Referenced by mri_imcount().
00113 { 00114 char *pg , **ff , *fn ; 00115 int ii , nf=0 ; 00116 FILE *fp ; 00117 00118 ENTRY("mri_imcount_mpeg") ; 00119 00120 /*--- check input for OK-ness ---*/ 00121 00122 if( fname == NULL || *fname == '\0' ) RETURN( 0 ); 00123 ii = mri_filesize(fname) ; 00124 if( ii <= 0 ) RETURN( 0 ); 00125 00126 mpeg_setup() ; 00127 00128 if( mpeg_filter == NULL ) RETURN( 0 ); /* can't filter? */ 00129 00130 /*--- create the filter for this file and run it to create .ppm files ---*/ 00131 00132 pg = AFMALL( char, strlen(fname)+strlen(mpeg_filter)+64) ; /* string to hold filter */ 00133 fn = AFMALL( char, strlen(fname)+32) ; 00134 sprintf(fn,"-count %s",fname) ; 00135 sprintf( pg , mpeg_filter , fn ) ; 00136 free(fn) ; 00137 THD_mkdir( tmpdir ) ; /* create the temp directory */ 00138 if( !THD_is_directory(tmpdir) ){ free(pg); RETURN(0); } /* can't? */ 00139 00140 system( pg ) ; /* run the command */ 00141 00142 /*-- open the COUNT file in the temp directory --*/ 00143 00144 sprintf( pg , "%sCOUNT" , tmpdir ) ; 00145 fp = fopen(pg,"rb") ; 00146 if( fp != NULL ){ fscanf(fp,"%d",&nf); fclose(fp); remove(pg); } 00147 remove( tmpdir ) ; free(pg) ; 00148 RETURN( nf ); 00149 } |
|
Convert an MPEG file into a set of images. Must have program mpegtoppm in the path. [03 Dec 2003] Definition at line 45 of file mri_read_mpeg.c. References ADDTO_IMARR, AFMALL, AFNI_yesenv(), DESTROY_IMARR, ENTRY, free, FREE_IMARR, IMARR_COUNT, IMARR_SUBIM, INIT_IMARR, mpeg_filter, mpeg_setup(), mri_filesize(), mri_free(), mri_isgray(), mri_read_ppm(), mri_to_byte(), RETURN, THD_is_directory(), THD_mkdir(), tmpdir, and TSIZ. Referenced by mri_read_file(), mri_read_file_delay(), THD_load_mpeg(), and THD_open_mpeg().
00046 { 00047 char *pg ; 00048 int ii , allgray=1 ; 00049 FILE *fp ; 00050 MRI_IMAGE *im ; 00051 MRI_IMARR *imar ; 00052 00053 ENTRY("mri_read_mpeg") ; 00054 00055 /*--- check input for OK-ness ---*/ 00056 00057 if( fname == NULL || *fname == '\0' ) RETURN( NULL ); 00058 ii = mri_filesize(fname) ; 00059 if( ii <= 0 ) RETURN( NULL ); 00060 00061 mpeg_setup() ; 00062 00063 if( mpeg_filter == NULL ) RETURN( NULL ); /* can't filter? */ 00064 00065 /*--- create the filter for this file and run it to create .ppm files ---*/ 00066 00067 pg = AFMALL(char, strlen(fname)+strlen(mpeg_filter)+32) ; /* string to hold filter */ 00068 sprintf( pg , mpeg_filter , fname ) ; 00069 THD_mkdir( tmpdir ) ; /* create the temp directory */ 00070 if( !THD_is_directory(tmpdir) ){ free(pg); RETURN(NULL); } /* can't? */ 00071 00072 if( ii > TSIZ ) fprintf(stderr,"++ Decoding file %s",fname) ; 00073 system( pg ) ; /* run the command */ 00074 if( ii > TSIZ ) fprintf(stderr,".\n") ; 00075 00076 /*--- read files from the temp directory ---*/ 00077 00078 INIT_IMARR(imar) ; 00079 for( ii=0 ; ; ii++ ){ /* loop until we fail to read */ 00080 sprintf( pg , "%s%06d.ppm" , tmpdir,ii ) ; 00081 im = mri_read_ppm( pg ) ; 00082 if( im == NULL ) break ; 00083 allgray = allgray && mri_isgray(im) ; 00084 remove( pg ) ; 00085 ADDTO_IMARR(imar,im) ; 00086 } 00087 remove( tmpdir ) ; free(pg) ; 00088 00089 /* if all images are grayscale, convert to byte-valued images */ 00090 00091 if( IMARR_COUNT(imar) == 0 ){ 00092 DESTROY_IMARR(imar); 00093 imar = NULL; 00094 } else if( AFNI_yesenv("AFNI_MPEG_GRAYIZE") ){ 00095 MRI_IMARR *qmar ; 00096 INIT_IMARR(qmar) ; 00097 for( ii=0 ; ii < IMARR_COUNT(imar) ; ii++ ){ 00098 im = mri_to_byte( IMARR_SUBIM(imar,ii) ) ; 00099 ADDTO_IMARR(qmar,im) ; 00100 mri_free( IMARR_SUBIM(imar,ii) ) ; 00101 } 00102 FREE_IMARR(imar) ; imar = qmar ; 00103 } 00104 00105 RETURN( imar ); 00106 } |
Variable Documentation
|
Definition at line 6 of file mri_read_mpeg.c. Referenced by mpeg_setup(). |
|
Definition at line 8 of file mri_read_mpeg.c. Referenced by mpeg_setup(), mri_imcount_mpeg(), and mri_read_mpeg(). |
|
Definition at line 7 of file mri_read_mpeg.c. Referenced by mpeg_setup(), mri_imcount_mpeg(), and mri_read_mpeg(). |