通过GPUImageMovie视频过滤器没有播放干净的视频

时间:2014-06-18 12:45:54

标签: ios video ios7 gpuimage video-editing

我在项目中添加了用于视频编辑的gpuimage框架, 但它不能播放视频干净(根据屏幕截图) 我检查了gpuimage框架中的示例,即" SimpleVideoFileFilter",  但它也有同样的问题, 音频干净,保存方便(电影编写器代码不在此处显示) 我检查了不同的视频格式,即" mp4"," mov"," m4v"但有同样的问题

我的代码在下面,

.h文件

  #import <UIKit/UIKit.h>
  #import <GPUImage.h>
  #import <AVFoundation/AVFoundation.h>

 @interface ViewController : UIViewController<GPUImageMovieDelegate>

 @end

和.m文件正在关注

#import "ViewController.h"

@interface ViewController ()
{
GPUImageMovie *movieFile;
GPUImageOutput<GPUImageInput> *filter;
GPUImageMovieWriter *movieWriter;
}
@property (nonatomic,strong) GPUImageView *gpuImageViewObj;
@property (nonatomic,strong) AVPlayer *player;
@property (nonatomic,strong) AVPlayerItem *playerItem;
@end

@implementation ViewController
@synthesize gpuImageViewObj,player,playerItem;

- (void)viewDidLoad
{
    [super viewDidLoad];

    gpuImageViewObj = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, 568, 320)];
    [self.view addSubview:gpuImageViewObj];


    [self try128];

 }

 -(void)try128{


   //AVplayer
   NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"Sample"  withExtension:@"m4v"];
playerItem = [[AVPlayerItem alloc]initWithURL:sampleURL];
player  = [[AVPlayer alloc ]initWithPlayerItem:playerItem];
[player play];


//GPUImage movie
movieFile = [[GPUImageMovie alloc] initWithPlayerItem:playerItem];
//    movieFile.runBenchmark = YES;
movieFile.playAtActualSpeed = YES;
movieFile.delegate = self;

//filter
filter = [[GPUImageFilter alloc] init];
[filter forceProcessingAtSize:gpuImageViewObj.sizeInPixels];

[movieFile addTarget:filter];
[filter  addTarget:gpuImageViewObj];


[movieFile startProcessing];


player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(didCompletePlayingMovie)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:nil];

  }


 #pragma mark - GPUImageMovieDelegate

 -(void)didCompletePlayingMovie
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:nil];

    [filter removeTarget:movieWriter];
       //    [movieFile endProcessing];  //not needed
     NSLog(@"finish............");

    }


     #pragma mark -GPUImageMovieWriterDelegate


   - (void)movieRecordingCompleted{
      NSLog(@"movieRecordingCompleted called...");

     //    [movieWriter finishRecording];

    }
  - (void)movieRecordingFailedWithError:(NSError*)error{
        NSLog(@"movieRecordingFailedWithError called...");

   }

我的o / p图像

image shown filtered video

1 个答案:

答案 0 :(得分:2)

我猜你是在尝试在模拟器中运行它,而不是在实际设备上运行。电影播放在模拟器上从未正常工作,这是一个神器。

相反,请在实际的iOS硬件上进行开发。