UIImagePickerコントローラまたはAVFoundationを使用する カメラ出力だけでなく、オーバーレイサブビューも記録する必要があるビデオをキャプチャまたは録画する必要があります。オーバーレイ画像をカメラプレビューに追加する例がたくさんありましたが、必要なのはオーバーレイ画像またはテキストプレビューだけでなく、最終ビデオ出力にオーバーレイを実際に記録することです。グラフィカルレイヤビデオプレビューレイヤテキストレイヤーオーバーレイテキストと画像でビデオを録画する
UIFont *font = [UIFont fontWithName:@"MarkerFelt-Thin" size:40.0];
CGSize maxSize = CGSizeMake(480, 10000.0);
CGSize labelSize = [@"Test Text" sizeWithFont:font constrainedToSize:maxSize lineBreakMode:NSLineBreakByWordWrapping];
CGRect labelFrame = CGRectMake(50.0, 10.0, labelSize.width, labelSize.height);
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
label.font = font;
label.text = @"Test Text";
label.numberOfLines = 0;
[videoPreview addSubview:label];
//でも、ボタンオーバーレイを追加を追加
videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:capSession];
videoPreviewLayer.frame = videoPreview.bounds;
videoPreviewLayer.backgroundColor = [UIColor blackColor].CGColor;
videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
videoPreview.layer.masksToBounds = YES;
[videoPreview.layer addSublayer:videoPreviewLayer];
[videoPreview.layer addSublayer:theDonut];
//を設定
CALayer *theDonut = [CALayer layer];
theDonut.bounds = CGRectMake(50,50, 150, 150);
theDonut.cornerRadius = 50/2;
theDonut.backgroundColor = [UIColor clearColor].CGColor;
theDonut.borderWidth = 50/5;
theDonut.borderColor = [UIColor orangeColor].CGColor;
//を追加
// !! !
UIButton *snap = [UIButton buttonWithType:UIButtonTypeCustom];
[snap setImage:[UIImage imageNamed:@"takePic"]
forState:UIControlStateNormal];
[snap addTarget:self
action:@selector(pickerCameraSnap:)
forControlEvents:UIControlEventTouchUpInside];
snap.frame = CGRectMake(74, 370, 178, 37);
[videoPreview addSubview:snap];
// 8) Commit session configuration
// 9) Start running capture session
// ========================================
[capSession commitConfiguration];
[capSession startRunning];
//Make sure video is not recording
[[videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:NO];
この例は、このサンプルコードから変更された - それは、ビデオのプレビューにテキストや描画を追加していますが、最終的な出力ファイルのものを記録しません。
http://ioscoreframeworks.com/assets/code/DemoCapture.zip
これを行う方法を説明するWWDCビデオがあり、関連するソースコードがあります。プレゼンテーションの名前を今思い出すことはできませんが(AVFoundation ...)、簡単に見つけることができます。 –
@skinnyTOD:実際にはAVFoundationに関するWWDCビデオをたくさん見てきましたが、この特定の必要性のためにシンプルで正確なコードを見つけることができず、したがってStackOverFlowのヘルプを取ることができませんでした。 とにかく私はまだWWDCのビデオをサーフィンしています。 –
ビデオにウォーターマークを追加するコードが見つかりました AVSimpleEditorは、簡単なビデオ編集作業にどのように使用できるのかを実証するシンプルなAVFoundationベースのムービー編集アプリケーションです。また、再生(AVPlayerItem)およびエクスポート(AVAssetExportSession)とのやりとりの仕方も示しています。アプリケーションはトリミング、回転、トリミング、音楽の追加、透かしの追加、およびエクスポートを実行します。このサンプルはARC対応です。 http://developer.apple.com/library/ios/#samplecode/AVSimpleEditoriOS/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012797-Intro-DontLinkElementID_2 –