Clean up headers and MP42SampleBuffer.
This commit is contained in:
1 parent
e2adc70d63
commit
7b1c7d0384
22 files changed
+122
-109
No files matched your search
@@ -864,8 +864,7 @@ static bool GetFirstHeader(FILE* inFile)
|
|||||||
sample->size = sampleSize;
|
sample->size = sampleSize;
|
||||||
sample->duration = MP4_INVALID_DURATION;
|
sample->duration = MP4_INVALID_DURATION;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = 0;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->isSync = 1;
|
|
||||||
sample->trackId = trackId;
|
sample->trackId = trackId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|||||||
@@ -374,8 +374,7 @@ static bool GetFirstHeader(FILE* inFile)
|
|||||||
sample->size = sampleSize;
|
sample->size = sampleSize;
|
||||||
sample->duration = MP4_INVALID_DURATION;
|
sample->duration = MP4_INVALID_DURATION;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = 0;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->isSync = 1;
|
|
||||||
sample->trackId = trackId;
|
sample->trackId = trackId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|||||||
+10
-10
@@ -418,14 +418,14 @@
|
|||||||
@"Encoding Tool", AVMetadataCommonKeySoftware,
|
@"Encoding Tool", AVMetadataCommonKeySoftware,
|
||||||
nil];
|
nil];
|
||||||
|
|
||||||
_metadata = [[MP42Metadata alloc] init];
|
self.metadata = [[[MP42Metadata alloc] init] autorelease];
|
||||||
|
|
||||||
for (NSString *commonKey in commonItemsDict.allKeys) {
|
for (NSString *commonKey in commonItemsDict.allKeys) {
|
||||||
NSArray<AVMetadataItem *> *items = [AVMetadataItem metadataItemsFromArray:_localAsset.commonMetadata
|
NSArray<AVMetadataItem *> *items = [AVMetadataItem metadataItemsFromArray:_localAsset.commonMetadata
|
||||||
withKey:commonKey
|
withKey:commonKey
|
||||||
keySpace:AVMetadataKeySpaceCommon];
|
keySpace:AVMetadataKeySpaceCommon];
|
||||||
if (items.count) {
|
if (items.count) {
|
||||||
[_metadata setTag:items.lastObject.value forKey:commonItemsDict[commonKey]];
|
[self.metadata setTag:items.lastObject.value forKey:commonItemsDict[commonKey]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@
|
|||||||
|
|
||||||
if ([artworkData isKindOfClass:[NSData class]]) {
|
if ([artworkData isKindOfClass:[NSData class]]) {
|
||||||
NSImage *image = [[NSImage alloc] initWithData:artworkData];
|
NSImage *image = [[NSImage alloc] initWithData:artworkData];
|
||||||
[_metadata.artworks addObject:[[[MP42Image alloc] initWithImage:image] autorelease]];
|
[self.metadata.artworks addObject:[[[MP42Image alloc] initWithImage:image] autorelease]];
|
||||||
[image release];
|
[image release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,7 +523,7 @@
|
|||||||
for (NSString *itunesKey in itunesMetadataDict.allKeys) {
|
for (NSString *itunesKey in itunesMetadataDict.allKeys) {
|
||||||
items = [AVMetadataItem metadataItemsFromArray:itunesMetadata withKey:itunesKey keySpace:AVMetadataKeySpaceiTunes];
|
items = [AVMetadataItem metadataItemsFromArray:itunesMetadata withKey:itunesKey keySpace:AVMetadataKeySpaceiTunes];
|
||||||
if (items.count) {
|
if (items.count) {
|
||||||
[_metadata setTag:items.lastObject.value forKey:itunesMetadataDict[itunesKey]];
|
[self.metadata setTag:items.lastObject.value forKey:itunesMetadataDict[itunesKey]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -569,7 +569,7 @@
|
|||||||
for (NSString *qtKey in quicktimeMetadataDict.allKeys) {
|
for (NSString *qtKey in quicktimeMetadataDict.allKeys) {
|
||||||
items = [AVMetadataItem metadataItemsFromArray:quicktimeMetadata withKey:qtKey keySpace:AVMetadataKeySpaceQuickTimeUserData];
|
items = [AVMetadataItem metadataItemsFromArray:quicktimeMetadata withKey:qtKey keySpace:AVMetadataKeySpaceQuickTimeUserData];
|
||||||
if (items.count) {
|
if (items.count) {
|
||||||
[_metadata setTag:items.lastObject.value forKey:quicktimeMetadataDict[qtKey]];
|
[self.metadata setTag:items.lastObject.value forKey:quicktimeMetadataDict[qtKey]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -602,7 +602,7 @@
|
|||||||
for (NSString *qtUserDataKey in quicktimeUserDataMetadataDict.allKeys) {
|
for (NSString *qtUserDataKey in quicktimeUserDataMetadataDict.allKeys) {
|
||||||
items = [AVMetadataItem metadataItemsFromArray:quicktimeUserDataMetadata withKey:qtUserDataKey keySpace:AVMetadataKeySpaceQuickTimeUserData];
|
items = [AVMetadataItem metadataItemsFromArray:quicktimeUserDataMetadata withKey:qtUserDataKey keySpace:AVMetadataKeySpaceQuickTimeUserData];
|
||||||
if (items.count) {
|
if (items.count) {
|
||||||
[_metadata setTag:items.lastObject.value forKey:quicktimeUserDataMetadataDict[qtUserDataKey]];
|
[self.metadata setTag:items.lastObject.value forKey:quicktimeUserDataMetadataDict[qtUserDataKey]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -862,10 +862,10 @@
|
|||||||
sample->presentationTimestamp = presentationTimeStamp.value;
|
sample->presentationTimestamp = presentationTimeStamp.value;
|
||||||
sample->presentationOutputTimestamp = currentOutputTimeStamp.value;
|
sample->presentationOutputTimestamp = currentOutputTimeStamp.value;
|
||||||
sample->timescale = duration.timescale;
|
sample->timescale = duration.timescale;
|
||||||
sample->isSync = sync;
|
sample->flags |= sync ? MP42SampleBufferFlagIsSync : 0;
|
||||||
|
sample->flags |= doNotDisplay ? MP42SampleBufferFlagDoNotDisplay : 0;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
sample->attachments = (void *)attachments;
|
sample->attachments = (void *)attachments;
|
||||||
sample->doNotDisplay = doNotDisplay;
|
|
||||||
|
|
||||||
if (sample->offset < demuxHelper->minDisplayOffset) {
|
if (sample->offset < demuxHelper->minDisplayOffset) {
|
||||||
demuxHelper->minDisplayOffset = sample->offset;
|
demuxHelper->minDisplayOffset = sample->offset;
|
||||||
@@ -995,9 +995,9 @@
|
|||||||
sample->presentationTimestamp = presentationTimeStamp.value;
|
sample->presentationTimestamp = presentationTimeStamp.value;
|
||||||
sample->presentationOutputTimestamp = presentationTimeStamp.value;
|
sample->presentationOutputTimestamp = presentationTimeStamp.value;
|
||||||
sample->timescale = sampleTimingInfo.duration.timescale;
|
sample->timescale = sampleTimingInfo.duration.timescale;
|
||||||
sample->isSync = sync;
|
sample->flags |= sync ? MP42SampleBufferFlagIsSync : 0;
|
||||||
|
sample->flags |= doNotDisplay ? MP42SampleBufferFlagDoNotDisplay : 0;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
sample->doNotDisplay = doNotDisplay;
|
|
||||||
|
|
||||||
if (attachmentsSent == NO) {
|
if (attachmentsSent == NO) {
|
||||||
sample->attachments = (void *)attachments;
|
sample->attachments = (void *)attachments;
|
||||||
|
|||||||
@@ -255,7 +255,7 @@ static AVPacket * packetFromSampleBuffer(MP42SampleBuffer *sample)
|
|||||||
AVPacket *pkt = av_packet_alloc();
|
AVPacket *pkt = av_packet_alloc();
|
||||||
pkt->data = sample->data;
|
pkt->data = sample->data;
|
||||||
pkt->size = sample->size;
|
pkt->size = sample->size;
|
||||||
pkt->pts = sample->timestamp;
|
pkt->pts = sample->decodeTimestamp;
|
||||||
pkt->dts = AV_NOPTS_VALUE;
|
pkt->dts = AV_NOPTS_VALUE;
|
||||||
|
|
||||||
return pkt;
|
return pkt;
|
||||||
|
|||||||
@@ -403,8 +403,10 @@ static MP42SampleBuffer *encode(AudioConverterRef encoder, AudioFileIO *afio)
|
|||||||
|
|
||||||
sample->size = fillBufList.mBuffers[0].mDataByteSize;
|
sample->size = fillBufList.mBuffers[0].mDataByteSize;
|
||||||
sample->duration = 1024;
|
sample->duration = 1024;
|
||||||
sample->timestamp = afio->outputPos * 1024;
|
sample->decodeTimestamp = afio->outputPos * 1024;
|
||||||
sample->isSync = YES;
|
sample->presentationTimestamp = sample->decodeTimestamp;
|
||||||
|
sample->presentationOutputTimestamp = sample->decodeTimestamp;
|
||||||
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
|
|
||||||
afio->outputPos += ioOutputDataPackets;
|
afio->outputPos += ioOutputDataPackets;
|
||||||
|
|
||||||
|
|||||||
@@ -194,8 +194,8 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
|||||||
sample->size = 8;
|
sample->size = 8;
|
||||||
sample->duration = ccSample.timestamp *= 1001;
|
sample->duration = ccSample.timestamp *= 1001;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = 0;
|
sample->decodeTimestamp = 0;
|
||||||
sample->isSync = 1;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = trackId;
|
sample->trackId = trackId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
@@ -228,8 +228,8 @@ static int ParseByte(const char *string, UInt8 *byte, Boolean hex)
|
|||||||
sample->size = byteCount + 8;
|
sample->size = byteCount + 8;
|
||||||
sample->duration = sampleDuration * 1001;
|
sample->duration = sampleDuration * 1001;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = 0;
|
sample->decodeTimestamp = 0;
|
||||||
sample->isSync = 1;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = trackId;
|
sample->trackId = trackId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
[self endEditListAtTime:editEnd empty:YES];
|
[self endEditListAtTime:editEnd empty:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL shouldStartNewEdit = trimStart || (sample->doNotDisplay == NO && _editOpen == NO);
|
BOOL shouldStartNewEdit = trimStart || ((sample->flags & MP42SampleBufferFlagDoNotDisplay) == NO && _editOpen == NO);
|
||||||
|
|
||||||
if (shouldStartNewEdit) {
|
if (shouldStartNewEdit) {
|
||||||
// Close the current edit list
|
// Close the current edit list
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
|
|
||||||
_currentTime += sample->duration;
|
_currentTime += sample->duration;
|
||||||
|
|
||||||
BOOL shouldEndEdit = trimEnd || (sample->doNotDisplay == YES && _editOpen == YES);
|
BOOL shouldEndEdit = trimEnd || ((sample->flags & MP42SampleBufferFlagDoNotDisplay) == YES && _editOpen == YES);
|
||||||
|
|
||||||
if (shouldEndEdit) {
|
if (shouldEndEdit) {
|
||||||
CMTime editEnd = CMTimeMake(_currentTime, _timescale);
|
CMTime editEnd = CMTimeMake(_currentTime, _timescale);
|
||||||
|
|||||||
@@ -13,10 +13,14 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
@class MP42SampleBuffer;
|
||||||
|
|
||||||
@interface MP42FileImporter (Private)
|
@interface MP42FileImporter (Private)
|
||||||
|
|
||||||
- (instancetype)initWithURL:(NSURL *)fileURL;
|
- (instancetype)initWithURL:(NSURL *)fileURL;
|
||||||
|
|
||||||
|
@property(nonatomic, readwrite) MP42Metadata *metadata;
|
||||||
|
|
||||||
- (void)addTrack:(MP42Track *)track;
|
- (void)addTrack:(MP42Track *)track;
|
||||||
- (void)addTracks:(NSArray<MP42Track *> *)tracks;
|
- (void)addTracks:(NSArray<MP42Track *> *)tracks;
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,11 @@
|
|||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@class MP42SampleBuffer;
|
|
||||||
@class MP42Metadata;
|
@class MP42Metadata;
|
||||||
@class MP42Track;
|
@class MP42Track;
|
||||||
|
|
||||||
@interface MP42FileImporter : NSObject {
|
@interface MP42FileImporter : NSObject {
|
||||||
@protected
|
@protected
|
||||||
NSInteger _chapterId;
|
|
||||||
MP42Metadata *_metadata;
|
|
||||||
|
|
||||||
double _progress;
|
double _progress;
|
||||||
int32_t _cancelled;
|
int32_t _cancelled;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ static NSArray<NSString *> *_supportedFileFormats;
|
|||||||
[track.muxer_helper->converter release];
|
[track.muxer_helper->converter release];
|
||||||
}
|
}
|
||||||
|
|
||||||
[_metadata release], _metadata = nil;
|
[_metadata release];
|
||||||
[_tracksArray release], _tracksArray = nil;
|
[_tracksArray release], _tracksArray = nil;
|
||||||
[_inputTracks release], _inputTracks = nil;
|
[_inputTracks release], _inputTracks = nil;
|
||||||
[_outputsTracks release], _outputsTracks = nil;
|
[_outputsTracks release], _outputsTracks = nil;
|
||||||
@@ -162,7 +162,11 @@ static NSArray<NSString *> *_supportedFileFormats;
|
|||||||
return [[_outputsTracks copy] autorelease];
|
return [[_outputsTracks copy] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
@synthesize metadata = _metadata;
|
- (void)setMetadata:(MP42Metadata * _Nonnull)metadata
|
||||||
|
{
|
||||||
|
_metadata = [metadata retain];
|
||||||
|
}
|
||||||
|
|
||||||
@synthesize tracks = _tracksArray;
|
@synthesize tracks = _tracksArray;
|
||||||
|
|
||||||
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
- (NSUInteger)timescaleForTrack:(MP42Track *)track
|
||||||
|
|||||||
@@ -1499,9 +1499,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
|||||||
sample->data = sampleData;
|
sample->data = sampleData;
|
||||||
sample->size = nal_buffer_size;
|
sample->size = nal_buffer_size;
|
||||||
sample->duration = mp4FrameDuration;
|
sample->duration = mp4FrameDuration;
|
||||||
sample->offset = 0;
|
sample->flags = nal_is_sync ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->timestamp = 0;
|
|
||||||
sample->isSync = nal_is_sync;
|
|
||||||
sample->trackId = trackId;
|
sample->trackId = trackId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
@@ -1588,9 +1586,7 @@ NSData* H264Info(const char *filePath, uint32_t *pic_width, uint32_t *pic_height
|
|||||||
sample->data = sampleData;
|
sample->data = sampleData;
|
||||||
sample->size = nal_buffer_size;
|
sample->size = nal_buffer_size;
|
||||||
sample->duration = mp4FrameDuration;
|
sample->duration = mp4FrameDuration;
|
||||||
sample->offset = 0;
|
sample->flags = nal_is_sync ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->timestamp = 0;
|
|
||||||
sample->isSync = nal_is_sync;
|
|
||||||
sample->trackId = trackId;
|
sample->trackId = trackId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|||||||
+17
-17
@@ -298,7 +298,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
|
|
||||||
free(trackSizes);
|
free(trackSizes);
|
||||||
|
|
||||||
_metadata = [[self readMatroskaMetadata] retain];
|
self.metadata = [self readMatroskaMetadata];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -677,15 +677,15 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
sample->size = FrameSize;
|
sample->size = FrameSize;
|
||||||
sample->duration = MP4_INVALID_DURATION;
|
sample->duration = MP4_INVALID_DURATION;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = StartTime;
|
sample->decodeTimestamp = StartTime;
|
||||||
sample->isSync = YES;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
#define VARIABLE_AUDIO_RATE 1
|
#define VARIABLE_AUDIO_RATE 1
|
||||||
|
|
||||||
#ifdef VARIABLE_AUDIO_RATE
|
#ifdef VARIABLE_AUDIO_RATE
|
||||||
if (demuxHelper->previousSample) {
|
if (demuxHelper->previousSample) {
|
||||||
uint64_t sampleDuration = (sample->timestamp * (double)mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq) / 1000000000.f) - demuxHelper->currentTime;
|
uint64_t sampleDuration = (sample->decodeTimestamp * (double)mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq) / 1000000000.f) - demuxHelper->currentTime;
|
||||||
|
|
||||||
// MKV timestamps are a bit random, try to round them
|
// MKV timestamps are a bit random, try to round them
|
||||||
// to make the sample table in the mp4 smaller.
|
// to make the sample table in the mp4 smaller.
|
||||||
@@ -710,7 +710,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
|
|
||||||
demuxHelper->currentTime += sampleDuration;
|
demuxHelper->currentTime += sampleDuration;
|
||||||
} else {
|
} else {
|
||||||
demuxHelper->currentTime = sample->timestamp * (double)mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq) / 1000000000.f;
|
demuxHelper->currentTime = sample->decodeTimestamp * (double)mkv_TruncFloat(trackInfo->AV.Audio.SamplingFreq) / 1000000000.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
[demuxHelper->previousSample release];
|
[demuxHelper->previousSample release];
|
||||||
@@ -748,10 +748,10 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
|
|
||||||
nextSample->duration = 0;
|
nextSample->duration = 0;
|
||||||
nextSample->offset = 0;
|
nextSample->offset = 0;
|
||||||
nextSample->timestamp = StartTime;
|
nextSample->decodeTimestamp = StartTime;
|
||||||
nextSample->data = frame;
|
nextSample->data = frame;
|
||||||
nextSample->size = FrameSize;
|
nextSample->size = FrameSize;
|
||||||
nextSample->isSync = YES;
|
nextSample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
nextSample->trackId = track.sourceId;
|
nextSample->trackId = track.sourceId;
|
||||||
|
|
||||||
// PGS are usually stored with just the start time, and blank samples to fill the gaps
|
// PGS are usually stored with just the start time, and blank samples to fill the gaps
|
||||||
@@ -760,18 +760,18 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
demuxHelper->previousSample = [[MP42SampleBuffer alloc] init];
|
demuxHelper->previousSample = [[MP42SampleBuffer alloc] init];
|
||||||
demuxHelper->previousSample->duration = StartTime / SCALE_FACTOR;
|
demuxHelper->previousSample->duration = StartTime / SCALE_FACTOR;
|
||||||
demuxHelper->previousSample->offset = 0;
|
demuxHelper->previousSample->offset = 0;
|
||||||
demuxHelper->previousSample->timestamp = StartTime;
|
demuxHelper->previousSample->decodeTimestamp = StartTime;
|
||||||
demuxHelper->previousSample->isSync = YES;
|
demuxHelper->previousSample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
demuxHelper->previousSample->trackId = track.sourceId;
|
demuxHelper->previousSample->trackId = track.sourceId;
|
||||||
} else {
|
} else {
|
||||||
if (nextSample->timestamp < demuxHelper->previousSample->timestamp) {
|
if (nextSample->decodeTimestamp < demuxHelper->previousSample->decodeTimestamp) {
|
||||||
// Out of order samples? swap the next with the previous
|
// Out of order samples? swap the next with the previous
|
||||||
MP42SampleBuffer *temp = nextSample;
|
MP42SampleBuffer *temp = nextSample;
|
||||||
nextSample = demuxHelper->previousSample;
|
nextSample = demuxHelper->previousSample;
|
||||||
demuxHelper->previousSample = temp;
|
demuxHelper->previousSample = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
demuxHelper->previousSample->duration = (nextSample->timestamp - demuxHelper->previousSample->timestamp) / SCALE_FACTOR;
|
demuxHelper->previousSample->duration = (nextSample->decodeTimestamp - demuxHelper->previousSample->decodeTimestamp) / SCALE_FACTOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self enqueue:demuxHelper->previousSample];
|
[self enqueue:demuxHelper->previousSample];
|
||||||
@@ -786,7 +786,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
sample->duration = (StartTime - demuxHelper->currentTime) / SCALE_FACTOR;
|
sample->duration = (StartTime - demuxHelper->currentTime) / SCALE_FACTOR;
|
||||||
sample->size = 2;
|
sample->size = 2;
|
||||||
sample->data = calloc(1, 2);
|
sample->data = calloc(1, 2);
|
||||||
sample->isSync = YES;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
@@ -845,8 +845,8 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
sample->size = currentSample->frameSize;
|
sample->size = currentSample->frameSize;
|
||||||
sample->duration = duration / 10000.0f;
|
sample->duration = duration / 10000.0f;
|
||||||
sample->offset = offset / 10000.0f;
|
sample->offset = offset / 10000.0f;
|
||||||
sample->timestamp = StartTime;
|
sample->decodeTimestamp = StartTime;
|
||||||
sample->isSync = currentSample->frameFlags & FRAME_KF;
|
sample->flags |= (currentSample->frameFlags & FRAME_KF) ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
demuxHelper->samplesWritten++;
|
demuxHelper->samplesWritten++;
|
||||||
@@ -919,8 +919,8 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
sample->size = currentSample->frameSize;
|
sample->size = currentSample->frameSize;
|
||||||
sample->duration = duration / 10000.0f;
|
sample->duration = duration / 10000.0f;
|
||||||
sample->offset = offset / 10000.0f;
|
sample->offset = offset / 10000.0f;
|
||||||
sample->timestamp = StartTime;
|
sample->decodeTimestamp = StartTime;
|
||||||
sample->isSync = currentSample->frameFlags & FRAME_KF;
|
sample->flags |= (currentSample->frameFlags & FRAME_KF) ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
demuxHelper->samplesWritten++;
|
demuxHelper->samplesWritten++;
|
||||||
@@ -970,7 +970,7 @@ int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
demuxHelper->currentTime += sample->duration;
|
demuxHelper->currentTime += sample->duration;
|
||||||
sample->timestamp = demuxHelper->currentTime;
|
sample->decodeTimestamp = demuxHelper->currentTime;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
[sample release];
|
[sample release];
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[self addTracks:sourceFile.tracks];
|
[self addTracks:sourceFile.tracks];
|
||||||
_metadata = [sourceFile.metadata retain];
|
self.metadata = sourceFile.metadata;
|
||||||
|
|
||||||
[sourceFile release];
|
[sourceFile release];
|
||||||
}
|
}
|
||||||
@@ -326,8 +326,8 @@
|
|||||||
sample->size = numBytes;
|
sample->size = numBytes;
|
||||||
sample->duration = duration;
|
sample->duration = duration;
|
||||||
sample->offset = renderingOffset;
|
sample->offset = renderingOffset;
|
||||||
sample->timestamp = pStartTime;
|
sample->decodeTimestamp = pStartTime;
|
||||||
sample->isSync = isSyncSample;
|
sample->flags |= isSyncSample ? MP42SampleBufferFlagIsSync : 0;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|||||||
+3
-2
@@ -503,6 +503,7 @@
|
|||||||
// Iterate the tracks array and mux the samples
|
// Iterate the tracks array and mux the samples
|
||||||
for (MP42Track *track in _workingTracks) {
|
for (MP42Track *track in _workingTracks) {
|
||||||
MP42SampleBuffer *sampleBuffer = nil;
|
MP42SampleBuffer *sampleBuffer = nil;
|
||||||
|
MP42TrackId trackId = track.trackId;
|
||||||
|
|
||||||
for (int i = 0; i < 100 && (sampleBuffer = [track copyNextSample]) != nil; i++) {
|
for (int i = 0; i < 100 && (sampleBuffer = [track copyNextSample]) != nil; i++) {
|
||||||
|
|
||||||
@@ -511,10 +512,10 @@
|
|||||||
track.muxer_helper->done = 1;
|
track.muxer_helper->done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!MP4WriteSample(_fileHandle, track.trackId,
|
else if (!MP4WriteSample(_fileHandle, trackId,
|
||||||
sampleBuffer->data, sampleBuffer->size,
|
sampleBuffer->data, sampleBuffer->size,
|
||||||
sampleBuffer->duration, sampleBuffer->offset,
|
sampleBuffer->duration, sampleBuffer->offset,
|
||||||
sampleBuffer->isSync)) {
|
sampleBuffer->flags & MP42SampleBufferFlagIsSync)) {
|
||||||
_cancelled = YES;
|
_cancelled = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -9,7 +9,10 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
|
typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
|
||||||
MP42SampleBufferFlagEndOfFile = 1 << 0,
|
MP42SampleBufferFlagEndOfFile = 1 << 0,
|
||||||
|
MP42SampleBufferFlagIsSync = 1 << 1,
|
||||||
|
MP42SampleBufferFlagIsForced = 1 << 2,
|
||||||
|
MP42SampleBufferFlagDoNotDisplay = 1 << 3
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface MP42SampleBuffer : NSObject {
|
@interface MP42SampleBuffer : NSObject {
|
||||||
@@ -23,16 +26,12 @@ typedef NS_OPTIONS(NSUInteger, MP42SampleBufferFlag) {
|
|||||||
|
|
||||||
int64_t presentationTimestamp;
|
int64_t presentationTimestamp;
|
||||||
int64_t presentationOutputTimestamp;
|
int64_t presentationOutputTimestamp;
|
||||||
uint64_t timestamp;
|
uint64_t decodeTimestamp;
|
||||||
|
|
||||||
uint32_t trackId;
|
uint32_t trackId;
|
||||||
|
|
||||||
BOOL isSync;
|
|
||||||
BOOL isForced;
|
|
||||||
BOOL doNotDisplay;
|
|
||||||
|
|
||||||
void *attachments;
|
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
|
void *attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -1063,8 +1063,8 @@ MP42SampleBuffer * copySubtitleSample(MP4TrackId subtitleTrackId, NSString *stri
|
|||||||
sample->size = sampleSize;
|
sample->size = sampleSize;
|
||||||
sample->duration = duration;
|
sample->duration = duration;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = duration;
|
sample->decodeTimestamp = duration;
|
||||||
sample->isSync = true;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = subtitleTrackId;
|
sample->trackId = subtitleTrackId;
|
||||||
|
|
||||||
return sample;
|
return sample;
|
||||||
@@ -1083,8 +1083,8 @@ MP42SampleBuffer* copyEmptySubtitleSample(MP4TrackId subtitleTrackId, MP4Duratio
|
|||||||
sample->size = 2;
|
sample->size = 2;
|
||||||
sample->duration = duration;
|
sample->duration = duration;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = duration;
|
sample->decodeTimestamp = duration;
|
||||||
sample->isSync = true;
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = subtitleTrackId;
|
sample->trackId = subtitleTrackId;
|
||||||
|
|
||||||
return sample;
|
return sample;
|
||||||
|
|||||||
@@ -31,9 +31,13 @@
|
|||||||
_mediaType = MP42MediaTypeSubtitle;
|
_mediaType = MP42MediaTypeSubtitle;
|
||||||
|
|
||||||
if (![_format isEqualToString:MP42SubtitleFormatVobSub]) {
|
if (![_format isEqualToString:MP42SubtitleFormatVobSub]) {
|
||||||
|
uint64_t width, height;
|
||||||
|
|
||||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", &height);
|
|
||||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", &width);
|
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", &width);
|
||||||
|
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", &height);
|
||||||
|
|
||||||
|
self.width = width;
|
||||||
|
self.height = height;
|
||||||
|
|
||||||
uint64_t displayFlags = 0;
|
uint64_t displayFlags = 0;
|
||||||
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.displayFlags", &displayFlags);
|
MP4GetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.displayFlags", &displayFlags);
|
||||||
@@ -104,9 +108,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_isEdited && !_muxed) {
|
if (_isEdited && !_muxed) {
|
||||||
|
float trackWidth, trackHeight;
|
||||||
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", &trackWidth);
|
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", &trackWidth);
|
||||||
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", &trackHeight);
|
MP4GetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", &trackHeight);
|
||||||
|
|
||||||
|
self.trackWidth = trackWidth;
|
||||||
|
self.trackHeight = trackHeight;
|
||||||
|
|
||||||
uint8_t *val;
|
uint8_t *val;
|
||||||
uint8_t nval[36];
|
uint8_t nval[36];
|
||||||
uint32_t *ptr32 = (uint32_t*) nval;
|
uint32_t *ptr32 = (uint32_t*) nval;
|
||||||
@@ -114,8 +122,8 @@
|
|||||||
|
|
||||||
MP4GetTrackBytesProperty(fileHandle ,_trackId, "tkhd.matrix", &val, &size);
|
MP4GetTrackBytesProperty(fileHandle ,_trackId, "tkhd.matrix", &val, &size);
|
||||||
memcpy(nval, val, size);
|
memcpy(nval, val, size);
|
||||||
offsetX = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
self.offsetX = CFSwapInt32BigToHost(ptr32[6]) / 0x10000;
|
||||||
offsetY = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
self.offsetY = CFSwapInt32BigToHost(ptr32[7]) / 0x10000;
|
||||||
free(val);
|
free(val);
|
||||||
|
|
||||||
[super writeToFile:fileHandle error:outError];
|
[super writeToFile:fileHandle error:outError];
|
||||||
@@ -127,8 +135,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (![_format isEqualToString:MP42SubtitleFormatVobSub]) {
|
if (![_format isEqualToString:MP42SubtitleFormatVobSub]) {
|
||||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", trackHeight);
|
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxBottom", self.trackHeight);
|
||||||
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", trackWidth);
|
MP4SetTrackIntegerProperty(fileHandle, _trackId, "mdia.minf.stbl.stsd.tx3g.defTextBoxRight", self.trackWidth);
|
||||||
|
|
||||||
uint32_t displayFlags = 0;
|
uint32_t displayFlags = 0;
|
||||||
if (_verticalPlacement)
|
if (_verticalPlacement)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@interface MP42Track : NSObject <NSCoding, NSCopying> {
|
@interface MP42Track : NSObject <NSCoding, NSCopying> {
|
||||||
@protected
|
@protected
|
||||||
MP42TrackId _trackId;
|
MP42TrackId _trackId;
|
||||||
MP42TrackId _sourceId;
|
|
||||||
|
|
||||||
NSURL *_sourceURL;
|
NSURL *_sourceURL;
|
||||||
NSString *_format;
|
NSString *_format;
|
||||||
@@ -34,19 +33,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
BOOL _muxed;
|
BOOL _muxed;
|
||||||
BOOL _needConversion;
|
BOOL _needConversion;
|
||||||
|
|
||||||
uint64_t _size;
|
|
||||||
uint32_t _timescale;
|
uint32_t _timescale;
|
||||||
uint32_t _bitrate;
|
|
||||||
MP42Duration _duration;
|
MP42Duration _duration;
|
||||||
|
|
||||||
NSMutableDictionary<NSString *, NSNumber *> *_updatedProperty;
|
NSMutableDictionary<NSString *, NSNumber *> *_updatedProperty;
|
||||||
|
|
||||||
@private
|
|
||||||
NSSet<NSString *> *_mediaCharacteristicTags;
|
|
||||||
|
|
||||||
uint64_t _alternate_group;
|
|
||||||
int64_t _startOffset;
|
|
||||||
|
|
||||||
void *_helper;
|
void *_helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,17 @@
|
|||||||
#import "MP42Track+Muxer.h"
|
#import "MP42Track+Muxer.h"
|
||||||
|
|
||||||
@implementation MP42Track
|
@implementation MP42Track
|
||||||
|
{
|
||||||
|
MP42TrackId _sourceId;
|
||||||
|
|
||||||
|
uint64_t _size;
|
||||||
|
uint32_t _bitrate;
|
||||||
|
|
||||||
|
NSSet<NSString *> *_mediaCharacteristicTags;
|
||||||
|
|
||||||
|
uint64_t _alternate_group;
|
||||||
|
int64_t _startOffset;
|
||||||
|
}
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-21
@@ -9,27 +9,7 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "MP42Track.h"
|
#import "MP42Track.h"
|
||||||
|
|
||||||
@interface MP42VideoTrack : MP42Track <NSCoding> {
|
@interface MP42VideoTrack : MP42Track <NSCoding>
|
||||||
@protected
|
|
||||||
uint64_t width, height;
|
|
||||||
float trackWidth, trackHeight;
|
|
||||||
|
|
||||||
// Pixel Aspect Ratio
|
|
||||||
uint64_t hSpacing, vSpacing;
|
|
||||||
|
|
||||||
// Clean Aperture
|
|
||||||
uint64_t cleanApertureWidthN, cleanApertureWidthD;
|
|
||||||
uint64_t cleanApertureHeightN, cleanApertureHeightD;
|
|
||||||
uint64_t horizOffN, horizOffD;
|
|
||||||
uint64_t vertOffN, vertOffD;
|
|
||||||
|
|
||||||
// Matrix
|
|
||||||
uint32_t offsetX, offsetY;
|
|
||||||
|
|
||||||
// H.264 profile
|
|
||||||
uint8_t _origProfile, _origLevel;
|
|
||||||
uint8_t _newProfile, _newLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property(nonatomic, readwrite) uint64_t width;
|
@property(nonatomic, readwrite) uint64_t width;
|
||||||
@property(nonatomic, readwrite) uint64_t height;
|
@property(nonatomic, readwrite) uint64_t height;
|
||||||
|
|||||||
+21
-1
@@ -13,6 +13,27 @@
|
|||||||
#import <mp4v2.h>
|
#import <mp4v2.h>
|
||||||
|
|
||||||
@implementation MP42VideoTrack
|
@implementation MP42VideoTrack
|
||||||
|
{
|
||||||
|
uint64_t width, height;
|
||||||
|
float trackWidth, trackHeight;
|
||||||
|
|
||||||
|
// Pixel Aspect Ratio
|
||||||
|
uint64_t hSpacing, vSpacing;
|
||||||
|
|
||||||
|
// Clean Aperture
|
||||||
|
uint64_t cleanApertureWidthN, cleanApertureWidthD;
|
||||||
|
uint64_t cleanApertureHeightN, cleanApertureHeightD;
|
||||||
|
uint64_t horizOffN, horizOffD;
|
||||||
|
uint64_t vertOffN, vertOffD;
|
||||||
|
|
||||||
|
// Matrix
|
||||||
|
uint32_t offsetX, offsetY;
|
||||||
|
|
||||||
|
// H.264 profile
|
||||||
|
uint8_t _origProfile, _origLevel;
|
||||||
|
uint8_t _newProfile, _newLevel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle
|
- (instancetype)initWithSourceURL:(NSURL *)URL trackID:(NSInteger)trackID fileHandle:(MP42FileHandle)fileHandle
|
||||||
{
|
{
|
||||||
@@ -93,7 +114,6 @@
|
|||||||
|
|
||||||
if (trackWidth > 0 && trackHeight > 0) {
|
if (trackWidth > 0 && trackHeight > 0) {
|
||||||
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", trackWidth);
|
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.width", trackWidth);
|
||||||
|
|
||||||
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", trackHeight);
|
MP4SetTrackFloatProperty(fileHandle, _trackId, "tkhd.height", trackHeight);
|
||||||
|
|
||||||
uint8_t *val;
|
uint8_t *val;
|
||||||
|
|||||||
@@ -364,8 +364,10 @@ static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSStr
|
|||||||
sample->data = calloc(1, 2);
|
sample->data = calloc(1, 2);
|
||||||
sample->duration = startTime - lastTime;
|
sample->duration = startTime - lastTime;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = startTime;
|
sample->presentationTimestamp = startTime;
|
||||||
sample->isSync = YES;
|
sample->presentationOutputTimestamp = startTime;
|
||||||
|
sample->decodeTimestamp = startTime;
|
||||||
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
@@ -377,8 +379,10 @@ static NSArray<SBVobSubTrack *> * LoadVobSubSubtitles(NSURL *theDirectory, NSStr
|
|||||||
sample->size = size;
|
sample->size = size;
|
||||||
sample->duration = duration;
|
sample->duration = duration;
|
||||||
sample->offset = 0;
|
sample->offset = 0;
|
||||||
sample->timestamp = startTime;
|
sample->presentationTimestamp = startTime;
|
||||||
sample->isSync = YES;
|
sample->presentationOutputTimestamp = startTime;
|
||||||
|
sample->decodeTimestamp = startTime;
|
||||||
|
sample->flags |= MP42SampleBufferFlagIsSync;
|
||||||
sample->trackId = track.sourceId;
|
sample->trackId = track.sourceId;
|
||||||
|
|
||||||
[self enqueue:sample];
|
[self enqueue:sample];
|
||||||
|
|||||||
Reference in new issue
Block a user