free( buf4 );
}
+void hb_set_size( hb_job_t * job, int aspect, int pixels )
+{
+ hb_title_t * title = job->title;
+
+ int croppedWidth = title->width - title->crop[2] - title->crop[3];
+ int croppedHeight = title->height - title->crop[0] - title->crop[1];
+ int croppedAspect = title->aspect * title->height * croppedWidth /
+ croppedHeight / title->width;
+ int addCrop;
+
+ if( aspect <= 0 )
+ {
+ /* Keep the best possible aspect ratio */
+ aspect = croppedAspect;
+ }
+
+ /* Crop if necessary to obtain the desired ratio */
+ memcpy( job->crop, title->crop, 4 * sizeof( int ) );
+ if( aspect < croppedAspect )
+ {
+ /* Need to crop on the left and right */
+ addCrop = croppedWidth - aspect * croppedHeight * title->width /
+ title->aspect / title->height;
+ if( addCrop & 3 )
+ {
+ addCrop = ( addCrop + 1 ) / 2;
+ job->crop[2] += addCrop;
+ job->crop[3] += addCrop;
+ }
+ else if( addCrop & 2 )
+ {
+ addCrop /= 2;
+ job->crop[2] += addCrop - 1;
+ job->crop[3] += addCrop + 1;
+ }
+ else
+ {
+ addCrop /= 2;
+ job->crop[2] += addCrop;
+ job->crop[3] += addCrop;
+ }
+ }
+ else if( aspect > croppedAspect )
+ {
+ /* Need to crop on the top and bottom */
+ /* TODO */
+ }
+
+ /* Compute a resolution from the number of pixels and aspect */
+ int i, w, h;
+ for( i = 0;; i++ )
+ {
+ w = 16 * i;
+ h = MULTIPLE_16( w * HB_ASPECT_BASE / aspect );
+ if( w * h > pixels )
+ {
+ break;
+ }
+ }
+ i--;
+ job->width = 16 * i;
+ job->height = MULTIPLE_16( 16 * i * HB_ASPECT_BASE / aspect );
+}
+
int hb_count( hb_handle_t * h )
{
return hb_list_count( h->jobs );
**********************************************************************/
- (void) awakeFromNib
{
+ NSEnumerator * enumerator;
+
/* Show the "Open DVD" interface */
fDriveDetector = [[DriveDetector alloc] initWithCallback: self
selector: @selector( openUpdateDrives: )];
[fWindow makeKeyAndOrderFront: nil];
/* NSTableView initializations */
- NSTableColumn * tableColumn = [fConvertTableView
- tableColumnWithIdentifier: @"Check"];
- NSButtonCell * buttonCell = [[[NSButtonCell alloc]
- initTextCell: @""] autorelease];
+ NSButtonCell * buttonCell;
+ NSTableColumn * tableColumn;
+ enumerator = [[fConvertTableView tableColumns] objectEnumerator];
+ while( ( tableColumn = [enumerator nextObject] ) )
+ {
+ [tableColumn setEditable: NO];
+ }
+ tableColumn = [fConvertTableView tableColumnWithIdentifier: @"Check"];
+ buttonCell = [[[NSButtonCell alloc] initTextCell: @""] autorelease];
[buttonCell setEditable: YES];
[buttonCell setButtonType: NSSwitchButton];
[tableColumn setDataCell: buttonCell];
hb_title_t * title = hb_list_item( fList, i );
hb_job_t * job = title->job;
- job->width = 320;
- for( ;; )
+ int pixels, aspect;
+ if( [fConvertFormatPopUp indexOfSelectedItem] )
{
- /* XXX */
- hb_fix_aspect( job, HB_KEEP_WIDTH );
- if( job->height == 240 )
- {
- break;
- }
- else if( job->height < 240 )
- {
- job->crop[2] += 2;
- job->crop[3] += 2;
- }
- else
- {
- job->crop[0] += 2;
- job->crop[1] += 2;
- }
+ job->vcodec = HB_VCODEC_FFMPEG;
+ job->vbitrate = 1200;
+ pixels = 230400;
+ }
+ else
+ {
+ job->vcodec = HB_VCODEC_X264;
+ job->h264_13 = 1;
+ job->vbitrate = 600;
+ pixels = 76800;
+ }
+ if( [fConvertAspectPopUp indexOfSelectedItem] )
+ {
+ aspect = -1;
}
+ else
+ {
+ aspect = 4 * HB_ASPECT_BASE / 3;
+ }
+
+ hb_set_size( job, aspect, pixels );
+
job->vquality = -1.0;
- job->vbitrate = 600;
- job->vcodec = HB_VCODEC_X264;
- job->h264_13 = 1;
job->file = strdup( [[NSString stringWithFormat:
@"%@/%p - Title %d.mp4", fConvertFolderString, self,
title->index] UTF8String] );
[fOpenFolderString release];
fOpenFolderString = [[[sheet filenames] objectAtIndex: 0] retain];
[fOpenFolderField setStringValue: [fOpenFolderString lastPathComponent]];
+ [self openGo: self];
}
- (void) openEnable: (BOOL) b
{
#define p s.param.working
case HB_STATE_WORKING:
+ {
+ NSMutableString * string = [NSMutableString
+ stringWithFormat: @"Converting: %.1f %%, %.1f fps",
+ 100.0 * p.progress, p.rate_avg];
+ if( p.hours > 0 )
+ {
+ [string appendFormat: @" (%d hours %d mins left)",
+ p.hours, p.minutes];
+ }
+ else if( p.minutes > 0 )
+ {
+ [string appendFormat: @" (%d mins %d secs left)",
+ p.minutes, p.seconds];
+ }
+ else if( p.seconds > -1 )
+ {
+ [string appendFormat: @" (%d seconds left)",
+ p.seconds];
+ }
+ [fConvertInfoString setStringValue: string];
[fConvertIndicator setIndeterminate: NO];
[fConvertIndicator setDoubleValue: 100.0 * p.progress];
break;
+ }
#undef p
case HB_STATE_WORKDONE:
[timer invalidate];
+ [fConvertInfoString setStringValue: @"Done."];
[fConvertIndicator setIndeterminate: NO];
[fConvertIndicator setDoubleValue: 0.0];
break;