Remove the aac priming delay from the edit list media time.
This commit is contained in:
1 parent
f710cf7ac2
commit
4e0d573c5b
3 files changed
+53
-22
No files matched your search
@@ -768,7 +768,7 @@
|
|||||||
track.muxer_helper->demuxer_context = [[AVFDemuxHelper alloc] init];
|
track.muxer_helper->demuxer_context = [[AVFDemuxHelper alloc] init];
|
||||||
demuxHelper = track.muxer_helper->demuxer_context;
|
demuxHelper = track.muxer_helper->demuxer_context;
|
||||||
demuxHelper->assetReaderOutput = assetReaderOutput;
|
demuxHelper->assetReaderOutput = assetReaderOutput;
|
||||||
demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] init];
|
demuxHelper->editsConstructor = [[MP42EditListsReconstructor alloc] initWithMediaFormat:track.format];
|
||||||
|
|
||||||
totalDataLength += [track dataLength];
|
totalDataLength += [track dataLength];
|
||||||
}
|
}
|
||||||
@@ -819,7 +819,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_Default);
|
CMTime currentOutputTimeStamp = CMTimeConvertScale(presentationOutputTimeStamp, duration.timescale, kCMTimeRoundingMethod_QuickTime);
|
||||||
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(NULL, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
|
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(NULL, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
|
||||||
|
|
||||||
#ifdef SB_AVF_DEBUG
|
#ifdef SB_AVF_DEBUG
|
||||||
@@ -1033,11 +1033,12 @@
|
|||||||
// Add back the new constructed edit lists.
|
// Add back the new constructed edit lists.
|
||||||
for (uint64_t i = 0; i < helper->editsConstructor.editsCount; i++) {
|
for (uint64_t i = 0; i < helper->editsConstructor.editsCount; i++) {
|
||||||
CMTimeRange timeRange = helper->editsConstructor.edits[i];
|
CMTimeRange timeRange = helper->editsConstructor.edits[i];
|
||||||
CMTime duration = CMTimeConvertScale(timeRange.duration, timescale, kCMTimeRoundingMethod_Default);
|
CMTime duration = CMTimeConvertScale(timeRange.duration, timescale, kCMTimeRoundingMethod_QuickTime);
|
||||||
|
|
||||||
trackDuration += duration.value;
|
trackDuration += duration.value;
|
||||||
|
|
||||||
MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID, timeRange.start.value - helper->minDisplayOffset,
|
MP4AddTrackEdit(fileHandle, trackId, MP4_INVALID_EDIT_ID,
|
||||||
|
timeRange.start.value - helper->minDisplayOffset,
|
||||||
duration.value, 0);
|
duration.value, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,19 @@
|
|||||||
|
|
||||||
int64_t _delta;
|
int64_t _delta;
|
||||||
|
|
||||||
CMTimeRange *_edits;
|
CMTimeRange *_edits;
|
||||||
uint64_t _editsCount;
|
uint64_t _editsCount;
|
||||||
uint64_t _editsSize;
|
uint64_t _editsSize;
|
||||||
|
|
||||||
BOOL _editOpen;
|
BOOL _editOpen;
|
||||||
|
|
||||||
|
FourCharCode _format;
|
||||||
|
uint64_t _priming;
|
||||||
|
BOOL _primingUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithMediaFormat:(NSString *)format;
|
||||||
|
|
||||||
- (void)addSample:(MP42SampleBuffer *)sample;
|
- (void)addSample:(MP42SampleBuffer *)sample;
|
||||||
- (void)done;
|
- (void)done;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "MP42EditListsReconstructor.h"
|
#import "MP42EditListsReconstructor.h"
|
||||||
|
#import "MP42MediaFormat.h"
|
||||||
|
|
||||||
@implementation MP42EditListsReconstructor
|
@implementation MP42EditListsReconstructor
|
||||||
|
|
||||||
@@ -14,11 +15,25 @@
|
|||||||
@synthesize editsCount = _editsCount;
|
@synthesize editsCount = _editsCount;
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
|
self = [self initWithMediaFormat:0];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithMediaFormat:(NSString *)format {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if (self) {
|
if (self) {
|
||||||
_priorityQueue = [[MP42Heap alloc] initWithCapacity:32 andComparator:^NSComparisonResult(MP42SampleBuffer * obj1, MP42SampleBuffer * obj2) {
|
_priorityQueue = [[MP42Heap alloc] initWithCapacity:32 andComparator:^NSComparisonResult(MP42SampleBuffer * obj1, MP42SampleBuffer * obj2) {
|
||||||
return obj2->presentationTimestamp - obj1->presentationTimestamp;
|
return obj2->presentationTimestamp - obj1->presentationTimestamp;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
||||||
|
if ([format isEqualToString:MP42AudioFormatAAC]) {
|
||||||
|
_priming = 2112;
|
||||||
|
}
|
||||||
|
else if ([format isEqualToString:MP42AudioFormatHEAAC])
|
||||||
|
{
|
||||||
|
_priming = 4224;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -36,14 +51,6 @@
|
|||||||
|
|
||||||
[_priorityQueue insert:sample];
|
[_priorityQueue insert:sample];
|
||||||
|
|
||||||
if (_timescale == 0) {
|
|
||||||
_timescale = sample->timescale;
|
|
||||||
// Re-align things if the first sample pts is not 0
|
|
||||||
if (sample->presentationTimestamp != 0) {
|
|
||||||
_currentTime += sample->presentationTimestamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([_priorityQueue isFull]) {
|
if ([_priorityQueue isFull]) {
|
||||||
MP42SampleBuffer *extractedSample = [_priorityQueue extract];
|
MP42SampleBuffer *extractedSample = [_priorityQueue extract];
|
||||||
[self analyzeSample:extractedSample];
|
[self analyzeSample:extractedSample];
|
||||||
@@ -60,7 +67,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_editOpen == YES) {
|
if (_editOpen == YES) {
|
||||||
[self endEditListAtTime:CMTimeMake(_currentTime, _timescale) empty:NO];
|
CMTime editEnd = CMTimeMake(_currentTime, _timescale);
|
||||||
|
[self endEditListAtTime:editEnd empty:NO];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,16 +77,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)analyzeSample:(MP42SampleBuffer *)sample {
|
- (void)analyzeSample:(MP42SampleBuffer *)sample {
|
||||||
|
|
||||||
|
#ifdef AVF_DEBUG
|
||||||
|
NSLog(@"T: %llu, P: %lld, PO: %lld O: %lld", _currentTime, sample->presentationTimestamp, sample->presentationOutputTimestamp, sample->offset);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (_timescale == 0) {
|
||||||
|
_timescale = sample->timescale;
|
||||||
|
// Re-align things if the first sample pts is not 0
|
||||||
|
if (sample->presentationTimestamp != 0) {
|
||||||
|
_currentTime += sample->presentationTimestamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CFDictionaryRef trimStart = NULL, trimEnd = NULL;
|
CFDictionaryRef trimStart = NULL, trimEnd = NULL;
|
||||||
if (sample->attachments) {
|
if (sample->attachments) {
|
||||||
trimStart = CFDictionaryGetValue(sample->attachments, kCMSampleBufferAttachmentKey_TrimDurationAtStart);
|
trimStart = CFDictionaryGetValue(sample->attachments, kCMSampleBufferAttachmentKey_TrimDurationAtStart);
|
||||||
trimEnd = CFDictionaryGetValue(sample->attachments, kCMSampleBufferAttachmentKey_TrimDurationAtEnd);
|
trimEnd = CFDictionaryGetValue(sample->attachments, kCMSampleBufferAttachmentKey_TrimDurationAtEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef AVF_DEBUG
|
// Check if we need to add an empty edit list.
|
||||||
NSLog(@"T: %llu, P: %llu, PO: %llu", _currentTime, sample->presentationTimestamp, sample->presentationOutputTimestamp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (sample->presentationOutputTimestamp > sample->presentationTimestamp + _delta) {
|
if (sample->presentationOutputTimestamp > sample->presentationTimestamp + _delta) {
|
||||||
_delta = sample->presentationOutputTimestamp - sample->presentationTimestamp;
|
_delta = sample->presentationOutputTimestamp - sample->presentationTimestamp;
|
||||||
|
|
||||||
@@ -106,10 +124,15 @@
|
|||||||
|
|
||||||
if (trimStart) {
|
if (trimStart) {
|
||||||
CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart);
|
CMTime trimStartTime = CMTimeMakeFromDictionary(trimStart);
|
||||||
trimStartTime = CMTimeConvertScale(trimStartTime, _timescale, kCMTimeRoundingMethod_Default);
|
trimStartTime = CMTimeConvertScale(trimStartTime, _timescale, kCMTimeRoundingMethod_QuickTime);
|
||||||
editStart.value += trimStartTime.value;
|
editStart.value += trimStartTime.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_priming && _primingUsed == NO) {
|
||||||
|
editStart.value -= _priming;
|
||||||
|
_primingUsed = YES;
|
||||||
|
}
|
||||||
|
|
||||||
[self startEditListAtTime:editStart];
|
[self startEditListAtTime:editStart];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +145,7 @@
|
|||||||
|
|
||||||
if (trimEnd) {
|
if (trimEnd) {
|
||||||
CMTime trimEndTime = CMTimeMakeFromDictionary(trimEnd);
|
CMTime trimEndTime = CMTimeMakeFromDictionary(trimEnd);
|
||||||
trimEndTime = CMTimeConvertScale(trimEndTime, _timescale, kCMTimeRoundingMethod_Default);
|
trimEndTime = CMTimeConvertScale(trimEndTime, _timescale, kCMTimeRoundingMethod_QuickTime);
|
||||||
editEnd.value -= trimEndTime.value;
|
editEnd.value -= trimEndTime.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user