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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
/* HBJob+UIAdditions.m $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#import "HBJob+UIAdditions.h"
#import "HBAttributedStringAdditions.h"
#import "HBTitle.h"
#import "HBJob.h"
#import "HBAudioTrack.h"
#import "HBAudioDefaults.h"
#import "HBSubtitlesTrack.h"
#import "HBPicture+UIAdditions.h"
#import "HBFilters+UIAdditions.h"
#include "hb.h"
// Text Styles
static NSMutableParagraphStyle *ps;
static NSDictionary *detailAttr;
static NSDictionary *detailBoldAttr;
static NSDictionary *titleAttr;
static NSDictionary *shortHeightAttr;
@implementation HBJob (UIAdditions)
- (BOOL)mp4OptionsEnabled
{
return ((self.container & HB_MUX_MASK_MP4) != 0);
}
+ (NSSet<NSString *> *)keyPathsForValuesAffectingMp4OptionsEnabled
{
return [NSSet setWithObjects:@"container", nil];
}
- (BOOL)mp4iPodCompatibleEnabled
{
return ((self.container & HB_MUX_MASK_MP4) != 0) && (self.video.encoder & HB_VCODEC_H264_MASK);
}
+ (NSSet<NSString *> *)keyPathsForValuesAffectingMp4iPodCompatibleEnabled
{
return [NSSet setWithObjects:@"container", @"video.encoder", nil];
}
- (NSArray *)angles
{
NSMutableArray *angles = [NSMutableArray array];
for (int i = 1; i <= self.title.angles; i++)
{
[angles addObject:[NSString stringWithFormat: @"%d", i]];
}
return angles;
}
- (NSArray *)containers
{
NSMutableArray *containers = [NSMutableArray array];
for (const hb_container_t *container = hb_container_get_next(NULL);
container != NULL;
container = hb_container_get_next(container))
{
NSString *title = nil;
if (container->format & HB_MUX_MASK_MP4)
{
title = NSLocalizedString(@"MP4 File", @"");
}
else if (container->format & HB_MUX_MASK_MKV)
{
title = NSLocalizedString(@"MKV File", @"");
}
else
{
title = @(container->name);
}
[containers addObject:title];
}
return [containers copy];
}
#pragma mark - Attributed description
- (void)initStyles
{
if (!ps)
{
// Attributes
ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
ps.headIndent = 88.0;
ps.paragraphSpacing = 1.0;
ps.tabStops = @[[[NSTextTab alloc] initWithType:
NSRightTabStopType location: 88],
[[NSTextTab alloc] initWithType:
NSLeftTabStopType location: 90]];
detailAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont smallSystemFontSize]],
NSParagraphStyleAttributeName: ps};
detailBoldAttr = @{NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont smallSystemFontSize]],
NSParagraphStyleAttributeName: ps};
titleAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]],
NSParagraphStyleAttributeName: ps};
shortHeightAttr = @{NSFontAttributeName: [NSFont systemFontOfSize:2.0]};
}
}
- (NSAttributedString *)titleAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
// Job name
[attrString appendString:self.description withAttributes:titleAttr];
// Range type
NSString *startStopString = @"";
if (self.range.type == HBRangeTypeChapters)
{
startStopString = (self.range.chapterStart == self.range.chapterStop) ?
[NSString stringWithFormat:@"Chapter %d", self.range.chapterStart + 1] :
[NSString stringWithFormat:@"Chapters %d through %d", self.range.chapterStart + 1, self.range.chapterStop + 1];
}
else if (self.range.type == HBRangeTypeSeconds)
{
startStopString = [NSString stringWithFormat:@"Seconds %d through %d", self.range.secondsStart, self.range.secondsStop];
}
else if (self.range.type == HBRangeTypeFrames)
{
startStopString = [NSString stringWithFormat:@"Frames %d through %d", self.range.frameStart, self.range.frameStop];
}
NSMutableString *passesString = [NSMutableString string];
// check to see if our first subtitle track is Foreign Language Search, in which case there is an in depth scan
if (self.subtitles.tracks.firstObject.sourceTrackIdx == 1)
{
[passesString appendString:@"1 Foreign Language Search Pass - "];
}
if (self.video.qualityType != 1 && self.video.twoPass == YES)
{
if (self.video.turboTwoPass == YES)
{
[passesString appendString:@"2 Video Passes First Turbo"];
}
else
{
[passesString appendString:@"2 Video Passes"];
}
}
if (passesString.length)
{
[attrString appendString:[NSString stringWithFormat:@" (Title %d, %@, %@) ▸ %@\n",
self.titleIdx, startStopString, passesString, self.outputFileName]
withAttributes:detailAttr];
}
else
{
[attrString appendString:[NSString stringWithFormat:@" (Title %d, %@) ▸ %@\n",
self.titleIdx, startStopString, self.outputFileName]
withAttributes:detailAttr];
}
return attrString;
}
- (NSAttributedString *)presetAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
[attrString appendString:@"\tPreset: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:self.presetName withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
return attrString;
}
- (NSAttributedString *)formatAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
NSMutableString *options = [NSMutableString string];
[options appendString:@(hb_container_get_name(self.container))];
if (self.chaptersEnabled)
{
[options appendString:@", Chapter Markers"];
}
if ((self.container & HB_MUX_MASK_MP4) && self.mp4HttpOptimize)
{
[options appendString:@", Web Optimized"];
}
if ((self.container & HB_MUX_MASK_MP4) && self.mp4iPodCompatible)
{
[options appendString:@", iPod 5G Support"];
}
if ([options hasPrefix:@", "])
{
[options deleteCharactersInRange:NSMakeRange(0, 2)];
}
[attrString appendString:@"\tFormat: \t" withAttributes:detailBoldAttr];
[attrString appendString:options withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
return attrString;
}
- (NSAttributedString *)destinationAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
[attrString appendString:@"\tDestination: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:self.completeOutputURL.path withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
return attrString;
}
- (NSAttributedString *)pictureAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
NSString *pictureInfo = self.picture.summary;
if (self.picture.keepDisplayAspect)
{
pictureInfo = [pictureInfo stringByAppendingString:@" Keep Aspect Ratio"];
}
[attrString appendString:@"\tPicture: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:pictureInfo withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
return attrString;
}
- (NSAttributedString *)filtersAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
NSMutableString *summary = [NSMutableString string];
HBFilters *filters = self.filters;
// Detelecine
if (![filters.detelecine isEqualToString:@"off"])
{
if ([filters.detelecine isEqualToString:@"custom"])
{
[summary appendFormat:@", Detelecine (%@)", filters.detelecineCustomString];
}
else
{
[summary appendFormat:@", Detelecine (%@)", [[[HBFilters detelecinePresetsDict] allKeysForObject:filters.detelecine] firstObject]];
}
}
else if (![filters.deinterlace isEqualToString:@"off"])
{
// Deinterlace or Decomb
NSString *type = [[[HBFilters deinterlaceTypesDict] allKeysForObject:filters.deinterlace] firstObject];
if ([filters.deinterlacePreset isEqualToString:@"custom"])
{
[summary appendFormat:@", %@ (%@)", type, filters.deinterlaceCustomString];
}
else
{
if ([filters.deinterlace isEqualToString:@"decomb"])
{
[summary appendFormat:@", %@ (%@)", type, [[[HBFilters decombPresetsDict] allKeysForObject:filters.deinterlacePreset] firstObject]];
}
else if ([filters.deinterlace isEqualToString:@"deinterlace"])
{
[summary appendFormat:@", %@ (%@)", type, [[[HBFilters deinterlacePresetsDict] allKeysForObject:filters.deinterlacePreset] firstObject]];
}
}
}
// Deblock
if (filters.deblock > 0)
{
[summary appendFormat:@", Deblock (%d)", filters.deblock];
}
// Denoise
if (![filters.denoise isEqualToString:@"off"])
{
[summary appendFormat:@", Denoise (%@", [[[HBFilters denoiseTypesDict] allKeysForObject:filters.denoise] firstObject]];
if (![filters.denoisePreset isEqualToString:@"custom"])
{
[summary appendFormat:@", %@", [[[HBFilters denoisePresetDict] allKeysForObject:filters.denoisePreset] firstObject]];
if ([filters.denoise isEqualToString:@"nlmeans"])
{
[summary appendFormat:@", %@", [[[HBFilters nlmeansTunesDict] allKeysForObject:filters.denoiseTune] firstObject]];
}
}
else
{
[summary appendFormat:@", %@", filters.denoiseCustomString];
}
[summary appendString:@")"];
}
// Sharpen
if (![filters.sharpen isEqualToString:@"off"])
{
[summary appendFormat:@", Sharpen (%@", [[[HBFilters sharpenTypesDict] allKeysForObject:filters.sharpen] firstObject]];
if (![filters.sharpenPreset isEqualToString:@"custom"])
{
[summary appendFormat:@", %@", [[[HBFilters sharpenPresetDict] allKeysForObject:filters.sharpenPreset] firstObject]];
if ([filters.sharpen isEqualToString:@"unsharp"])
{
[summary appendFormat:@", %@", [[[HBFilters sharpenTunesDict] allKeysForObject:filters.sharpenTune] firstObject]];
}
else if ([filters.sharpen isEqualToString:@"lapsharp"])
{
[summary appendFormat:@", %@", [[[HBFilters sharpenTunesDict] allKeysForObject:filters.sharpenTune] firstObject]];
}
}
else
{
[summary appendFormat:@", %@", filters.sharpenCustomString];
}
[summary appendString:@")"];
}
// Grayscale
if (filters.grayscale)
{
[summary appendString:@", Grayscale"];
}
if ([summary hasPrefix:@", "])
{
[summary deleteCharactersInRange:NSMakeRange(0, 2)];
}
// Optional String for Picture Filters
if (summary.length)
{
[attrString appendString:@"\tFilters: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:summary withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
}
return attrString;
}
- (NSAttributedString *)videoAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
NSMutableString *videoInfo = [NSMutableString string];
const char *encoderName = hb_video_encoder_get_name(self.video.encoder);
[videoInfo appendFormat:@"Encoder: %@, ", encoderName ? @(encoderName) : @"Unknown"];
[videoInfo appendString:@"Framerate: "];
if (self.video.frameRate == 0)
{
if (self.video.frameRateMode == 0)
{
// we are using same as source with vfr
[videoInfo appendFormat:@"Same as source (variable)"];
}
else
{
[videoInfo appendFormat:@"Same as source (constant)"];
}
}
else
{
// we have a specified, constant framerate
if (self.video.frameRateMode == 0)
{
[videoInfo appendFormat:@"Peak %@ (may be lower)", @(hb_video_framerate_get_name(self.video.frameRate))];
}
else
{
[videoInfo appendFormat:@"Peak %@ (constant frame rate)", @(hb_video_framerate_get_name(self.video.frameRate))];
}
}
if (self.video.qualityType == 0) // ABR
{
[videoInfo appendFormat:@", Bitrate: %d kbps", self.video.avgBitrate];
}
else // CRF
{
[videoInfo appendFormat:@", Constant Quality: %.2f %s" ,self.video.quality, hb_video_quality_get_name(self.video.encoder)];
}
[attrString appendString:@"\tVideo: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:videoInfo withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
if (hb_video_encoder_get_presets(self.video.encoder) != NULL)
{
NSMutableString *encoderPresetInfo = [NSMutableString string];
if (self.video.advancedOptions)
{
// we are using the old advanced panel
if (self.video.videoOptionExtra.length)
{
[encoderPresetInfo appendString:self.video.videoOptionExtra];
}
else
{
[encoderPresetInfo appendString:@"default settings"];
}
}
else
{
// we are using the x264 system
[encoderPresetInfo appendFormat:@"Preset: %@", self.video.preset];
if (self.video.tune.length || self.video.fastDecode)
{
[encoderPresetInfo appendString:@", Tune: "];
if (self.video.tune.length)
{
[encoderPresetInfo appendString:self.video.tune];
}
if (self.video.fastDecode)
{
[encoderPresetInfo appendString:@" - fastdecode"];
}
}
if (self.video.videoOptionExtra.length)
{
[encoderPresetInfo appendFormat:@", Options: %@", self.video.videoOptionExtra];
}
if (self.video.profile.length)
{
[encoderPresetInfo appendFormat:@", Profile: %@", self.video.profile];
}
if (self.video.level.length)
{
[encoderPresetInfo appendFormat:@", Level: %@", self.video.level];
}
}
[attrString appendString:@"\tVideo Options: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:encoderPresetInfo withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
}
else
{
// we are using libavcodec
NSString *lavcInfo = @"";
if (self.video.videoOptionExtra.length)
{
lavcInfo = self.video.videoOptionExtra;
}
else
{
lavcInfo = @"default settings";
}
[attrString appendString:@"\tVideo Options: " withAttributes:detailBoldAttr];
[attrString appendString:@"\t" withAttributes:detailAttr];
[attrString appendString:lavcInfo withAttributes:detailAttr];
[attrString appendString:@"\n" withAttributes:detailAttr];
}
return attrString;
}
- (NSAttributedString *)audioAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
BOOL secondLine = NO;
[attrString appendString:@"\tAudio: " withAttributes: detailBoldAttr];
for (HBAudioTrack *audioTrack in self.audio.tracks)
{
if (audioTrack.isEnabled)
{
NSMutableString *detailString = [NSMutableString stringWithFormat:@"%@ ▸ Encoder: %@",
self.audio.sourceTracks[audioTrack.sourceTrackIdx][keyAudioTrackName],
@(hb_audio_encoder_get_name(audioTrack.encoder))];
if ((audioTrack.encoder & HB_ACODEC_PASS_FLAG) == 0)
{
[detailString appendFormat:@", Mixdown: %@, Samplerate: %@, Bitrate: %d kbps",
@(hb_mixdown_get_name(audioTrack.mixdown)),
audioTrack.sampleRate ? [NSString stringWithFormat:@"%@ khz", @(hb_audio_samplerate_get_name(audioTrack.sampleRate))] : @"Auto",
audioTrack.bitRate];
if (0.0 < audioTrack.drc)
{
[detailString appendFormat:@", DRC: %.2f", audioTrack.drc];
}
if (0.0 != audioTrack.gain)
{
[detailString appendFormat:@", Gain: %.2f", audioTrack.gain];
}
}
[attrString appendString:@"\t" withAttributes: detailAttr];
if (secondLine)
{
[attrString appendString:@"\t" withAttributes: detailAttr];
}
else
{
secondLine = YES;
}
[attrString appendString:detailString withAttributes: detailAttr];
[attrString appendString:@"\n" withAttributes: detailAttr];
}
}
return attrString;
}
- (NSAttributedString *)subtitlesAttributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
BOOL secondLine = NO;
[attrString appendString:@"\tSubtitles: " withAttributes:detailBoldAttr];
for (HBSubtitlesTrack *track in self.subtitles.tracks)
{
// Ignore the none track.
if (track.isEnabled)
{
NSMutableString *detailString = [NSMutableString string];
// remember that index 0 of Subtitles can contain "Foreign Audio Search
[detailString appendString:self.subtitles.sourceTracks[track.sourceTrackIdx][@"keySubTrackName"]];
if (track.forcedOnly)
{
[detailString appendString:@", Forced Only"];
}
if (track.burnedIn)
{
[detailString appendString:@", Burned In"];
}
if (track.def)
{
[detailString appendString:@", Default"];
}
[attrString appendString:@"\t" withAttributes: detailAttr];
if (secondLine)
{
[attrString appendString:@"\t" withAttributes: detailAttr];
}
else
{
secondLine = YES;
}
[attrString appendString:detailString withAttributes: detailAttr];
[attrString appendString:@"\n" withAttributes: detailAttr];
}
}
return attrString;
}
- (NSAttributedString *)attributedDescription
{
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init];
[self initStyles];
@autoreleasepool
{
[attrString appendAttributedString:[self titleAttributedDescription]];
[attrString appendAttributedString:[self presetAttributedDescription]];
[attrString appendAttributedString:[self formatAttributedDescription]];
[attrString appendAttributedString:[self destinationAttributedDescription]];
[attrString appendAttributedString:[self pictureAttributedDescription]];
[attrString appendAttributedString:[self filtersAttributedDescription]];
[attrString appendAttributedString:[self videoAttributedDescription]];
if (self.audio.countOfTracks > 1)
{
[attrString appendAttributedString:[self audioAttributedDescription]];
}
if (self.subtitles.countOfTracks > 1)
{
[attrString appendAttributedString:[self subtitlesAttributedDescription]];
}
}
[attrString deleteCharactersInRange:NSMakeRange(attrString.length - 1, 1)];
return attrString;
}
@end
@implementation HBContainerTransformer
+ (Class)transformedValueClass
{
return [NSString class];
}
- (id)transformedValue:(id)value
{
int container = [value intValue];
if (container & HB_MUX_MASK_MP4)
{
return NSLocalizedString(@"MP4 File", @"");
}
else if (container & HB_MUX_MASK_MKV)
{
return NSLocalizedString(@"MKV File", @"");
}
else
{
const char *name = hb_container_get_name(container);
if (name)
{
return @(name);
}
else
{
return nil;
}
}
}
+ (BOOL)allowsReverseTransformation
{
return YES;
}
- (id)reverseTransformedValue:(id)value
{
if ([value isEqualToString:NSLocalizedString(@"MP4 File", @"")])
{
return @(HB_MUX_AV_MP4);
}
else if ([value isEqualToString:NSLocalizedString(@"MKV File", @"")])
{
return @(HB_MUX_AV_MKV);
}
return @(hb_container_get_from_name([value UTF8String]));
}
@end
@implementation HBURLTransformer
+ (Class)transformedValueClass
{
return [NSString class];
}
- (id)transformedValue:(id)value
{
if (value)
return [value path];
else
return nil;
}
+ (BOOL)allowsReverseTransformation
{
return YES;
}
- (id)reverseTransformedValue:(id)value
{
if (value)
{
return [NSURL fileURLWithPath:value];
}
return nil;
}
@end
|