用透明背景播放视频IOS

问题描述:

我想用透明背景播放视频。唯一的问题是,我在互联网上找到的所有信息都是“如何让视频背景变得透明”,但是我的视频背景已经是透明的了,现在我需要让播放器的背景透明。我怎么做?我试过这个:用透明背景播放视频IOS

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"New Project 5" ofType:@"m4v"]; 
NSLog(@"%@",resourcePath); 
NSURL *url = [NSURL fileURLWithPath:resourcePath]; 
NSLog(@"%@",url); 

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

moviePlayer.shouldAutoplay=YES; 
moviePlayer.controlStyle = MPMovieControlStyleNone; 
[moviePlayer setFullscreen:NO animated:YES]; 
[self.view addSubview:moviePlayer.view]; 

moviePlayer.view.frame = CGRectMake(200, 600, 400, 300); 

[moviePlayer play]; 

moviePlayer.view.backgroundColor = [UIColor clearColor]; 
for(UIView *aSubView in moviePlayer.view.subviews) { 
    aSubView.backgroundColor = [UIColor clearColor]; 
} 

但它不起作用。它显示黑色背景。

+0

'UIView'具有'opaque'属性,默认情况下由于性能原因呈现透明为黑色。这与旧iPhone相关,默认值为YES。尝试将它设置为NO的电影播放器​​(也可能是子视图以及) – FeifanZ 2013-05-08 18:28:06

+0

- [1] [1] [iPhone SDK如何发挥与透明度的视频?]:HTTP://计算器。 com/questions/1401517/iphone-sdk-how-to-play-a-video-with-transparency – Masa 2013-05-08 18:35:03

+0

@Masa告诉我如何让背景变得透明,而不是如何让视频播放器透明 – Alessandro 2013-05-08 19:00:54

这是一个真正解决这个问题的链接playing-movies-with-an-alpha-channel-on-the-ipad。她的博客文章正在讨论iPad上的视频,但支持Alpha频道的同一个库也适用于iPhone。使用博客文章评论中描述的方法,也可以使用alpha通道支持编码为h.264。

+0

MoDJ的图书馆需要一个商业广告许可证,相当涉及额外的步骤,并没有那么好的性能(提取7z,额外的视频轨道等) 这是一个使用免费开源库的解决方案,完全在GPU上工作(即使对于大视频也有很好的性能),并要求只有两件事: - 透明图像(PNG或代码) - 代替透明,绿色背景的视频 http://*.com/questions/33244347/video-with-gpuimagechromakeyfilter-hastint-when-played -in-transparent-gpuimagev/33255662 – 2015-10-21 09:35:10

+0

逐点比较可显示绿色屏幕与alpha通道比较的实际结果。 http://www.modejong.com/blog/post18_green_screen/ – MoDJ 2015-12-02 23:32:07