3

私のアプリケーションには、ビデオを録画する機能があり、録画したビデオに時間と日付の詳細を追加したいと考えています。

アプリ内で実行中に簡単に追加できますが、やりたいことは、そのビデオを写真アプリでエクスポートするか、そのビデオをメールで送信する場合、日付と時刻もそこにあるはずです。

Apple からこのサンプル コードを確認しましたが、このテキストでは静的であり、常に同じままである可​​能性があります。

AVSimpleEditor

誰でも私またはリンクを案内できますか? ビデオにタイムスタンプの詳細を追加する方法..

助けてくれてありがとう。

4

2 に答える 2

2

Brad Larson によるGPUImage クラスを使用できます。要件に応じて、画像とビデオにフィルターを追加できます。最近、私のプロジェクトの 1 つで、あなたが求めていたものとまったく同じものを実装しました。

私がしたことは、UILabel を as として使用しGPUImageUIElement、それを に追加することでしたGPUImageNormalBlendFilter。コールバックごとにラベル テキストを更新したところ、魅力的に機能しました。

コードは次のとおりです。

filterView = [[GPUImageView alloc] initWithFrame:self.videoRecordView.frame];
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack];

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1920,1080)];

[self.view addSubview:filterView];
movieWriter.encodingLiveVideo = YES;
movieWriter.encodingLiveVideo = YES;
videoCamera.audioEncodingTarget = movieWriter;


GPUImageNormalBlendFilter *blendFilter1 = [[GPUImageNormalBlendFilter alloc] init];


UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 635, 768.0f, 50.0f)];

timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:fontSize];
timeLabel.textAlignment = NSTextAlignmentCenter;
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor whiteColor];

uiElementInput = [[GPUImageUIElement alloc] initWithView:timeLabel];
[uiElementInput addTarget:blendFilter1];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"MMMM dd, yyyy  hh : mm : ss a"];


[blendFilter1 addTarget:filterView];
[blendFilter1 addTarget:movieWriter];
[videoCamera addTarget:blendFilter1];


__unsafe_unretained GPUImageUIElement *weakUIElementInput = uiElementInput;
    [filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){
       
    timeLabel.textColor =[UIColor whiteColor];
    
    float sizefont =[[[NSUserDefaults standardUserDefaults]objectForKey:KfontSize] floatValue];
    timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(sizefont)? sizefont:30];
    NSDate * originalDate = [NSDate dateWithTimeIntervalSinceNow:interval];

    NSString *timeString=[dateFormatter stringFromDate:originalDate];
    timeLabel.text = [NSString stringWithFormat:@"%@", timeString];
    [weakUIElementInput update];
}];

私は質問が古いことを知っていますが、これを見つけるのに時間がかかったので誰かを助けるかもしれません.

于 2014-09-15T10:57:21.043 に答える
1

リンクしたサンプルは、方法の 90% を取得する方法を示しています。最後のステップは、AVVideoCompositionCoreAnimationToolのドキュメントを確認することです。このクラスを使用すると、コア アニメーションをビデオに追加できます。これを行う方法は、アニメーションをCALayerに追加することです。

CATextLayer を使用すると、文字列プロパティをアニメーション化できます。

于 2013-02-15T12:37:43.477 に答える