From b20dac505d44a35a8feaef763e52c84c8fe24f99 Mon Sep 17 00:00:00 2001 From: Single Date: Thu, 28 Nov 2019 15:32:15 +0800 Subject: [PATCH] SGVideoDecoder: Reset frame rate. --- .../Classes/Core/SGDecoder/SGVideoDecoder.m | 26 ++++++++++++++++++- .../Classes/Core/SGOption/SGDecoderOptions.m | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/SGPlayer/Classes/Core/SGDecoder/SGVideoDecoder.m b/SGPlayer/Classes/Core/SGDecoder/SGVideoDecoder.m index 2611532d..461f5eae 100644 --- a/SGPlayer/Classes/Core/SGDecoder/SGVideoDecoder.m +++ b/SGPlayer/Classes/Core/SGDecoder/SGVideoDecoder.m @@ -340,7 +340,31 @@ - (void)flush - (NSArray<__kindof SGFrame *> *)resampleFrames:(NSArray<__kindof SGFrame *> *)frames { - return frames; + if (!self->_options.resetFrameRate && + CMTIME_IS_NUMERIC(self->_options.preferredFrameRate)) { + return frames; + } + CMTime frameRate = self->_options.preferredFrameRate; + NSMutableArray *ret = [NSMutableArray array]; + for (SGVideoFrame *obj in frames) { + SGVideoFrame *frame = obj; + while (CMTimeCompare(frame.duration, frameRate) > 0) { + CMTime start = CMTimeAdd(frame.timeStamp, frameRate); + CMTime duration = CMTimeSubtract(frame.duration, frameRate); + SGCodecDescriptor *cd = [[SGCodecDescriptor alloc] init]; + cd.track = frame.track; + cd.metadata = frame.codecDescriptor.metadata; + [frame setCodecDescriptor:cd]; + [frame fillWithTimeStamp:frame.timeStamp decodeTimeStamp:frame.timeStamp duration:frameRate]; + SGVideoFrame *newFrame = [SGVideoFrame frame]; + [newFrame fillWithFrame:frame]; + [newFrame fillWithTimeStamp:start decodeTimeStamp:start duration:duration]; + [ret addObject:frame]; + frame = newFrame; + } + [ret addObject:frame]; + } + return ret; } @end diff --git a/SGPlayer/Classes/Core/SGOption/SGDecoderOptions.m b/SGPlayer/Classes/Core/SGOption/SGDecoderOptions.m index 8127e14f..1fbf31ef 100644 --- a/SGPlayer/Classes/Core/SGOption/SGDecoderOptions.m +++ b/SGPlayer/Classes/Core/SGOption/SGDecoderOptions.m @@ -41,7 +41,7 @@ - (instancetype)init self->_supportedPixelFormats = [SGVideoRenderer supportedPixelFormats]; self->_supportedAudioDescriptors = @[[SGAudioRenderer supportedAudioDescriptor]]; self->_resetFrameRate = NO; - self->_preferredFrameRate = CMTimeMake(1, 25); + self->_preferredFrameRate = CMTimeMake(1, 20); } return self; }