diff --git a/Base.lproj/QueueOptions.xib b/Base.lproj/QueueOptions.xib index 3f8c3f5..bd5a075 100644 --- a/Base.lproj/QueueOptions.xib +++ b/Base.lproj/QueueOptions.xib @@ -1,8 +1,8 @@ - + - + @@ -15,7 +15,7 @@ - + - + @@ -398,7 +398,7 @@ - + @@ -440,7 +440,7 @@ - + @@ -481,6 +481,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -489,6 +538,7 @@ + @@ -496,7 +546,6 @@ - @@ -506,14 +555,18 @@ + + + + @@ -536,6 +589,7 @@ + @@ -546,6 +600,7 @@ + @@ -553,6 +608,7 @@ + @@ -561,6 +617,7 @@ + @@ -569,7 +626,7 @@ - + diff --git a/Classes/SBQueueAction.h b/Classes/SBQueueAction.h index 02ee819..f2f1522 100644 --- a/Classes/SBQueueAction.h +++ b/Classes/SBQueueAction.h @@ -79,4 +79,20 @@ typedef NS_ENUM(NSUInteger, SBQueueMetadataActionPreferredArtwork) { - (instancetype)initWithLanguage:(NSString *)language; @end +/** + * An actions that set the video track color space. + */ + +typedef NS_ENUM(NSUInteger, SBQueueColorSpaceActionTag) { + SBQueueColorSpaceActionTagNone = 1, + SBQueueColorSpaceActionTagRec601PAL, + SBQueueColorSpaceActionTagRec601SMPTEC, + SBQueueColorSpaceActionTagRec709, + SBQueueColorSpaceActionTagRec2020 + }; +@interface SBQueueColorSpaceAction : NSObject +- (instancetype)initWithTag:(uint16_t)tag; +- (instancetype)initWithColorPrimaries:(uint16_t)colorPrimaries transferCharacteristics:(uint16_t)transferCharacteristics matrixCoefficients:(uint16_t)matrixCoefficients; +@end + NS_ASSUME_NONNULL_END diff --git a/Classes/SBQueueAction.m b/Classes/SBQueueAction.m index 7518cf2..10f5397 100644 --- a/Classes/SBQueueAction.m +++ b/Classes/SBQueueAction.m @@ -473,3 +473,101 @@ @end +@interface SBQueueColorSpaceAction () +@property(nonatomic, readonly) uint16_t colorPrimaries; +@property(nonatomic, readonly) uint16_t transferCharacteristics; +@property(nonatomic, readonly) uint16_t matrixCoefficients; +@end + +@implementation SBQueueColorSpaceAction + +- (instancetype)initWithTag:(uint16_t)tag { + self = [super init]; + if (self) { + switch (tag) { + case SBQueueColorSpaceActionTagRec601PAL: + _colorPrimaries = 5; + _transferCharacteristics = 1; + _matrixCoefficients = 6; + break; + + case SBQueueColorSpaceActionTagRec601SMPTEC: + _colorPrimaries = 6; + _transferCharacteristics = 1; + _matrixCoefficients = 6; + break; + + case SBQueueColorSpaceActionTagRec709: + _colorPrimaries = 1; + _transferCharacteristics = 1; + _matrixCoefficients = 1; + break; + + case SBQueueColorSpaceActionTagRec2020: + _colorPrimaries = 9; + _transferCharacteristics = 1; + _matrixCoefficients = 9; + break; + + case SBQueueColorSpaceActionTagNone: + default: + _colorPrimaries = 0; + _transferCharacteristics = 0; + _matrixCoefficients = 0; + break; + } + } + return self; +} + +- (instancetype)initWithColorPrimaries:(uint16_t)colorPrimaries transferCharacteristics:(uint16_t)transferCharacteristics matrixCoefficients:(uint16_t)matrixCoefficients { + self = [super init]; + if (self) { + _colorPrimaries = colorPrimaries; + _transferCharacteristics = transferCharacteristics; + _matrixCoefficients = matrixCoefficients; + } + return self; +} + +- (void)runAction:(SBQueueItem *)item { + for (MP42VideoTrack *track in [item.mp4File tracksWithMediaType:kMP42MediaType_Video]) { + if (track.format == kMP42VideoCodecType_H264 || + track.format == kMP42VideoCodecType_HEVC || + track.format == kMP42VideoCodecType_HEVC_2 || + track.format == kMP42VideoCodecType_MPEG4Video) { + track.colorPrimaries = self.colorPrimaries; + track.transferCharacteristics = self.transferCharacteristics; + track.matrixCoefficients = self.matrixCoefficients; + } + } +} + +- (NSString *)description { + return NSLocalizedString(@"Set color space.", @"Set track color space action description"); +} + +- (NSString *)localizedDescription { + return NSLocalizedString(@"Setting color space", @"Set track color space action local description"); +} + ++ (BOOL)supportsSecureCoding { + return YES; +} + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super init]; + _colorPrimaries = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionColorPrimaries"]; + _transferCharacteristics = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionTransferCharacteristics"]; + _matrixCoefficients = [coder decodeInt32ForKey:@"SBQueueColorSpaceActionMatrixCoefficients"]; + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [coder encodeInt32:self.colorPrimaries forKey:@"SBQueueColorSpaceActionColorPrimaries"]; + [coder encodeInt32:self.transferCharacteristics forKey:@"SBQueueColorSpaceActionTransferCharacteristics"]; + [coder encodeInt32:self.matrixCoefficients forKey:@"SBQueueColorSpaceActionMatrixCoefficients"]; +} + +@end + diff --git a/Classes/SBQueueController.m b/Classes/SBQueueController.m index 42d899b..6565c19 100755 --- a/Classes/SBQueueController.m +++ b/Classes/SBQueueController.m @@ -283,6 +283,10 @@ static void *SBQueueContex = &SBQueueContex; [item addAction:[[SBQueueSetLanguageAction alloc] initWithLanguage:self.options[SBQueueFixTrackLanguageValue]]]; } + if ([(self.options)[SBQueueApplyColorSpace] boolValue]) { + [item addAction:[[SBQueueColorSpaceAction alloc] initWithTag:[self.options[SBQueueApplyColorSpaceValue] unsignedIntegerValue]]]; + } + if ((self.options)[SBQueueSet]) { [item addAction:[[SBQueueSetAction alloc] initWithSet:(self.options)[SBQueueSet]]]; } diff --git a/Classes/SBQueueItem.m b/Classes/SBQueueItem.m index 6377c0b..886b41a 100755 --- a/Classes/SBQueueItem.m +++ b/Classes/SBQueueItem.m @@ -360,9 +360,11 @@ bail: // Convert from a file reference url to a normal url // the file will be replaced if optimized, and the reference url // may point to nil - [self willChangeValueForKey:@"fileURL"]; - _fileURL = filePathURL; - [self didChangeValueForKey:@"fileURL"]; + dispatch_sync(dispatch_get_main_queue(), ^{ + [self willChangeValueForKey:@"fileURL"]; + self->_fileURL = filePathURL; + [self didChangeValueForKey:@"fileURL"]; + }); #ifdef SB_SANDBOX if ([destination respondsToSelector:@selector(stopAccessingSecurityScopedResource)]) @@ -410,7 +412,8 @@ bail: _actionsInternal = [decoder decodeObjectOfClasses:[NSSet setWithObjects:[NSMutableArray class], [SBQueueSetAction class], [SBQueueMetadataAction class], [SBQueueSubtitlesAction class], [SBQueueSetLanguageAction class], [SBQueueFixFallbacksAction class], - [SBQueueClearTrackNameAction class], [SBQueueOrganizeGroupsAction class], nil] + [SBQueueClearTrackNameAction class], [SBQueueOrganizeGroupsAction class], + [SBQueueColorSpaceAction class], nil] forKey:@"SBQueueItemActions"]; _status = [decoder decodeIntForKey:@"SBQueueItemStatus"]; diff --git a/Classes/SBQueuePreferences.h b/Classes/SBQueuePreferences.h index 4b11994..c83e8f0 100644 --- a/Classes/SBQueuePreferences.h +++ b/Classes/SBQueuePreferences.h @@ -25,6 +25,9 @@ extern NSString * const SBQueueShowDoneNotification; extern NSString * const SBQueueFixTrackLanguage; extern NSString * const SBQueueFixTrackLanguageValue; +extern NSString * const SBQueueApplyColorSpace; +extern NSString * const SBQueueApplyColorSpaceValue; + extern NSString * const SBQueueMovieProvider; extern NSString * const SBQueueTVShowProvider; extern NSString * const SBQueueMovieProviderLanguage; diff --git a/Classes/SBQueuePreferences.m b/Classes/SBQueuePreferences.m index b7b99cf..bafe6c5 100644 --- a/Classes/SBQueuePreferences.m +++ b/Classes/SBQueuePreferences.m @@ -25,6 +25,9 @@ NSString * const SBQueueShowDoneNotification = @"SBQueueShowDoneNotification"; NSString * const SBQueueFixTrackLanguage = @"SBQueueFixTrackLanguage"; NSString * const SBQueueFixTrackLanguageValue = @"SBQueueFixTrackLanguageValue"; +NSString * const SBQueueApplyColorSpace = @"SBQueueApplyColorSpace"; +NSString * const SBQueueApplyColorSpaceValue = @"SBQueueApplyColorSpaceValue"; + NSString * const SBQueueDestination = @"SBQueueDestination"; NSString * const SBQueueMovieProvider = @"SBQueueMovieProvider"; @@ -42,7 +45,7 @@ NSString * const SBQueueSet = @"SBQueueSet"; if (self) { _options = [[NSMutableDictionary alloc] init]; - NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork]; + NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueOptimize, SBQueueShowDoneNotification, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork]; [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { self.options[obj] = [[NSUserDefaults standardUserDefaults] valueForKey:obj]; @@ -73,6 +76,9 @@ NSString * const SBQueueSet = @"SBQueueSet"; SBQueueMetadata : @NO, SBQueueSubtitles: @YES, + SBQueueApplyColorSpace: @NO, + SBQueueApplyColorSpaceValue: @1, + SBQueueAutoStart: @NO, SBQueueOptimize : @YES, SBQueueShowDoneNotification: @YES, @@ -88,7 +94,7 @@ NSString * const SBQueueSet = @"SBQueueSet"; * Save the queue user defaults */ - (void)saveUserDefaults { - NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork]; + NSArray *keys = @[SBQueueFileType, SBQueueOrganize, SBQueueFixTrackLanguage, SBQueueFixTrackLanguageValue, SBQueueApplyColorSpace, SBQueueApplyColorSpaceValue, SBQueueFixFallbacks, SBQueueClearTrackName, SBQueueMetadata, SBQueueSubtitles, SBQueueAutoStart, SBQueueShowDoneNotification, SBQueueOptimize, SBQueueMovieProvider, SBQueueTVShowProvider, SBQueueMovieProviderLanguage, SBQueueTVShowProviderLanguage, SBQueueProviderArtwork]; [keys enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [[NSUserDefaults standardUserDefaults] setValue:(self.options)[obj] forKey:obj];