1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* $Id: test.c,v 1.7 2003/11/13 01:18:52 titer Exp $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.m0k.org/>.
It may be used under the terms of the GNU General Public License. */
#include <signal.h>
#include "HandBrake.h"
volatile int die;
void SigHandler( int signal )
{
die = 1;
}
int main( int argc, char ** argv )
{
int c;
HBHandle * h;
HBStatus s;
/* Default values */
int debug = 1;
char * device = NULL;
char * file = NULL;
int titleIdx = 1;
int audio1Idx = 1;
int audio2Idx = 0;
int twoPass = 0;
int deinterlace = 0;
int width = 0;
int topCrop = 0;
int bottomCrop = 0;
int leftCrop = 0;
int rightCrop = 0;
int cpuCount = 0;
int vBitrate = 1024;
int aBitrate = 128;
int xvid = 0;
die = 0;
/* Exit ASAP on Ctrl-C */
signal( SIGINT, SigHandler );
fprintf( stderr, "Welcome to HandBrake " VERSION "\n" );
/* Parse command line */
while( ( c = getopt( argc, argv,
"qd:o:t:a:b:piw:j:k:l:m:c:e:f:x" ) ) != -1 )
{
switch( c )
{
case 'q':
debug = 0;
break;
case 'd':
device = strdup( optarg );
break;
case 'o':
file = strdup( optarg );
break;
case 't':
titleIdx = atoi( optarg );
break;
case 'a':
audio1Idx = atoi( optarg );
break;
case 'b':
audio2Idx = atoi( optarg );
break;
case 'p':
twoPass = 1;
break;
case 'i':
deinterlace = 1;
break;
case 'w':
width = atoi( optarg );
break;
case 'j':
topCrop = atoi( optarg );
break;
case 'k':
bottomCrop = atoi( optarg );
break;
case 'l':
leftCrop = atoi( optarg );
break;
case 'm':
rightCrop = atoi( optarg );
break;
case 'c':
cpuCount = atoi( optarg );
break;
case 'e':
vBitrate = atoi( optarg );
break;
case 'f':
aBitrate = atoi( optarg );
break;
case 'x':
xvid = 1;
break;
default:
break;
}
}
/* Check parsed options */
if( !device || !file )
{
fprintf( stderr,
"Syntax: HBTest [options] -d <device> -o <file>\n"
"Possible options are :\n"
" -q quiet output\n"
" -t <value> select a title (default is 1)\n"
" -a <value> primary audio channel (default is 1)\n"
" -b <value> secondary audio channel (default is none)\n"
" -p 2-pass encoding\n"
" -i deinterlace picture\n"
" -w output width\n"
" -j <value> top cropping\n"
" -k <value> bottom cropping\n"
" -l <value> left cropping\n"
" -m <value> right cropping\n"
" -c <value> CPU count (default: autodetected)\n"
" -e <value> Video bitrate (default is 1024)\n"
" -f <value> Audio bitrate (default is 128)\n"
" -x Use XviD instead of Ffmpeg\n" );
return 1;
}
/* Create the lihb thread & init things */
h = HBInit( debug, cpuCount );
while( !die )
{
HBSnooze( 100000 );
if( !HBGetStatus( h, &s ) )
continue;
switch( s.mode )
{
case HB_MODE_UNDEF:
/* Will never happen */
break;
case HB_MODE_NEED_DEVICE:
/* Feed libhb with a DVD to scan */
HBScanDevice( h, device, titleIdx );
break;
case HB_MODE_SCANNING:
/* s.scannedTitle: title scanned at the moment */
break;
case HB_MODE_INVALID_DEVICE:
die = 1;
break;
case HB_MODE_READY_TO_RIP:
{
HBAudio * audio1, * audio2;
HBTitle * title = HBListItemAt( s.titleList, 0 );
title->file = strdup( file );
title->twoPass = twoPass;
title->deinterlace = deinterlace;
if( width ) title->outWidth = width;
title->topCrop = topCrop;
title->bottomCrop = bottomCrop;
title->leftCrop = leftCrop;
title->rightCrop = rightCrop;
title->bitrate = vBitrate;
title->codec = xvid ? HB_CODEC_XVID : HB_CODEC_FFMPEG;
audio1 = HBListItemAt( title->audioList,
audio1Idx - 1 );
audio2 = HBListItemAt( title->audioList,
audio2Idx - 1 );
if( audio1 ) audio1->outBitrate = aBitrate;
if( audio2 ) audio2->outBitrate = aBitrate;
HBStartRip( h, title, audio1, audio2 );
break;
}
case HB_MODE_ENCODING:
/* s.position : current progress (0.0->1.0)
s.frameRate : average framerate
s.remainingTime: ... (in seconds) */
break;
case HB_MODE_DONE:
die = 1;
break;
case HB_MODE_CANCELED:
die = 1;
break;
case HB_MODE_ERROR:
/* s.error: error code */
die = 1;
break;
default:
break;
}
}
HBClose( &h );
if( device ) free( device );
if( file ) free( file );
return 0;
}
|