Permalink
Browse files

Fix Video Timestamp Inconsistence - which video stops too early

  • Loading branch information...
tuo committed Jan 20, 2015
1 parent 4a3be64 commit e99878196e85820be86296a53f1c40ada4a40b5f
Showing with 8 additions and 2 deletions.
  1. +3 −0 framework/Source/GPUImageMovie.h
  2. +5 −2 framework/Source/GPUImageMovie.m
@@ -43,6 +43,9 @@
@property (readonly, nonatomic) BOOL audioEncodingIsFinished;
@property (readonly, nonatomic) BOOL videoEncodingIsFinished;
@property (nonatomic) BOOL pauseVideoRead;
@property(nonatomic, copy) void (^onProcessMovieFrameDone)(GPUImageMovie *, CMTime);
/// @name Initialization and teardown
- (id)initWithAsset:(AVAsset *)asset;
- (id)initWithPlayerItem:(AVPlayerItem *)playerItem;
@@ -372,16 +372,16 @@ - (void)displayLinkCallback:(CADisplayLink *)sender
- (BOOL)readNextVideoFrameFromOutput:(AVAssetReaderOutput *)readerVideoTrackOutput;
{
if (reader.status == AVAssetReaderStatusReading && ! videoEncodingIsFinished)
if (reader.status == AVAssetReaderStatusReading && ! videoEncodingIsFinished && !self.pauseVideoRead)
{
CMSampleBufferRef sampleBufferRef = [readerVideoTrackOutput copyNextSampleBuffer];
if (sampleBufferRef)
{
//NSLog(@"read a video frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, CMSampleBufferGetOutputPresentationTimeStamp(sampleBufferRef))));
CMTime currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(sampleBufferRef);
if (_playAtActualSpeed)
{
// Do this outside of the video processing queue to not slow that down while waiting
CMTime currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(sampleBufferRef);
CMTime differenceFromLastFrame = CMTimeSubtract(currentSampleTime, previousFrameTime);
CFAbsoluteTime currentActualTime = CFAbsoluteTimeGetCurrent();
@@ -402,6 +402,9 @@ - (BOOL)readNextVideoFrameFromOutput:(AVAssetReaderOutput *)readerVideoTrackOutp
[weakSelf processMovieFrame:sampleBufferRef];
CMSampleBufferInvalidate(sampleBufferRef);
CFRelease(sampleBufferRef);
if(weakSelf.onProcessMovieFrameDone){
weakSelf.onProcessMovieFrameDone(weakSelf, currentSampleTime);
}
});
return YES;

1 comment on commit e998781

@tuo

This comment has been minimized.

Show comment
Hide comment
@tuo
Owner

tuo commented on e998781 Jan 20, 2015

Please sign in to comment.