SCRecorder
SCRecorder copied to clipboard
SCPlayer sometimes just show black screen, but the sound works fine.
After I use [self.player setItemByUrl:[NSURL fileURLWithPath:videoPath]]; to setItem, and make self.player.shouldSuppressPlayerRendering = NO;, black screen are getting less, but still happens sometime.
+1 experiencing this sometimes as well, I'll take a look over the next few days.
I have been looking into this for two days, can't figure out why...
I moved it into viewWillAppear: as sample, but still happens.
Here's an easy fix for this, just nuke the filters. This obsession with photo and video filters for everything is pretty dumb if you ask me, so here's the nuke em' solution:
in SCVideoPlayerViewController.m
change the the ENTIRE viewDidLoad method to this:
- (void)viewDidLoad {
[super viewDidLoad];
self.exportView.clipsToBounds = YES;
self.exportView.layer.cornerRadius = 20;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveToCameraRoll)];
_player = [SCPlayer player];
SCVideoPlayerView *playerView = [[SCVideoPlayerView alloc] initWithPlayer:_player];
playerView.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
playerView.frame = self.filterSwitcherView.frame;
playerView.autoresizingMask = self.filterSwitcherView.autoresizingMask;
[self.filterSwitcherView.superview insertSubview:playerView aboveSubview:self.filterSwitcherView];
[self.filterSwitcherView removeFromSuperview];
_player.loopEnabled = YES;
}
Then, you won't have that silly blackscreen anymore. This is tested on iphone 6s+ with 128 GB of memory running the latest IOS 9.1
EDIT
One more quick fix, hold up, I gutted too much, this does do away with the blackscreen but I accidently killed the editing button, one sec
... Okay, it works now, just nuke the viewdidload like I show above and it's fixed, I'd also disable the loopenabled and just jump right to the editing screen.
@jimmykrinkles Yes, kill filter do fix blackscreen. But i do need filter, it seems something wrong with SCFilterSwitcherView.
When I got a blackscreen, layoutSubviews in SCFilterSwitcherView only print twice.
When filter works fine, layoutSubviews in SCFilterSwitcherView print thrice.
I fixed it by calling unsetupDisplayLink followed by setupDisplayLink whenever I set a new item to play
@CristianoCastroNabia
I tried reset CIImageRenderer, should works same as your way, but still got blackscreen.
self.player.CIImageRenderer = nil;
self.player.CIImageRenderer = self.containerView.filterSwitcherView;
You should also just shut off Metal rendering since the author of this library doesn't know a damn thing about rendering with Metal. Turning off metal should fix a lot. When I say turn it off, just gut everything that is Metal related. The way the textures are set up with Metal is wrong, even though many people are having the same Metal errors that this library has. There's a right way to do this and this library doesn't employ the textures correctly, not even close to correctly, so disabling this part will help you out, or you can just redevelop the Metal rendering the correct way. Either way, you'll notice that the first check on the device compatibility check is to check if the device can handle Metal, if it can, then Metal is chosen, so turning this off helps since the Metal in this library isn't even close to correct.
The Metal part shouldn't be used by default anyway. Is it true I know little to nothing about it (just quickly went through for iOS 9), I just followed one example that Apple gave (which doesn't seem to work on iOS 9.1). You are very welcome to help me out with that since you are such an expert.
Regarding the black screen issue: Are you reusing the player? When that happens, can you tell me the status of the following:
- is the displayLink being set? what's the value of its "paused" property? Is willRenderFrame: being called?
You should also update the library since it appears you are using an older version (CIImageRenderer has been replaced by SCImageView for instance).
@rFlex Thanks for your library.
I use 2.5.3 because I need to support iOS 7.x.
I did nothing with displayLink, I only do setItemByAsset:,
I did call [self.player pause] before setItem, and do play after setItem.
I have checked willRenderFrame is being called.
@albertgh 你黑屏解决了吗,我也遇到了,和player有关系,普通的avplayer就没问题。。
Any update on this? @albertgh Were you able to fix an issue somehow?
@ren6 Sorry I still can't figure out, I just disable the filters for now.
@omergul123 any clue on how to fix this?
@albertgh I was facing the same issue, the thing is SCPlayer setItemWithURL seems not to work properly. I've tested in the example project and the black screen problem appears. I'm using setItemByAsset instead and it works perfectly. Hope it helps
@sherm4n90 are you using it with the filters and it's working fine for you? And is there any limitations taking that out?
@moofaces Yes, Im using the SCSwipeableFiltersView and it works great. No limitations, you just need to change your code to supply an SCRecordSession.assetRepresentingSegments to the SCPlayer and it should work.
@sherm4n90 This doesn't make sense because setItemWithURL: calls setItemByAsset: I think the problem still appears for you or you have fixed it another way.
@ren6 You are right, what I mean is the problem should be at setting an usual asset and not an asset from a SCRecordSession created with - (AVAsset *)assetRepresentingSegments. I tried any possible solution and no success when using AVasset or url asset by myself. After figure out the problem I tried by creating a SCSessionRecord, add a SCRecordSessionSegment with my URL and then use SCRecordSession.assetRepresentingSegments and it also works fine(if you can't use the SCRecorder or just don't want this may be your solution) . Hope it helps.
@sherm4n90, are you saying we shouldn't see the issue if we are using a SCSessionRecord.assetRepresentingSegments for the player? I'm attempting this but only seeing a black screen, though my issue might be different from others as I also have no audio.
Edit: If I add the filter to my recorder instead of the preview after done recording, I get audio with a black screen.
@ayurkows Yes, that is what I mean. As I said before I've tried with an URL asset in the provided example and the black screen appears. For the audio only issue check the SCRecorder delegate responses, it has some methods that may result useful.
@rFlex I was finally able to see the black screen hooked to the debugger. the most interesting thing I found was: (pretend these are CMTime comparisons) recordedSession.duration.seconds > 0 but player.playableDuration.seconds == 0
so it seems like player.setItemByAsset(recordedSession.assetRepresentingSegments()) is somewhere along the line creating a bad asset item. (mine is called in will appear)
recordedSession.assetRepresentingSegments() worked in the debugger but it barfed on AVPlayerItem(asset:recordedSession.assetRepresentingSegments())
Interestingly I have a button on screen that brings up a modal. Dismissing that fires will appear again and my recordedSession plays fine no more black screen.
Anyone ever figure this out?
I'm experiencing the same thing but it is very hard to reproduce. It seems to happen more often on the iPhone 6 Plus. It happens to me about 10% of the time, but I've had other iPhone 6 Plus users report it happening as much as 30% of the time.
I got this issue whenever I'm recording and have a comming call
@levantAJ That's a predictable issue and expected because it has to do with the shared audio session of your device. What I described, and what others have described above, is a much trickier issue that should not be happening.
I think it may have something to do with setting the videoConfiguration's filter property before/while recording, but I'm honestly not sure and that's just a random guess.
Edit: I saw fewer black screens, but this did not solve the issue when the app moved to QA.
I've had some success so far with the following method:
- Before adding
SCSwipeableFilterViewto a player'sSCImageView, I setshouldSuppressPlayerRenderingto false. - Later in the lifecycle (but before the view appears, I chose
viewWillAppear), I setshouldSuppressPlayerRenderingto true.
This seemed to be a workaround for me, and seemed to consistently work in development. Will update on this issue during QA and testing. I'll take a deeper dive soon.
@alihen This sounds interesting! I ended up just removing the filters altogether because analytics showed that users preferred our basic image filters, but I'd still love to find a fix for this issue.
Please keep us updated and let us know if that truly fixes it.
After doing some digging, I found that the issue is independent of using AVAsset or a URL (both are used as an AVAsset).
What I have found is that this is most likely caused by a race condition relating to the rendering of SCSwipeableFilterView. A workaround was to suppress the player rendering, and then enable player rendering once the view had appeared. In order to do this, I used a simple timer (This is quite hacky, but has shown better results - 100% in dev), but you're welcome to use other methods.
func setupVideo(){
...
self.view.alpha = 0 // Set to alpha to 0 to prevent flashing of screen
self.player.shouldSuppressPlayerRendering = false
... // Set up player as you would.
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
NSTimer.scheduledTimerWithTimeInterval(0.3, target: self, selector: #selector(ViewController.enableFilterRendering), userInfo: nil, repeats: false)
// I set the timer to 0.3 seconds, leaving enough time for the offending method to complete.
}
func enableFilterRendering() {
if !self.player.shouldSuppressPlayerRendering{
self.player.shouldSuppressPlayerRendering = true
UIView.animateWithDuration(0.1, animations: {
self.view.alpha = 1
})
}
}
Really want to get to be bottom of this issue when I have some free time, but for now this will have to do. Hope this helps @rFlex and others.
I may have fixed the issue yesterday. Could you please try again with the latest version? It's not on cocoapods yet though.
@rFlex, tested master with a basic sample and still seeing the issue, although maybe a bit less frequently.
Any fix for this? Unfortunately we're using this pod specifically for CIFilters with videos. Seeing black image about 60-70% of the time on iPhone 6.