1 /* $Id: Test.cpp,v 1.5 2003/10/05 14:28:40 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://beos.titer.org/handbrake/>.
5 It may be used under the terms of the GNU General Public License. */
13 void SigHandler( int signal )
18 int main( int argc, char ** argv )
22 /* Exit ASAP on Ctrl-C */
23 signal( SIGINT, SigHandler );
28 char * outputFile = NULL;
31 bool deinterlace = false;
38 /* Parse command line */
40 while( ( c = getopt( argc, argv, "vd:o:t:piw:j:k:l:m:" ) ) != -1 )
49 device = strdup( optarg );
53 outputFile = strdup( optarg );
57 titleIdx = atoi( optarg );
69 width = atoi( optarg );
73 topCrop = atoi( optarg );
77 bottomCrop = atoi( optarg );
81 leftCrop = atoi( optarg );
85 rightCrop = atoi( optarg );
93 /* Check parsed options */
94 if( !device || !outputFile )
97 "Syntax: HBTest [options] -d <device> -o <file>\n"
98 "Possible options are :\n"
99 " -v verbose output\n"
100 " -t <value> select a title (default is 1)\n"
101 " -p 2-pass encoding\n"
102 " -i deinterlace picture\n"
104 " -j <value> top cropping\n"
105 " -k <value> bottom cropping\n"
106 " -l <value> left cropping\n"
107 " -m <value> right cropping\n" );
111 /* Create the manager thread */
112 HBManager * manager = new HBManager( debug );
114 /* Tell the manager to scan the specified volume */
115 manager->ScanVolumes( device );
120 if( !manager->NeedUpdate() )
126 status = manager->GetStatus();
128 switch( status.fMode )
133 case HB_MODE_SCANNING:
134 if( !status.fScannedTitle )
136 fprintf( stderr, "Scanning %s\n",
137 status.fScannedVolume );
141 fprintf( stderr, "Scanning %s, title %d\n",
142 status.fScannedVolume,
143 status.fScannedTitle );
147 case HB_MODE_READY_TO_RIP:
150 HBTitle * title = NULL;
151 for( uint32_t i = 0; i < status.fTitleList->CountItems(); i++ )
153 title = (HBTitle*) status.fTitleList->ItemAt( i );
154 if( title->fIndex == titleIdx )
166 fprintf( stderr, "Error: unvalid title. Possible "
169 i < status.fTitleList->CountItems(); i++ )
171 title = (HBTitle*) status.fTitleList->ItemAt( i );
172 fprintf( stderr, "%d%s", title->fIndex,
173 ( i == status.fTitleList->CountItems() - 1 )
179 title->fTwoPass = twoPass;
180 title->fDeinterlace = deinterlace;
181 if( width ) title->fOutWidth = width;
182 title->fTopCrop = topCrop;
183 title->fBottomCrop = bottomCrop;
184 title->fLeftCrop = leftCrop;
185 title->fRightCrop = rightCrop;
187 HBAudio * audio = (HBAudio*) title->fAudioList->ItemAt( 0 );
189 manager->StartRip( title, audio, NULL, outputFile );
193 case HB_MODE_ENCODING:
194 fprintf( stderr, "Progress = %.2f %%, %.2f fps "
195 "(%02d:%02d:%02d remaining)\n",
196 100 * status.fPosition, status.fFrameRate,
197 status.fRemainingTime / 3600,
198 ( status.fRemainingTime % 3600 ) / 60,
199 status.fRemainingTime % 60 );
203 fprintf( stderr, "Done\n" );
207 case HB_MODE_CANCELED:
208 fprintf( stderr, "Canceled\n" );
213 fprintf( stderr, "Error\n" );
224 if( device ) free( device );
225 if( outputFile ) free( outputFile );