Fix closed captions importer usage of architecture specific long size.
This commit is contained in:
1 parent
e9d693993a
commit
dd036eacf8
2 files changed
+40
-33
No files matched your search
+39
-32
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
- (NSSize)sizeForTrack:(MP42Track *)track
|
- (NSSize)sizeForTrack:(MP42Track *)track
|
||||||
{
|
{
|
||||||
return NSMakeSize([(MP42SubtitleTrack*)track trackWidth], [(MP42SubtitleTrack*) track trackHeight]);
|
return NSMakeSize([(MP42SubtitleTrack *)track trackWidth], [(MP42SubtitleTrack *)track trackHeight]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nullable NSData *)magicCookieForTrack:(MP42Track *)track
|
- (nullable NSData *)magicCookieForTrack:(MP42Track *)track
|
||||||
@@ -114,79 +114,84 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
|||||||
MP4TrackId trackId = self.inputTracks.lastObject.sourceId;
|
MP4TrackId trackId = self.inputTracks.lastObject.sourceId;
|
||||||
|
|
||||||
NSString *scc = STStandardizeStringNewlines(STLoadFileWithUnknownEncoding(self.fileURL));
|
NSString *scc = STStandardizeStringNewlines(STLoadFileWithUnknownEncoding(self.fileURL));
|
||||||
if (!scc) return;
|
if (!scc) { return; }
|
||||||
|
|
||||||
NSScanner *sc = [NSScanner scannerWithString:scc];
|
NSScanner *sc = [NSScanner scannerWithString:scc];
|
||||||
NSString *res=nil;
|
NSString *res = nil;
|
||||||
[sc setCharactersToBeSkipped:nil];
|
[sc setCharactersToBeSkipped:nil];
|
||||||
|
|
||||||
[sc scanUpToString:@"\n" intoString:&res];
|
[sc scanUpToString:@"\n" intoString:&res];
|
||||||
if (![res isEqualToString:@"Scenarist_SCC V1.0"])
|
if (![res isEqualToString:@"Scenarist_SCC V1.0"]) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned startTime=0;
|
unsigned startTime=0;
|
||||||
BOOL firstSample = YES;
|
BOOL firstSample = YES;
|
||||||
NSString *splitLine = @"\\n+";
|
NSString *splitLine = @"\\n+";
|
||||||
NSString *splitTimestamp = @"\\t+";
|
NSString *splitTimestamp = @"\\t+";
|
||||||
NSString *splitBytes = @"\\s+";
|
NSString *splitBytes = @"\\s+";
|
||||||
NSArray *fileArray = nil;
|
NSArray<NSString *> *fileArray = nil;
|
||||||
NSUInteger i = 0;
|
NSUInteger i = 0;
|
||||||
|
|
||||||
fileArray = [scc MP42_componentsSeparatedByRegex:splitLine];
|
fileArray = [scc MP42_componentsSeparatedByRegex:splitLine];
|
||||||
|
|
||||||
NSMutableArray *sampleArray = [[NSMutableArray alloc] initWithCapacity:[fileArray count]];
|
NSMutableArray *sampleArray = [[NSMutableArray alloc] initWithCapacity:fileArray.count];
|
||||||
|
|
||||||
uint64_t dropFrame = 0;
|
UInt64 dropFrame = 0;
|
||||||
uint64_t frameDrop = 0;
|
UInt64 frameDrop = 0;
|
||||||
uint64_t minutesDrop = 0;
|
UInt64 minutesDrop = 0;
|
||||||
|
|
||||||
for (NSString *line in fileArray) {
|
for (NSString *line in fileArray) {
|
||||||
NSArray *lineArray = [line MP42_componentsSeparatedByRegex:splitTimestamp];
|
NSArray<NSString *> *lineArray = [line MP42_componentsSeparatedByRegex:splitTimestamp];
|
||||||
|
|
||||||
if ([lineArray count] < 2)
|
if (lineArray.count < 2) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
startTime = ParseTimeCode(lineArray[0].UTF8String, 30000, NO, &dropFrame);
|
||||||
|
|
||||||
startTime = ParseTimeCode([[lineArray objectAtIndex:0] UTF8String], 30000, NO, &dropFrame);
|
|
||||||
MP42TextSample *sample = [[MP42TextSample alloc] init];
|
MP42TextSample *sample = [[MP42TextSample alloc] init];
|
||||||
sample.timestamp = startTime;
|
sample.timestamp = startTime;
|
||||||
sample.title = [lineArray lastObject];
|
sample.title = [lineArray lastObject];
|
||||||
|
|
||||||
[sampleArray addObject:[sample autorelease]];
|
[sampleArray addObject:sample];
|
||||||
|
[sample release];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MP42TextSample *ccSample in sampleArray) {
|
for (MP42TextSample *ccSample in sampleArray) {
|
||||||
if (_cancelled)
|
if (_cancelled) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
NSArray *bytesArray = nil;
|
NSArray *bytesArray = nil;
|
||||||
MP4Duration sampleDuration = 0;
|
MP4Duration sampleDuration = 0;
|
||||||
bytesArray = [ccSample.title MP42_componentsSeparatedByRegex:splitBytes];
|
bytesArray = [ccSample.title MP42_componentsSeparatedByRegex:splitBytes];
|
||||||
|
|
||||||
NSUInteger byteCount = [bytesArray count] *2;
|
NSUInteger byteCount = bytesArray.count * 2;
|
||||||
UInt8 *bytes = malloc(sizeof(UInt8)*byteCount*2 + (sizeof(UInt8)*8));
|
UInt8 *bytes = malloc(sizeof(UInt8) * byteCount * 2 + (sizeof(UInt8) * 8));
|
||||||
UInt8 *bytesPos = bytes;
|
UInt8 *bytesPos = bytes;
|
||||||
|
|
||||||
// Write out the size of the atom
|
// Write out the size of the atom
|
||||||
*(long*)bytesPos = EndianS32_NtoB(8 + byteCount);
|
*(SInt32 *)bytesPos = EndianS32_NtoB(8 + byteCount);
|
||||||
bytesPos += sizeof(long);
|
bytesPos += sizeof(SInt32);
|
||||||
|
|
||||||
// Write out the atom type
|
// Write out the atom type
|
||||||
*(OSType*)bytesPos = EndianU32_NtoB('cdat');
|
*(OSType*) bytesPos = EndianU32_NtoB('cdat');
|
||||||
bytesPos += sizeof(OSType);
|
bytesPos += sizeof(OSType);
|
||||||
|
|
||||||
for (NSString *hexByte in bytesArray) {
|
for (NSString *hexByte in bytesArray) {
|
||||||
ParseByte([hexByte UTF8String], bytesPos , 1);
|
ParseByte(hexByte.UTF8String, bytesPos , 1);
|
||||||
ParseByte([hexByte UTF8String] + 2, bytesPos + 1, 1);
|
ParseByte(hexByte.UTF8String + 2, bytesPos + 1, 1);
|
||||||
bytesPos +=2;
|
bytesPos +=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstSample && ccSample.timestamp != 0 && i == 0) {
|
if (firstSample && ccSample.timestamp != 0 && i == 0) {
|
||||||
MP42TextSample *boh = [sampleArray objectAtIndex:1];
|
MP42TextSample *textSample = sampleArray[1];
|
||||||
sampleDuration = boh.timestamp - ccSample.timestamp;
|
sampleDuration = textSample.timestamp - ccSample.timestamp;
|
||||||
firstSample = NO;
|
firstSample = NO;
|
||||||
u_int8_t *emptyBuffer = malloc(sizeof(u_int8_t)*8);
|
UInt8 *emptyBuffer = malloc(sizeof(UInt8) * 8);
|
||||||
u_int8_t empty[8] = {0,0,0,8,'c','d','a','t'};
|
UInt8 empty[8] = {0,0,0,8,'c','d','a','t'};
|
||||||
memcpy(emptyBuffer, empty, sizeof(u_int8_t)*8);
|
memcpy(emptyBuffer, empty, sizeof(UInt8) * 8);
|
||||||
|
|
||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->data = emptyBuffer;
|
sample->data = emptyBuffer;
|
||||||
@@ -203,15 +208,16 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
|||||||
frameDrop += ccSample.timestamp;
|
frameDrop += ccSample.timestamp;
|
||||||
minutesDrop += frameDrop;
|
minutesDrop += frameDrop;
|
||||||
}
|
}
|
||||||
else if (i+1 < [sampleArray count]) {
|
else if (i + 1 < sampleArray.count) {
|
||||||
MP42TextSample *boh = [sampleArray objectAtIndex:i+1];
|
MP42TextSample *textSample = sampleArray[i + 1];
|
||||||
sampleDuration = boh.timestamp - ccSample.timestamp;
|
sampleDuration = textSample.timestamp - ccSample.timestamp;
|
||||||
frameDrop += sampleDuration;
|
frameDrop += sampleDuration;
|
||||||
minutesDrop += sampleDuration;
|
minutesDrop += sampleDuration;
|
||||||
|
|
||||||
if (frameDrop >= 1800 && dropFrame) {
|
if (frameDrop >= 1800 && dropFrame) {
|
||||||
if (minutesDrop > 18000)
|
if (minutesDrop > 18000) {
|
||||||
minutesDrop -= 16200;
|
minutesDrop -= 16200;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
sampleDuration -= 2;
|
sampleDuration -= 2;
|
||||||
}
|
}
|
||||||
@@ -219,8 +225,9 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
|||||||
frameDrop -= 1800;
|
frameDrop -= 1800;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
sampleDuration = 6;
|
sampleDuration = 6;
|
||||||
|
}
|
||||||
|
|
||||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||||
sample->data = bytes;
|
sample->data = bytes;
|
||||||
@@ -235,7 +242,7 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
|||||||
[sample release];
|
[sample release];
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
_progress = ((CGFloat)i / [sampleArray count]) * 100;
|
_progress = ((CGFloat)i / sampleArray.count) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
[sampleArray release];
|
[sampleArray release];
|
||||||
|
|||||||
+1
-1
@@ -482,7 +482,7 @@
|
|||||||
videoSize.width = getFixedVideoWidth(_fileHandle, videoTrack);
|
videoSize.width = getFixedVideoWidth(_fileHandle, videoTrack);
|
||||||
videoSize.height = MP4GetTrackVideoHeight(_fileHandle, videoTrack);
|
videoSize.height = MP4GetTrackVideoHeight(_fileHandle, videoTrack);
|
||||||
}
|
}
|
||||||
else {
|
if (videoSize.width == 0 || videoSize.height == 0) {
|
||||||
videoSize.width = 640;
|
videoSize.width = 640;
|
||||||
videoSize.height = 480;
|
videoSize.height = 480;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user