More cosmetics
This commit is contained in:
1 parent
a074653ec1
commit
f6b23874f6
27 files changed
+1018
-933
No files matched your search
+108
-109
@@ -106,138 +106,137 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
||||
|
||||
- (void)demux:(id)sender
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
MP4TrackId trackId = [[_inputTracks lastObject] sourceId];
|
||||
@autoreleasepool {
|
||||
MP4TrackId trackId = [[_inputTracks lastObject] sourceId];
|
||||
|
||||
NSString *scc = STStandardizeStringNewlines(STLoadFileWithUnknownEncoding([_fileURL path]));
|
||||
if (!scc) return;
|
||||
NSString *scc = STStandardizeStringNewlines(STLoadFileWithUnknownEncoding([_fileURL path]));
|
||||
if (!scc) return;
|
||||
|
||||
NSScanner *sc = [NSScanner scannerWithString:scc];
|
||||
NSString *res=nil;
|
||||
[sc setCharactersToBeSkipped:nil];
|
||||
NSScanner *sc = [NSScanner scannerWithString:scc];
|
||||
NSString *res=nil;
|
||||
[sc setCharactersToBeSkipped:nil];
|
||||
|
||||
[sc scanUpToString:@"\n" intoString:&res];
|
||||
if (![res isEqualToString:@"Scenarist_SCC V1.0"])
|
||||
return;
|
||||
[sc scanUpToString:@"\n" intoString:&res];
|
||||
if (![res isEqualToString:@"Scenarist_SCC V1.0"])
|
||||
return;
|
||||
|
||||
unsigned startTime=0;
|
||||
BOOL firstSample = YES;
|
||||
NSString *splitLine = @"\\n+";
|
||||
NSString *splitTimestamp = @"\\t+";
|
||||
NSString *splitBytes = @"\\s+";
|
||||
NSArray *fileArray = nil;
|
||||
NSUInteger i = 0;
|
||||
unsigned startTime=0;
|
||||
BOOL firstSample = YES;
|
||||
NSString *splitLine = @"\\n+";
|
||||
NSString *splitTimestamp = @"\\t+";
|
||||
NSString *splitBytes = @"\\s+";
|
||||
NSArray *fileArray = nil;
|
||||
NSUInteger i = 0;
|
||||
|
||||
fileArray = [scc componentsSeparatedByRegex:splitLine];
|
||||
fileArray = [scc componentsSeparatedByRegex:splitLine];
|
||||
|
||||
NSMutableArray *sampleArray = [[NSMutableArray alloc] initWithCapacity:[fileArray count]];
|
||||
NSMutableArray *sampleArray = [[NSMutableArray alloc] initWithCapacity:[fileArray count]];
|
||||
|
||||
uint64_t dropFrame = 0;
|
||||
uint64_t frameDrop = 0;
|
||||
uint64_t minutesDrop = 0;
|
||||
uint64_t dropFrame = 0;
|
||||
uint64_t frameDrop = 0;
|
||||
uint64_t minutesDrop = 0;
|
||||
|
||||
for (NSString *line in fileArray) {
|
||||
NSArray *lineArray = [line componentsSeparatedByRegex:splitTimestamp];
|
||||
for (NSString *line in fileArray) {
|
||||
NSArray *lineArray = [line componentsSeparatedByRegex:splitTimestamp];
|
||||
|
||||
if ([lineArray count] < 2)
|
||||
continue;
|
||||
if ([lineArray count] < 2)
|
||||
continue;
|
||||
|
||||
startTime = ParseTimeCode([[lineArray objectAtIndex:0] UTF8String], 30000, NO, &dropFrame);
|
||||
MP42TextSample *sample = [[MP42TextSample alloc] init];
|
||||
sample.timestamp = startTime;
|
||||
sample.title = [lineArray lastObject];
|
||||
|
||||
[sampleArray addObject:[sample autorelease]];
|
||||
}
|
||||
startTime = ParseTimeCode([[lineArray objectAtIndex:0] UTF8String], 30000, NO, &dropFrame);
|
||||
MP42TextSample *sample = [[MP42TextSample alloc] init];
|
||||
sample.timestamp = startTime;
|
||||
sample.title = [lineArray lastObject];
|
||||
|
||||
for (MP42TextSample *ccSample in sampleArray) {
|
||||
if (_cancelled)
|
||||
break;
|
||||
|
||||
NSArray *bytesArray = nil;
|
||||
MP4Duration sampleDuration = 0;
|
||||
bytesArray = [ccSample.title componentsSeparatedByRegex:splitBytes];
|
||||
|
||||
NSUInteger byteCount = [bytesArray count] *2;
|
||||
UInt8 *bytes = malloc(sizeof(UInt8)*byteCount*2 + (sizeof(UInt8)*8));
|
||||
UInt8 *bytesPos = bytes;
|
||||
|
||||
// Write out the size of the atom
|
||||
*(long*)bytesPos = EndianS32_NtoB(8 + byteCount);
|
||||
bytesPos += sizeof(long);
|
||||
|
||||
// Write out the atom type
|
||||
*(OSType*)bytesPos = EndianU32_NtoB('cdat');
|
||||
bytesPos += sizeof(OSType);
|
||||
|
||||
for (NSString *hexByte in bytesArray) {
|
||||
ParseByte([hexByte UTF8String], bytesPos , 1);
|
||||
ParseByte([hexByte UTF8String] + 2, bytesPos + 1, 1);
|
||||
bytesPos +=2;
|
||||
[sampleArray addObject:[sample autorelease]];
|
||||
}
|
||||
|
||||
if (firstSample && ccSample.timestamp != 0 && i == 0) {
|
||||
MP42TextSample *boh = [sampleArray objectAtIndex:1];
|
||||
sampleDuration = boh.timestamp - ccSample.timestamp;
|
||||
firstSample = NO;
|
||||
u_int8_t *emptyBuffer = malloc(sizeof(u_int8_t)*8);
|
||||
u_int8_t empty[8] = {0,0,0,8,'c','d','a','t'};
|
||||
memcpy(emptyBuffer, empty, sizeof(u_int8_t)*8);
|
||||
for (MP42TextSample *ccSample in sampleArray) {
|
||||
if (_cancelled)
|
||||
break;
|
||||
|
||||
NSArray *bytesArray = nil;
|
||||
MP4Duration sampleDuration = 0;
|
||||
bytesArray = [ccSample.title componentsSeparatedByRegex:splitBytes];
|
||||
|
||||
NSUInteger byteCount = [bytesArray count] *2;
|
||||
UInt8 *bytes = malloc(sizeof(UInt8)*byteCount*2 + (sizeof(UInt8)*8));
|
||||
UInt8 *bytesPos = bytes;
|
||||
|
||||
// Write out the size of the atom
|
||||
*(long*)bytesPos = EndianS32_NtoB(8 + byteCount);
|
||||
bytesPos += sizeof(long);
|
||||
|
||||
// Write out the atom type
|
||||
*(OSType*)bytesPos = EndianU32_NtoB('cdat');
|
||||
bytesPos += sizeof(OSType);
|
||||
|
||||
for (NSString *hexByte in bytesArray) {
|
||||
ParseByte([hexByte UTF8String], bytesPos , 1);
|
||||
ParseByte([hexByte UTF8String] + 2, bytesPos + 1, 1);
|
||||
bytesPos +=2;
|
||||
}
|
||||
|
||||
if (firstSample && ccSample.timestamp != 0 && i == 0) {
|
||||
MP42TextSample *boh = [sampleArray objectAtIndex:1];
|
||||
sampleDuration = boh.timestamp - ccSample.timestamp;
|
||||
firstSample = NO;
|
||||
u_int8_t *emptyBuffer = malloc(sizeof(u_int8_t)*8);
|
||||
u_int8_t empty[8] = {0,0,0,8,'c','d','a','t'};
|
||||
memcpy(emptyBuffer, empty, sizeof(u_int8_t)*8);
|
||||
|
||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||
sample->data = emptyBuffer;
|
||||
sample->size = 8;
|
||||
sample->duration = ccSample.timestamp *= 1001;
|
||||
sample->offset = 0;
|
||||
sample->timestamp = 0;
|
||||
sample->isSync = 1;
|
||||
sample->trackId = trackId;
|
||||
|
||||
[self enqueue:sample];
|
||||
[sample release];
|
||||
|
||||
frameDrop += ccSample.timestamp;
|
||||
minutesDrop += frameDrop;
|
||||
}
|
||||
else if (i+1 < [sampleArray count]) {
|
||||
MP42TextSample *boh = [sampleArray objectAtIndex:i+1];
|
||||
sampleDuration = boh.timestamp - ccSample.timestamp;
|
||||
frameDrop += sampleDuration;
|
||||
minutesDrop += sampleDuration;
|
||||
|
||||
if (frameDrop >= 1800 && dropFrame) {
|
||||
if (minutesDrop > 18000)
|
||||
minutesDrop -= 16200;
|
||||
else {
|
||||
sampleDuration -= 2;
|
||||
}
|
||||
|
||||
frameDrop -= 1800;
|
||||
}
|
||||
}
|
||||
else
|
||||
sampleDuration = 6;
|
||||
|
||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||
sample->data = emptyBuffer;
|
||||
sample->size = 8;
|
||||
sample->duration = ccSample.timestamp *= 1001;
|
||||
sample->data = bytes;
|
||||
sample->size = byteCount + 8;
|
||||
sample->duration = sampleDuration * 1001;
|
||||
sample->offset = 0;
|
||||
sample->timestamp = 0;
|
||||
sample->isSync = 1;
|
||||
sample->trackId = trackId;
|
||||
|
||||
|
||||
[self enqueue:sample];
|
||||
[sample release];
|
||||
|
||||
frameDrop += ccSample.timestamp;
|
||||
minutesDrop += frameDrop;
|
||||
|
||||
i++;
|
||||
_progress = ((CGFloat)i / [sampleArray count]) * 100;
|
||||
}
|
||||
else if (i+1 < [sampleArray count]) {
|
||||
MP42TextSample *boh = [sampleArray objectAtIndex:i+1];
|
||||
sampleDuration = boh.timestamp - ccSample.timestamp;
|
||||
frameDrop += sampleDuration;
|
||||
minutesDrop += sampleDuration;
|
||||
|
||||
if (frameDrop >= 1800 && dropFrame) {
|
||||
if (minutesDrop > 18000)
|
||||
minutesDrop -= 16200;
|
||||
else {
|
||||
sampleDuration -= 2;
|
||||
}
|
||||
|
||||
frameDrop -= 1800;
|
||||
}
|
||||
}
|
||||
else
|
||||
sampleDuration = 6;
|
||||
|
||||
MP42SampleBuffer *sample = [[MP42SampleBuffer alloc] init];
|
||||
sample->data = bytes;
|
||||
sample->size = byteCount + 8;
|
||||
sample->duration = sampleDuration * 1001;
|
||||
sample->offset = 0;
|
||||
sample->timestamp = 0;
|
||||
sample->isSync = 1;
|
||||
sample->trackId = trackId;
|
||||
|
||||
[self enqueue:sample];
|
||||
[sample release];
|
||||
|
||||
i++;
|
||||
_progress = ((CGFloat)i / [sampleArray count]) * 100;
|
||||
|
||||
[sampleArray release];
|
||||
[self setDone:YES];
|
||||
}
|
||||
|
||||
[sampleArray release];
|
||||
[self setDone:YES];
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
- (void)startReading
|
||||
|
||||
Reference in new issue
Block a user