ショートビデオSDKは、デュエット録画機能を提供し、サンプルビデオとカメラでキャプチャされたビデオで構成されるデュエットを録画できます。 2つのビデオは、左右分割画面、上下分割画面、またはピクチャ・イン・ピクチャ (PiP) などの指定されたレイアウトで配置されます。 デュエットの各フレームは、2つのビデオからの画像を含み、サンプルビデオのオーディオは、デュエットのオーディオとして使用される。 デュエット録画機能は、新しいローカルビデオトラックを追加する基本録画機能のアップグレードバージョンです。
サポートされているエディション
エディション | 対応 |
Professional | 必須 |
標準 | 必須 |
基本 | 選択可能 |
用語
このセクションでは、デュエットレコーディング機能をよりよく理解するのに役立つ用語について説明します。 詳細については、「デュエット録音」、「トラック」、および「トラックレイアウト」をご参照ください。
関連クラス
クラス | 説明 |
レコーディング、プレビュー設定、エフェクト設定、コールバック設定など、デュエットレコーディング機能を定義するコアクラス。 | |
カメラによってキャプチャされたビデオを表示するために使用されるビューのサイズと位置、およびサンプルビデオを表示するために使用されるビューのサイズと位置など、デュエット録画のパラメーターを定義するクラス。 | |
ビデオの解像度など、カメラでキャプチャされたビデオの構成を定義するクラス。 | |
サンプルビデオのファイルパス、サンプルビデオの開始時刻、終了時刻など、サンプルビデオの設定を定義するクラス。 |
デュエット録音の設定
デュエット録音には、カメラとマイクの権限が必要です。 そうでなければ、記録は失敗する。
デュエット録画を設定する手順は、ビデオ録画を設定する手順と同様です。 主な違いは、設定する必要がある入出力パラメータとプレビュー設定にあります。
設定 | 手順 | 説明 | サンプルコード |
基本設定 | 1 | 録画インスタンスを作成し、録画パラメーターを設定します。 | |
2 | コールバックを設定します。 | ||
3 | プレビューを開始するか、プレビューを停止します。 | ||
4 | 録音を開始または録音を停止します。 | ||
5 | 記録を停止し、設定情報を生成します。 | ||
詳細構成 | 6 | レタッチ、フィルター、BGMなどのレコーディングエフェクトを設定し、写真撮影などの機能を設定します。 |
デュエット録音パラメータの設定
デュエットレコーディングインスタンスの初期化パラメーターとして、デュエットレコーディングパラメーターを設定します。 コードで使用されるパラメーターの詳細については、「関連クラス」をご参照ください。
デュエット録音パラメータの設定
AliyunMixMediaInfoParam *mixMediaInfo = [[AliyunMixMediaInfoParam alloc] init];
mixMediaInfo.outputSizeView = previewView;
mixMediaInfo.mixVideoInfo.filePath = mixVideoFile; // The path of the sample video.レイアウトパラメーターの設定
サンプルビデオとカメラによってキャプチャされたビデオの座標系は、システムの座標系と同じです。 この例では、PiPレイアウトが使用されています。
// Configure the view that is used to display the sample video. The view is displayed at the bottom in full screen.
CGFloat mixWidth = previewView.bounds.size.width;
CGFloat mixHeight = previewView.bounds.size.height;
mixMediaInfo.mixVideoInfo.frame = CGRectMake(0, 0, mixWidth, mixHeight);
mixMediaInfo.mixVideoInfo.layerLevel = 1;
// Configure the view that is used to display the video captured by the camera. The view is displayed at the 9:16 aspect ratio in portrait mode. The recording resolution is 360p. The view is displayed in the lower-right corner of the window and on the top of the sample video.
CGFloat recordRatio = 9.0 / 16.0;
mixMediaInfo.recordVideoInfo.resolution = CGSizeMake(360, 360 / recordRatio);
CGFloat recordHeight = previewView.bounds.size.height * 0.5;
CGFloat recordWidth = recordHeight * recordRatio;
mixMediaInfo.recordVideoInfo.frame = CGRectMake(previewView.bounds.size.width - recordWidth - 4.0, previewView.bounds.size.height - recordHeight - 4, recordWidth, recordHeight);
mixMediaInfo.recordVideoInfo.layerLevel = 2;その他のパラメーター
// Configure the border of the sample video. This setting is optional.
mixMediaInfo.mixVideoInfo.borderInfo.color = UIColor.blueColor;
mixMediaInfo.mixVideoInfo.borderInfo.width = 2;
mixMediaInfo.mixVideoInfo.borderInfo.cornerRadius = 6.0;
// Configure the border of the video captured by the camera. This setting is optional.
mixMediaInfo.recordVideoInfo.borderInfo.color = UIColor.blueColor;
mixMediaInfo.recordVideoInfo.borderInfo.width = 1;
mixMediaInfo.recordVideoInfo.borderInfo.cornerRadius = 6.0;デュエットレコーディングオブジェクトを作成する
デュエット録音オブジェクトを作成する場合、設定する必要があるパラメーターは、基本的な録音のパラメーターと同様です。 詳細については、「基本的な記録」をご参照ください。
AliyunMixRecorder *_recorder = [[AliyunMixRecorder alloc] initWithMediaInfo:mixMediaInfo outputSize:CGSizeMake(720, 720)];
_recorder.outputType = AliyunIRecorderVideoOutputPixelFormatType420f;
_recorder.useFaceDetect = YES;
_recorder.faceDetectCount = 2;
_recorder.faceDectectSync = NO;
_recorder.frontCaptureSessionPreset = AVCaptureSessionPreset1280x720;
_recorder.GOP = 250;
_recorder.videoQuality = AliyunVideoQualityHight;
_recorder.recordFps = 30;
_recorder.outputPath = [taskPath stringByAppendingPathComponent:@"output.mp4"];
_recorder.cameraRotate = 0;
_recorder.beautifyStatus = YES;
_recorder.frontCameraSupportVideoZoomFactor = YES;
self.aliyunMixRecorder = _recorder;記録期間の設定
出力ビデオの持続時間は、最も長い持続時間を有するビデオと同じです。 たとえば、カメラによってキャプチャされたビデオの持続時間が10秒であり、サンプルビデオの持続時間が5秒である場合、デュエットの持続時間は10秒です。
// We recommend that you set the duration of the sample video as the duration of the duet. If the duration is reached, a recorderDidStopWithMaxDuration callback is triggered.
AVURLAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:[self resourcePath:mixVideoPath]]];
[self.aliyunMixRecorder setRecordMaxDuration:asset.aliyunVideoDuration];
[self.aliyunMixRecorder setRecordMinDuration:1.0];デュエットの背景を設定する
// Set the background color for the duet.
[self.aliyunMixRecorder setBackgroundColor:0xFF0100];
// Set the background image for the duet.
NSString *imgPath = [self.class resourcePath:@"pig.jpeg"];
[self.aliyunMixRecorder setBackgroundImageFilePath:imgPath imageDisplayMode:AliyunMixVideoBackgroundImageModeScaleAspectFit];出力オーディオの設定
録音エコーを削除したり、ビデオをミュートしたり、ビデオに1つのオーディオトラックまたは2つのミックスオーディオトラックを指定したりできます。
出力ビデオがミュートされている場合、またはサンプルビデオのオーディオのみが使用されている場合、エコー除去は必要ありません。
// Configure the hardware echo removal effect. We recommend that you use the Hardware mode.
self.aliyunMixRecorder.recorderAECType = AliyunIRecorderAECTypeHardware;
// Configure a duet to use the recorded audio track.
[self.aliyunMixRecorder setMixAudioSource:MixAudioSourceTypeBoth];
[self.aliyunMixRecorder setMixAudioOriginalWeight:50 recordWeight:50];コールバックの設定
コールバックを設定して、処理の進行状況、およびオーディオとビデオのステータスをタイムリーに取得できます。 コードで使用されるパラメーターの詳細については、「関連クラス」をご参照ください。
- (void)recorderDeviceAuthorization:(AliyunIRecorderDeviceAuthor)status {
dispatch_async(dispatch_get_main_queue(), ^{
if (status == AliyunIRecorderDeviceAuthorAudioDenied) {
[DeviceAuthorization openSetting:@"You are not authorized to use the microphone."];
} else if (status == AliyunIRecorderDeviceAuthorVideoDenied) {
[DeviceAuthorization openSetting:@"You are not authorized to use the camera."];
}
});
}
// The recording progress.
- (void)recorderVideoDuration:(CGFloat)duration {
NSLog(@"Mix Record Video Duration: %f", duration);
}
// Stop recording.
- (void)recorderDidStopRecording {
NSLog(@"Mix Record Stop Recording");
}
// The recording stops when the maximum recording duration is reached.
- (void)recorderDidStopWithMaxDuration {
NSLog(@"Mix Record Stop Recording With Max Duration");
[self.aliyunMixRecorder finishRecording]; // The recording is complete.
}
// The recording is complete.
- (void)recorderDidFinishRecording {
NSLog(@"Mix Record Did Finish Recording");
}
// The merge for duet recording is complete.
- (void)mixRecorderComposerDidComplete {
NSLog(@"Mix Record Complete");
[[MBProgressHUD HUDForView:self.view] hideAnimated:YES];
}
// An error occurred during the merge.
- (void)mixRecorderComposerDidError:(int)errorCode {
NSLog(@"Mix Record Error");
[[MBProgressHUD HUDForView:self.view] hideAnimated:YES];
}
// Merge starts for duet recording.
- (void)mixRecorderComposerDidStart {
NSLog(@"Mix Record Start");
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeDeterminate;
hud.removeFromSuperViewOnHide = YES;
hud.label.text = @"Merging...";
}
// The merge is complete.
- (void)mixRecorderComposerOnProgress:(CGFloat)progress {
NSLog(@"Mix Record Progress: %f", progress);
MBProgressHUD *hub = [MBProgressHUD HUDForView:self.view];
hub.progress = progress / self.aliyunMixRecorder.recordDuration;
}プレビューの設定
コードで使用されるパラメーターの詳細については、「関連クラス」をご参照ください。
// Enable the preview.
[self.aliyunMixRecorder startPreviewWithPositon:AliyunIRecorderCameraPositionFront];
// Stop the preview. Call stopPreview after the recording is complete.
[self.aliyunMixRecorder stopPreview];録音を開始
startRecordingとstopRecordingはペアで呼び出す必要があります。 それらを1回または複数回呼び出すことができ、1つ以上の一時的なビデオクリップが生成されます。 コードで使用されるパラメーターの詳細については、「関連クラス」をご参照ください。
// Start recording a video clip.
[self.aliyunMixRecorder startRecording];
// Stop recording a video clip.
[self.aliyunMixRecorder stopRecording];録音を停止する
録画が完了したら、finishRecordingを呼び出して、サンプルビデオとカメラでキャプチャされたビデオをマージできます。 コードで使用されるパラメーターの詳細については、「関連クラス」をご参照ください。
// Stop recording, and merge the sample video and the video captured by the camera.
[self.aliyunMixRecorder finishRecording];その他の設定
デュエット録音は、レタッチ、フィルター、バックグラウンドミュージックなどの効果の録音もサポートしています。 AliyunMixRecorderクラスを使用して、撮影などの録画エフェクトや機能を設定できます。 設定方法は、基本的な記録に使用される設定方法と同様です。 詳細については、「基本的な記録」をご参照ください。