Comments (5)
It's potentially possible, but complicated! There's a delegate method which you can implement, but then you're entirely responsible for writing the video/live stream/openGL etc.
However, I'm not sure AVPlayer will give you access to the video data, so it might not be possible in your current use case?
// If your view contains an AVCaptureVideoPreviewLayer or an openGL view
// you'll need to write that data into the CGContextRef yourself.
// In the viewcontroller responsible for the AVCaptureVideoPreviewLayer / openGL view
// set yourself as the delegate for ASScreenRecorder.
// [ASScreenRecorder sharedInstance].delegate = self
// Then implement 'writeBackgroundFrameInContext:(CGContextRef*)contextRef'
// use 'CGContextDrawImage' to draw your view into the provided CGContextRef
@protocol ASScreenRecorderDelegate <NSObject>
- (void)writeBackgroundFrameInContext:(CGContextRef*)contextRef;
@end
from asscreenrecorder.
I can use an AVAssetReader, which should give me the bitmap data from the same video the AVPlayer is displaying at least. Time syncing might be a little difficult. Will the recorder use this method for an AVPlayerLayer automatically? How does it know to fall back to this delegate method?
from asscreenrecorder.
In your view controller you need to set yourself as the delegate [ASScreenRecorder sharedInstance].delegate = self;
. The delegate method will be called every time a new frame is required for the video. You only need to write the video data (your UI will be rendered on top automatically).
The extra complication is that you need to be ready with the data, otherwise the frame rate will plummet.
Here is the implementation I use to record a AVCaptureVideoPreviewLayer
in my app.
- (void)writeBackgroundFrameInContext:(CGContextRef*)contextRef;
{
dispatch_sync(_imageQueue, ^{
if (_capturedImage) { // this a CGImageRef
CGContextSaveGState(*contextRef);
CGAffineTransform flipRotate = CGAffineTransformMake(0.0, 1.0, 1.0, 0.0, 0.0, 0.0);
CGContextConcatCTM(*contextRef, flipRotate);
CGContextDrawImage(*contextRef, CGRectMake(0,0, CGRectGetHeight(_cameraView.bounds), CGRectGetWidth(_cameraView.bounds)), _capturedImage);
CGContextRestoreGState(*contextRef);
_needsNewImage = YES;
}
});
}
I create the CGImageRef when my AVCaptureVideoDataOutputSampleBufferDelegate
gets called:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
dispatch_sync(_imageQueue, ^{
if (_needsNewImage) { // only create image if needed
CGImageRelease(_capturedImage);
_capturedImage = [self createCGImageFromSampleBuffer:sampleBuffer];
_needsNewImage = NO;
}
});
}
It's a bit of a palaver as you need to keep track of additional state to get everything to work. Here are the extra properties/ivars I'm using to tie everything together.
@property (strong, nonatomic) dispatch_queue_t imageQueue;
// the iVars below must be mutated using the serial dispatch_queue above
CGImageRef _capturedImage;
BOOL _needsNewImage;
With any luck, that'll give you some idea of what's involved. It's not pretty :(
from asscreenrecorder.
@domhofmann Were you able to figure out how to record AVPlayer content?
from asscreenrecorder.
I've managed to record the preview layer by rendering each frame into a CALayer
. endel/react-native-camera@e739b50
from asscreenrecorder.
Related Issues (20)
- How to record particular view only ? HOT 1
- UIAlertview not visible HOT 2
- Urgent Help: Black video on iOS9? HOT 1
- how to add Audio ? HOT 1
- Warning: Unable to write buffer to video HOT 1
- Not working properly HOT 1
- Appstore? HOT 1
- [FPS] How change FPS of the video to 60/1? HOT 4
- In background Mode HOT 1
- Recored only Subview HOT 1
- After once record,Twice will be crash. HOT 1
- How to Capture AVCaptureVideoPreviewLayer? (camera.previewlayer) HOT 4
- Carsh on my iPhone HOT 1
- cpu very high HOT 4
- record half size resolution for retina iPads????
- unable to capture the camera preview layer HOT 8
- Unable to record youtube full screen video
- Unable to build on Swift 5
- FPS HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asscreenrecorder.