Return NO in updateMP4FileWithAttributes:attributes:error: only if a serious error happened like a permission error or the mp4 not closing properly. Print the other errors to the log.

This commit is contained in:
Damiano Galassi committed 2014-12-14 09:23:18 +01:00
1 parent f0b349eef1
commit 017cd8d8c1
6 files changed
+152 -120

No files matched your search

+56 -42
View File
@@ -710,100 +710,113 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
} }
- (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError { - (BOOL)updateMP4FileWithAttributes:(NSDictionary *)attributes error:(NSError **)outError {
BOOL noErr = YES;
// Organize the alternate groups // Organize the alternate groups
if ([[attributes valueForKey:MP42OrganizeAlternateGroups] boolValue]) if ([[attributes valueForKey:MP42OrganizeAlternateGroups] boolValue]) {
[self organizeAlternateGroups]; [self organizeAlternateGroups];
}
// Open the mp4 file // Open the mp4 file
if (![self startWriting]) { if (![self startWriting]) {
if (outError) if (outError) {
*outError = MP42Error(@"The file could not be saved.", @"You may do not have sufficient permissions for this operation.", 101); *outError = MP42Error(@"The file could not be saved.", @"You may do not have sufficient permissions for this operation.", 101);
[_logger writeErrorToLog:*outError];
}
return NO; return NO;
} }
// Delete tracks // Delete tracks
for (MP42Track *track in _tracksToBeDeleted) for (MP42Track *track in _tracksToBeDeleted) {
[self removeMuxedTrack:track]; [self removeMuxedTrack:track];
}
// Init the muxer and prepare the work // Init the muxer and prepare the work
NSMutableArray *tracksToMux = [[NSMutableArray alloc] init]; NSMutableArray *unsupportedTracks = [[NSMutableArray alloc] init];
self.muxer = [[[MP42Muxer alloc] initWithFileHandle:self.fileHandle delegate:self logger:_logger] autorelease];
for (MP42Track *track in self.itracks) { for (MP42Track *track in self.itracks) {
if (!track.muxed) { if (!track.muxed) {
// Reopen the file importer is they are not already open // Reopen the file importer is they are not already open
// this happens when the object was unarchived from a file // this happens when the object was unarchived from a file.
if (![track isMemberOfClass:[MP42ChapterTrack class]] && !track.muxer_helper->importer && [track sourceURL]) { if (![track isMemberOfClass:[MP42ChapterTrack class]] && !track.muxer_helper->importer && track.sourceURL) {
MP42FileImporter *fileImporter = [self.importers valueForKey:[[track sourceURL] path]]; MP42FileImporter *fileImporter = [self.importers valueForKey:track.sourceURL.path];
if (!fileImporter) { if (!fileImporter) {
fileImporter = [[[MP42FileImporter alloc] initWithURL:[track sourceURL] error:outError] autorelease]; fileImporter = [[[MP42FileImporter alloc] initWithURL:track.sourceURL error:outError] autorelease];
[self.importers setObject:fileImporter forKey:[[track sourceURL] path]]; [self.importers setObject:fileImporter forKey:track.sourceURL.path];
} }
if (fileImporter) { if (fileImporter) {
track.muxer_helper->importer = fileImporter; track.muxer_helper->importer = fileImporter;
} else { } else {
if (outError) { if (outError) {
*outError = MP42Error(@"Missing sources.", NSError *error = MP42Error(@"Missing sources.", @"One or more sources files are missing.", 200);
@"One or more sources files are missing.", [_logger writeErrorToLog:error];
200); if (outError) { *outError = error; }
} }
noErr = NO;
break; break;
} }
} }
// Add the track to the muxer // Add the track to the muxer
if (track.muxer_helper->importer) if (track.muxer_helper->importer) {
[tracksToMux addObject:track]; if ([self.muxer canAddTrack:track]) {
}
}
if (!noErr) {
[self stopWriting];
return NO;
}
if ([tracksToMux count]) {
self.muxer = [[[MP42Muxer alloc] initWithDelegate:self andLogger:_logger] autorelease];
for (MP42Track *track in tracksToMux) {
[self.muxer addTrack:track]; [self.muxer addTrack:track];
} else {
// We don't know how to handle this type of track.
NSError *error = MP42Error(@"Unsupported track",
[NSString stringWithFormat:@"%@, %@, has not been muxed.", track.name, track.format],
201);
[_logger writeErrorToLog:error];
if (outError) { *outError = error; }
[unsupportedTracks addObject:track];
}
}
}
} }
// Setup the muxer [self.muxer setup:outError];
noErr = [self.muxer setup:self.fileHandle error:outError];
[self.muxer work]; [self.muxer work];
self.muxer = nil; self.muxer = nil;
}
[tracksToMux release]; // Remove the unsupported tracks from the array of the tracks
// to update. Unsupported tracks haven't been muxed, so there is no
// to update them.
NSMutableArray *tracksToUpdate = [self.itracks mutableCopy];
[tracksToUpdate removeObjectsInArray:unsupportedTracks];
[unsupportedTracks release];
[self.importers removeAllObjects]; [self.importers removeAllObjects];
// Update modified tracks properties // Update modified tracks properties
updateMoovDuration(self.fileHandle); updateMoovDuration(self.fileHandle);
for (MP42Track *track in self.itracks) { for (MP42Track *track in tracksToUpdate) {
if (track.isEdited) { if (track.isEdited) {
noErr = [track writeToFile:self.fileHandle error:outError]; if (![track writeToFile:self.fileHandle error:outError]) {
if (!noErr) if (*outError) {
break; [_logger writeErrorToLog:*outError];
}
}
} }
} }
[tracksToUpdate release];
// Update metadata // Update metadata
if (self.metadata.isEdited) if (self.metadata.isEdited) {
[self.metadata writeMetadataWithFileHandle:self.fileHandle]; [self.metadata writeMetadataWithFileHandle:self.fileHandle];
}
// Close the mp4 file handle // Close the mp4 file handle
if (![self stopWriting]) { if (![self stopWriting]) {
if (outError) if (*outError == nil) {
*outError = MP42Error(@"File excedes 4 GB.", *outError = MP42Error(@"File excedes 4 GB.",
@"The file is bigger than 4 GB, but it was created with 32bit data chunk offset.\nSelect 64bit data chunk offset in the save panel.", @"The file is bigger than 4 GB, but it was created with 32bit data chunk offset.\nSelect 64bit data chunk offset in the save panel.",
102); 102);
[_logger writeErrorToLog:*outError];
}
return NO; return NO;
} }
@@ -814,10 +827,11 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
[self customChaptersPreview]; [self customChaptersPreview];
} }
if ([self.delegate respondsToSelector:@selector(saveDidEnd:)]) if ([self.delegate respondsToSelector:@selector(saveDidEnd:)]) {
[self.delegate performSelector:@selector(saveDidEnd:) withObject:self]; [self.delegate performSelector:@selector(saveDidEnd:) withObject:self];
}
return noErr; return YES;
} }
#pragma mark - Chapters previews #pragma mark - Chapters previews
+5 -1
View File
@@ -676,8 +676,12 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
if (trackInfo->Type == TT_SUB) { if (trackInfo->Type == TT_SUB) {
if (readMkvPacket(_ioStream, trackInfo, FilePos, &frame, &FrameSize)) { if (readMkvPacket(_ioStream, trackInfo, FilePos, &frame, &FrameSize)) {
if (strcmp(trackInfo->CodecID, "S_VOBSUB") && strcmp(trackInfo->CodecID, "S_HDMV/PGS")) { if (strcmp(trackInfo->CodecID, "S_VOBSUB") && strcmp(trackInfo->CodecID, "S_HDMV/PGS")) {
if (!demuxHelper->ss) if (!demuxHelper->ss) {
demuxHelper->ss = [[SBSubSerializer alloc] init]; demuxHelper->ss = [[SBSubSerializer alloc] init];
if (!strcmp(trackInfo->CodecID, "S_TEXT/ASS") || !strcmp(trackInfo->CodecID, "S_TEXT/SSA")) {
[demuxHelper->ss setSSA:YES];
}
}
NSString *string = [[[NSString alloc] initWithBytes:frame length:FrameSize encoding:NSUTF8StringEncoding] autorelease]; NSString *string = [[[NSString alloc] initWithBytes:frame length:FrameSize encoding:NSUTF8StringEncoding] autorelease];
if (!strcmp(trackInfo->CodecID, "S_TEXT/ASS") || !strcmp(trackInfo->CodecID, "S_TEXT/SSA")) { if (!strcmp(trackInfo->CodecID, "S_TEXT/ASS") || !strcmp(trackInfo->CodecID, "S_TEXT/SSA")) {
+3 -2
View File
@@ -27,11 +27,12 @@
int32_t _cancelled; int32_t _cancelled;
} }
- (instancetype)initWithDelegate:(id <MP42MuxerDelegate>)del andLogger:(id <MP42Logging>)logger; - (instancetype)initWithFileHandle:(MP4FileHandle)fileHandle delegate:(id <MP42MuxerDelegate>)del logger:(id <MP42Logging>)logger;
- (BOOL)canAddTrack:(MP42Track *)track;
- (void)addTrack:(MP42Track *)track; - (void)addTrack:(MP42Track *)track;
- (BOOL)setup:(MP4FileHandle)fileHandle error:(NSError **)outError; - (BOOL)setup:(NSError **)outError;
- (void)work; - (void)work;
- (void)cancel; - (void)cancel;
+73 -68
View File
@@ -27,10 +27,11 @@
return self; return self;
} }
- (instancetype)initWithDelegate:(id <MP42MuxerDelegate>)del andLogger:(id <MP42Logging>)logger - (instancetype)initWithFileHandle:(MP4FileHandle)fileHandle delegate:(id <MP42MuxerDelegate>)del logger:(id <MP42Logging>)logger
{ {
if ((self = [super init])) { if ((self = [self init])) {
_workingTracks = [[NSMutableArray alloc] init]; NSParameterAssert(fileHandle);
_fileHandle = fileHandle;
_delegate = del; _delegate = del;
_logger = [logger retain]; _logger = [logger retain];
} }
@@ -38,16 +39,29 @@
return self; return self;
} }
- (void)addTrack:(MP42Track*)track - (BOOL)canAddTrack:(MP42Track *)track
{
NSArray *supportedFormats = @[MP42VideoFormatH264, MP42VideoFormatMPEG4Visual, MP42VideoFormatJPEG,
MP42AudioFormatAAC, MP42AudioFormatAC3, MP42AudioFormatALAC, MP42AudioFormatDTS,
MP42SubtitleFormatTx3g, MP42SubtitleFormatVobSub, MP42ClosedCaptionFormatCEA608];
if ([supportedFormats containsObject:track.format]) {
return YES;
if ([track isMemberOfClass:[MP42AudioTrack class]]) {
// TO-DO Check if we can initialize the audio converter
}
} else {
return NO;
}
}
- (void)addTrack:(MP42Track *)track
{ {
if (![track isMemberOfClass:[MP42ChapterTrack class]]) if (![track isMemberOfClass:[MP42ChapterTrack class]])
[_workingTracks addObject:track]; [_workingTracks addObject:track];
} }
- (BOOL)setup:(MP4FileHandle)fileHandle error:(NSError **)outError - (BOOL)setup:(NSError **)outError
{ {
BOOL noErr = YES;
_fileHandle = fileHandle;
NSMutableArray *unsupportedTracks = [[NSMutableArray alloc] init];; NSMutableArray *unsupportedTracks = [[NSMutableArray alloc] init];;
for (MP42Track *track in _workingTracks) { for (MP42Track *track in _workingTracks) {
@@ -60,16 +74,17 @@
magicCookie = [helper->importer magicCookieForTrack:track]; magicCookie = [helper->importer magicCookieForTrack:track];
timeScale = [helper->importer timescaleForTrack:track]; timeScale = [helper->importer timescaleForTrack:track];
} else { } else {
[unsupportedTracks addObject:track];
continue; continue;
} }
if([track isMemberOfClass:[MP42AudioTrack class]] && track.needConversion) { // Setup the converters
if ([track isMemberOfClass:[MP42AudioTrack class]] && track.needConversion) {
MP42AudioConverter *audioConverter = [[MP42AudioConverter alloc] initWithTrack:(MP42AudioTrack *)track MP42AudioConverter *audioConverter = [[MP42AudioConverter alloc] initWithTrack:(MP42AudioTrack *)track
andMixdownType:[(MP42AudioTrack *)track mixdownType] andMixdownType:[(MP42AudioTrack *)track mixdownType]
error:outError]; error:outError];
if (audioConverter == nil) { if (audioConverter == nil) {
noErr = NO;
if (outError && *outError) { if (outError && *outError) {
[_logger writeErrorToLog:*outError]; [_logger writeErrorToLog:*outError];
} }
@@ -79,12 +94,11 @@
helper->converter = audioConverter; helper->converter = audioConverter;
} }
if([track isMemberOfClass:[MP42SubtitleTrack class]] && ([track.sourceFormat isEqualToString:MP42SubtitleFormatVobSub] || [track.sourceFormat isEqualToString:MP42SubtitleFormatPGS]) && track.needConversion) { if ([track isMemberOfClass:[MP42SubtitleTrack class]] && ([track.sourceFormat isEqualToString:MP42SubtitleFormatVobSub] || [track.sourceFormat isEqualToString:MP42SubtitleFormatPGS]) && track.needConversion) {
MP42BitmapSubConverter *subConverter = [[MP42BitmapSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track MP42BitmapSubConverter *subConverter = [[MP42BitmapSubConverter alloc] initWithTrack:(MP42SubtitleTrack *)track
error:outError]; error:outError];
if (subConverter == nil) { if (subConverter == nil) {
noErr = NO;
if (outError && *outError) { if (outError && *outError) {
[_logger writeErrorToLog:*outError]; [_logger writeErrorToLog:*outError];
} }
@@ -93,9 +107,9 @@
} }
helper->converter = subConverter; helper->converter = subConverter;
} } else if ([track isMemberOfClass:[MP42SubtitleTrack class]] && track.needConversion) {
else if([track isMemberOfClass:[MP42SubtitleTrack class]] && track.needConversion)
track.format = MP42SubtitleFormatTx3g; track.format = MP42SubtitleFormatTx3g;
}
// H.264 video track // H.264 video track
if ([track isMemberOfClass:[MP42VideoTrack class]] && [track.format isEqualToString:MP42VideoFormatH264]) { if ([track isMemberOfClass:[MP42VideoTrack class]] && [track.format isEqualToString:MP42VideoFormatH264]) {
@@ -105,7 +119,7 @@
NSSize size = [helper->importer sizeForTrack:track]; NSSize size = [helper->importer sizeForTrack:track];
uint8_t *avcCAtom = (uint8_t*)[magicCookie bytes]; uint8_t *avcCAtom = (uint8_t*)[magicCookie bytes];
dstTrackId = MP4AddH264VideoTrack(fileHandle, timeScale, dstTrackId = MP4AddH264VideoTrack(_fileHandle, timeScale,
MP4_INVALID_DURATION, MP4_INVALID_DURATION,
size.width, size.height, size.width, size.height,
avcCAtom[1], // AVCProfileIndication avcCAtom[1], // AVCProfileIndication
@@ -119,7 +133,7 @@
for (i = 0; i < spsCount; i++) { for (i = 0; i < spsCount; i++) {
uint16_t spsSize = (avcCAtom[ptrPos++] << 8) & 0xff00; uint16_t spsSize = (avcCAtom[ptrPos++] << 8) & 0xff00;
spsSize += avcCAtom[ptrPos++] & 0xff; spsSize += avcCAtom[ptrPos++] & 0xff;
MP4AddH264SequenceParameterSet(fileHandle, dstTrackId, MP4AddH264SequenceParameterSet(_fileHandle, dstTrackId,
avcCAtom+ptrPos, spsSize); avcCAtom+ptrPos, spsSize);
ptrPos += spsSize; ptrPos += spsSize;
} }
@@ -128,27 +142,27 @@
for (i = 0; i < ppsCount; i++) { for (i = 0; i < ppsCount; i++) {
uint16_t ppsSize = (avcCAtom[ptrPos++] << 8) & 0xff00; uint16_t ppsSize = (avcCAtom[ptrPos++] << 8) & 0xff00;
ppsSize += avcCAtom[ptrPos++] & 0xff; ppsSize += avcCAtom[ptrPos++] & 0xff;
MP4AddH264PictureParameterSet(fileHandle, dstTrackId, MP4AddH264PictureParameterSet(_fileHandle, dstTrackId,
avcCAtom+ptrPos, ppsSize); avcCAtom+ptrPos, ppsSize);
ptrPos += ppsSize; ptrPos += ppsSize;
} }
MP4SetVideoProfileLevel(fileHandle, 0x15); MP4SetVideoProfileLevel(_fileHandle, 0x15);
[helper->importer setActiveTrack:track]; [helper->importer setActiveTrack:track];
} }
// MPEG-4 Visual video track // MPEG-4 Visual video track
else if ([track isMemberOfClass:[MP42VideoTrack class]] && [track.format isEqualToString:MP42VideoFormatMPEG4Visual]) { else if ([track isMemberOfClass:[MP42VideoTrack class]] && [track.format isEqualToString:MP42VideoFormatMPEG4Visual]) {
MP4SetVideoProfileLevel(fileHandle, MPEG4_SP_L3); MP4SetVideoProfileLevel(_fileHandle, MPEG4_SP_L3);
// Add video track // Add video track
dstTrackId = MP4AddVideoTrack(fileHandle, timeScale, dstTrackId = MP4AddVideoTrack(_fileHandle, timeScale,
MP4_INVALID_DURATION, MP4_INVALID_DURATION,
[(MP42VideoTrack*)track width], [(MP42VideoTrack*)track height], [(MP42VideoTrack*)track width], [(MP42VideoTrack*)track height],
MP4_MPEG4_VIDEO_TYPE); MP4_MPEG4_VIDEO_TYPE);
if ([magicCookie length]) if ([magicCookie length])
MP4SetTrackESConfiguration(fileHandle, dstTrackId, MP4SetTrackESConfiguration(_fileHandle, dstTrackId,
[magicCookie bytes], [magicCookie bytes],
[magicCookie length]); [magicCookie length]);
@@ -158,7 +172,7 @@
// Photo-JPEG video track // Photo-JPEG video track
else if ([track isMemberOfClass:[MP42VideoTrack class]] && [track.format isEqualToString:MP42VideoFormatJPEG]) { else if ([track isMemberOfClass:[MP42VideoTrack class]] && [track.format isEqualToString:MP42VideoFormatJPEG]) {
// Add video track // Add video track
dstTrackId = MP4AddJpegVideoTrack(fileHandle, timeScale, dstTrackId = MP4AddJpegVideoTrack(_fileHandle, timeScale,
MP4_INVALID_DURATION, [(MP42VideoTrack*)track width], [(MP42VideoTrack*)track height]); MP4_INVALID_DURATION, [(MP42VideoTrack*)track width], [(MP42VideoTrack*)track height]);
[helper->importer setActiveTrack:track]; [helper->importer setActiveTrack:track];
@@ -166,12 +180,12 @@
// AAC audio track // AAC audio track
else if ([track isMemberOfClass:[MP42AudioTrack class]] && [track.format isEqualToString:MP42AudioFormatAAC]) { else if ([track isMemberOfClass:[MP42AudioTrack class]] && [track.format isEqualToString:MP42AudioFormatAAC]) {
dstTrackId = MP4AddAudioTrack(fileHandle, dstTrackId = MP4AddAudioTrack(_fileHandle,
timeScale, timeScale,
1024, MP4_MPEG4_AUDIO_TYPE); 1024, MP4_MPEG4_AUDIO_TYPE);
if (!track.needConversion && [magicCookie length]) { if (!track.needConversion && [magicCookie length]) {
MP4SetTrackESConfiguration(fileHandle, dstTrackId, MP4SetTrackESConfiguration(_fileHandle, dstTrackId,
[magicCookie bytes], [magicCookie bytes],
[magicCookie length]); [magicCookie length]);
} }
@@ -186,7 +200,7 @@
const uint64_t * ac3Info = (const uint64_t *)[magicCookie bytes]; const uint64_t * ac3Info = (const uint64_t *)[magicCookie bytes];
dstTrackId = MP4AddAC3AudioTrack(fileHandle, dstTrackId = MP4AddAC3AudioTrack(_fileHandle,
timeScale, timeScale,
ac3Info[0], ac3Info[0],
ac3Info[1], ac3Info[1],
@@ -200,21 +214,21 @@
// ALAC audio track // ALAC audio track
else if ([track isMemberOfClass:[MP42AudioTrack class]] && [track.format isEqualToString:MP42AudioFormatALAC]) { else if ([track isMemberOfClass:[MP42AudioTrack class]] && [track.format isEqualToString:MP42AudioFormatALAC]) {
dstTrackId = MP4AddALACAudioTrack(fileHandle, dstTrackId = MP4AddALACAudioTrack(_fileHandle,
timeScale); timeScale);
if ([magicCookie length]) if ([magicCookie length])
MP4SetTrackBytesProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.alac.alac.AppleLosslessMagicCookie", [magicCookie bytes], [magicCookie length]); MP4SetTrackBytesProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.alac.alac.AppleLosslessMagicCookie", [magicCookie bytes], [magicCookie length]);
[helper->importer setActiveTrack:track]; [helper->importer setActiveTrack:track];
} }
// DTS audio track // DTS audio track
else if ([track isMemberOfClass:[MP42AudioTrack class]] && [track.format isEqualToString:MP42AudioFormatDTS]) { else if ([track isMemberOfClass:[MP42AudioTrack class]] && [track.format isEqualToString:MP42AudioFormatDTS]) {
dstTrackId = MP4AddAudioTrack(fileHandle, dstTrackId = MP4AddAudioTrack(_fileHandle,
timeScale, timeScale,
512, 0xA9); 512, 0xA9);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.*.channels", [(MP42AudioTrack*)track channels]); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.*.channels", [(MP42AudioTrack*)track channels]);
[helper->importer setActiveTrack:track]; [helper->importer setActiveTrack:track];
} }
@@ -233,10 +247,10 @@
} }
if (!videoSize.width) { if (!videoSize.width) {
MP4TrackId videoTrack = findFirstVideoTrack(fileHandle); MP4TrackId videoTrack = findFirstVideoTrack(_fileHandle);
if (videoTrack) { if (videoTrack) {
videoSize.width = getFixedVideoWidth(fileHandle, videoTrack); videoSize.width = getFixedVideoWidth(_fileHandle, videoTrack);
videoSize.height = MP4GetTrackVideoHeight(fileHandle, videoTrack); videoSize.height = MP4GetTrackVideoHeight(_fileHandle, videoTrack);
} }
else { else {
videoSize.width = 640; videoSize.width = 640;
@@ -253,11 +267,11 @@
subSize.height = videoSize.height; subSize.height = videoSize.height;
const uint8_t textColor[4] = { 255,255,255,255 }; const uint8_t textColor[4] = { 255,255,255,255 };
dstTrackId = MP4AddSubtitleTrack(fileHandle, timeScale, videoSize.width, subSize.height); dstTrackId = MP4AddSubtitleTrack(_fileHandle, timeScale, videoSize.width, subSize.height);
MP4SetTrackDurationPerChunk(fileHandle, dstTrackId, timeScale / 8); MP4SetTrackDurationPerChunk(_fileHandle, dstTrackId, timeScale / 8);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "tkhd.alternate_group", 2); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "tkhd.alternate_group", 2);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "tkhd.layer", -1); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "tkhd.layer", -1);
int32_t displayFlags = 0; int32_t displayFlags = 0;
if (vPlacement) if (vPlacement)
@@ -267,25 +281,25 @@
else if ([(MP42SubtitleTrack *)track allSamplesAreForced]) else if ([(MP42SubtitleTrack *)track allSamplesAreForced])
displayFlags += 0xC0000000; displayFlags += 0xC0000000;
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.displayFlags", displayFlags); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.displayFlags", displayFlags);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.horizontalJustification", 1); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.horizontalJustification", 1);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.verticalJustification", -1); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.verticalJustification", -1);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorRed", 0); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorRed", 0);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorGreen", 0); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorGreen", 0);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorBlue", 0); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorBlue", 0);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorAlpha", 0); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.bgColorAlpha", 0);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", subSize.height); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", subSize.height);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", videoSize.width); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", videoSize.width);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontSize", videoSize.height * 0.05); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontSize", videoSize.height * 0.05);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorRed", textColor[0]); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorRed", textColor[0]);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorGreen", textColor[1]); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorGreen", textColor[1]);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorBlue", textColor[2]); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorBlue", textColor[2]);
MP4SetTrackIntegerProperty(fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorAlpha", textColor[3]); MP4SetTrackIntegerProperty(_fileHandle, dstTrackId, "mdia.minf.stbl.stsd.tx3g.fontColorAlpha", textColor[3]);
/* translate the track */ /* translate the track */
if (!vPlacement) { if (!vPlacement) {
@@ -294,11 +308,11 @@
uint32_t *ptr32 = (uint32_t*) nval; uint32_t *ptr32 = (uint32_t*) nval;
uint32_t size; uint32_t size;
MP4GetTrackBytesProperty(fileHandle, dstTrackId, "tkhd.matrix", &val, &size); MP4GetTrackBytesProperty(_fileHandle, dstTrackId, "tkhd.matrix", &val, &size);
memcpy(nval, val, size); memcpy(nval, val, size);
ptr32[7] = CFSwapInt32HostToBig( (videoSize.height * 0.85) * 0x10000); ptr32[7] = CFSwapInt32HostToBig( (videoSize.height * 0.85) * 0x10000);
MP4SetTrackBytesProperty(fileHandle, dstTrackId, "tkhd.matrix", nval, size); MP4SetTrackBytesProperty(_fileHandle, dstTrackId, "tkhd.matrix", nval, size);
free(val); free(val);
} }
@@ -312,7 +326,7 @@
if ([magicCookie length] < sizeof(uint32_t) * 16) if ([magicCookie length] < sizeof(uint32_t) * 16)
continue; continue;
dstTrackId = MP4AddSubpicTrack(fileHandle, timeScale, 640, 480); dstTrackId = MP4AddSubpicTrack(_fileHandle, timeScale, 640, 480);
uint32_t *subPalette = (uint32_t*) [magicCookie bytes]; uint32_t *subPalette = (uint32_t*) [magicCookie bytes];
int ii; int ii;
@@ -326,7 +340,7 @@
palette[ii][2] = (subPalette[ii] >> 8) & 0xff; palette[ii][2] = (subPalette[ii] >> 8) & 0xff;
palette[ii][3] = (subPalette[ii]) & 0xff; palette[ii][3] = (subPalette[ii]) & 0xff;
} }
MP4SetTrackESConfiguration( fileHandle, dstTrackId, MP4SetTrackESConfiguration(_fileHandle, dstTrackId,
(uint8_t*)palette, 16 * 4 ); (uint8_t*)palette, 16 * 4 );
[helper->importer setActiveTrack:track]; [helper->importer setActiveTrack:track];
@@ -344,10 +358,10 @@
} }
if (!videoSize.width) { if (!videoSize.width) {
MP4TrackId videoTrack = findFirstVideoTrack(fileHandle); MP4TrackId videoTrack = findFirstVideoTrack(_fileHandle);
if (videoTrack) { if (videoTrack) {
videoSize.width = getFixedVideoWidth(fileHandle, videoTrack); videoSize.width = getFixedVideoWidth(_fileHandle, videoTrack);
videoSize.height = MP4GetTrackVideoHeight(fileHandle, videoTrack); videoSize.height = MP4GetTrackVideoHeight(_fileHandle, videoTrack);
} }
else { else {
videoSize.width = 640; videoSize.width = 640;
@@ -355,25 +369,16 @@
} }
} }
dstTrackId = MP4AddCCTrack(fileHandle, timeScale, videoSize.width, videoSize.height); dstTrackId = MP4AddCCTrack(_fileHandle, timeScale, videoSize.width, videoSize.height);
[helper->importer setActiveTrack:track]; [helper->importer setActiveTrack:track];
} else { } else {
// We don't know how to handle this type of track.
// Alert the user.
NSError *error = MP42Error(@"Unsupported track",
[NSString stringWithFormat:@"%@, %@, has not been muxed.", track.name, track.format],
140);
[_logger writeErrorToLog:error];
if (outError) { *outError = error; }
[unsupportedTracks addObject:track]; [unsupportedTracks addObject:track];
continue; continue;
} }
if (dstTrackId) { if (dstTrackId) {
MP4SetTrackDurationPerChunk(fileHandle, dstTrackId, timeScale / 8); MP4SetTrackDurationPerChunk(_fileHandle, dstTrackId, timeScale / 8);
track.Id = dstTrackId; track.Id = dstTrackId;
} }
} }
@@ -381,7 +386,7 @@
[_workingTracks removeObjectsInArray:unsupportedTracks]; [_workingTracks removeObjectsInArray:unsupportedTracks];
[unsupportedTracks release]; [unsupportedTracks release];
return noErr; return YES;
} }
- (void)work - (void)work
+4
View File
@@ -33,6 +33,8 @@
BOOL position_information, forced; BOOL position_information, forced;
unsigned last_begin_time, last_end_time; unsigned last_begin_time, last_end_time;
unsigned linesInput; unsigned linesInput;
BOOL ssa;
} }
-(void)addLine:(SBSubLine *)sline; -(void)addLine:(SBSubLine *)sline;
-(void)setFinished:(BOOL)finished; -(void)setFinished:(BOOL)finished;
@@ -42,6 +44,8 @@
-(void)setPositionInformation:(BOOL)info; -(void)setPositionInformation:(BOOL)info;
-(BOOL)forced; -(BOOL)forced;
-(void)setForced:(BOOL)info; -(void)setForced:(BOOL)info;
-(void)setSSA:(BOOL)ssa;
@end @end
NSMutableString *STStandardizeStringNewlines(NSString *str); NSMutableString *STStandardizeStringNewlines(NSString *str);
+11 -7
View File
@@ -118,9 +118,14 @@ canOutput:
if (l->begin_time > begin_time) if (l->begin_time > begin_time)
end_time = MIN(end_time, l->begin_time); end_time = MIN(end_time, l->begin_time);
if (l->begin_time <= begin_time) if (l->begin_time <= begin_time) {
// Try to be a bit smart and avoid duplicated lines
// from ssa.
if (!ssa || ![str containsString:l->line]) {
[str appendString:l->line]; [str appendString:l->line];
} }
}
}
for (i = 0; i < nlines; i++) { for (i = 0; i < nlines; i++) {
SBSubLine *l = [lines objectAtIndex:i - deleted]; SBSubLine *l = [lines objectAtIndex:i - deleted];
@@ -186,6 +191,11 @@ canOutput:
forced = info; forced = info;
} }
-(void)setSSA:(BOOL)isSSA
{
ssa = isSSA;
}
-(NSString*)description -(NSString*)description
{ {
return [NSString stringWithFormat:@"lines left: %lu finished inputting: %d",(unsigned long)[lines count],finished]; return [NSString stringWithFormat:@"lines left: %lu finished inputting: %d",(unsigned long)[lines count],finished];
@@ -958,12 +968,6 @@ NSString* removeNewLines(NSString* string) {
while ([mutableString length] && [mutableString characterAtIndex:[mutableString length] - 1] == '\n') while ([mutableString length] && [mutableString characterAtIndex:[mutableString length] - 1] == '\n')
[mutableString deleteCharactersInRange:NSMakeRange([mutableString length] -1, 1)]; [mutableString deleteCharactersInRange:NSMakeRange([mutableString length] -1, 1)];
NSMutableString *mutableString2 = [NSMutableString stringWithString:mutableString];
NSUInteger replacedCount = [mutableString2 replaceOccurrencesOfString:@"\n" withString:@" " options:0 range:NSMakeRange(0,[mutableString2 length])];
if (replacedCount >= 2)
return mutableString2;
else
return mutableString; return mutableString;
} }