Skip to content

Commit 5b1ba46

Browse files
committed
Merge pull request wess#9 from PGMY/pgmy
fixed wess#4 and wess#7
2 parents 85bd6ac + 4c9ad5b commit 5b1ba46

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

Glimpse/Glimpse/Glimpse.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ - (void)startRecordingView:(UIView *)view onCompletion:(GlimpseCompletedCallback
4444
{
4545
self.sourceView = view;
4646
self.callback = block;
47+
self.writer.size = view.bounds.size;
4748

4849
self.writer.startDate = [NSDate date];
4950

@@ -74,10 +75,13 @@ - (void)stop
7475

7576
- (UIImage *)imageFromView:(UIView *)view
7677
{
77-
UIGraphicsBeginImageContext(view.bounds.size);
78-
79-
[[view.layer presentationLayer] renderInContext:UIGraphicsGetCurrentContext()];
80-
78+
UIGraphicsBeginImageContextWithOptions(view.frame.size , YES , 0 );
79+
80+
if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)]) {
81+
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES];
82+
} else {
83+
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
84+
}
8185
UIImage *rasterizedView = UIGraphicsGetImageFromCurrentImageContext();
8286
UIGraphicsEndImageContext();
8387

Glimpse/Glimpse/GlimpseAssetWriter.m

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ @interface GlimpseAssetWriter()
1313
{
1414
CFAbsoluteTime _timeOfFirstFrame;
1515
CFTimeInterval _timestamp;
16-
uint64_t _frameRate;
16+
int32_t _frameRate;
1717
uint64_t _frameCount;
1818
dispatch_queue_t _queue;
1919

@@ -40,26 +40,26 @@ - (id)init
4040
if (self)
4141
{
4242
self.size = [[UIScreen mainScreen] bounds].size;
43-
self.framesPerSecond = 1;
43+
self.framesPerSecond = 24;
4444
self.frameBuffer = [[NSMutableArray alloc] init];
4545

46-
_frameRate = (uint64_t)self.framesPerSecond;
46+
_frameRate = (int32_t)self.framesPerSecond;
4747
_queue = dispatch_queue_create([GlimpseAssetWriterQueueName cStringUsingEncoding:NSUTF8StringEncoding], 0);
4848
}
4949
return self;
5050
}
5151

52-
- (NSURL *)fileOutputURL
52+
- (NSURL *)createFileOutputURL
5353
{
5454
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
5555
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
5656
NSString *filename = [NSString stringWithFormat:@"glimpse_%08x.mov", (int)timestamp];
5757
NSString *path = [NSString stringWithFormat:@"%@/%@", documentDirectory, filename];
5858
NSFileManager *fileManager = [NSFileManager defaultManager];
59-
59+
6060
if([fileManager fileExistsAtPath:path])
6161
[fileManager removeItemAtPath:path error:nil];
62-
62+
6363
NSLog(@"OUTPUT: %@", path);
6464
return [NSURL fileURLWithPath:path];
6565
}
@@ -69,6 +69,8 @@ - (AVAssetWriter *)writer
6969
if(_writer)
7070
return _writer;
7171

72+
_fileOutputURL = [self createFileOutputURL];
73+
7274
NSError *error = nil;
7375
_writer = [[AVAssetWriter alloc] initWithURL:self.fileOutputURL fileType:AVFileTypeQuickTimeMovie error:&error];
7476
NSAssert(error == nil, error.debugDescription);
@@ -154,10 +156,7 @@ - (void)writeVideoFromImageFrames:(void(^)(NSURL *outputPath))callback
154156
if(self.input.readyForMoreMediaData)
155157
{
156158
i++;
157-
158-
CFAbsoluteTime current = CFAbsoluteTimeGetCurrent();
159-
CFTimeInterval elapse = current - _timeOfFirstFrame;
160-
CMTime present = CMTimeMake(elapse * 600, 600);
159+
CMTime present = CMTimeMake(i , _frameRate);
161160

162161
buffer = [self pixelBufferForImage:image];
163162
BOOL result = [self.adapter appendPixelBuffer:buffer withPresentationTime:present];

0 commit comments

Comments
 (0)