Skip to content

Commit

Permalink
SGVideoDecoder: Reset frame rate.
Browse files Browse the repository at this point in the history
  • Loading branch information
libobjc committed Nov 28, 2019
1 parent 15e6ad1 commit b20dac5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion SGPlayer/Classes/Core/SGDecoder/SGVideoDecoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion SGPlayer/Classes/Core/SGOption/SGDecoderOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b20dac5

Please sign in to comment.