それは私の最初の質問なので、間違いや明確な説明がなくて申し訳ありません。ビデオをループでキャプチャし、バックグラウンドでサーバーに送信するアプリを開発しています。別ファイル(リクエスト後)のように送信し、サーバー側で1つに接続したい。
私は AVframework の使用経験があまりありません。したがって、ベースとして - AVCam プロジェクトを使用し、それを私の機能に合わせて変更します。私は今、そのような問題を解決する必要があります。それぞれ 2 MB 近くの短いビデオ ファイルを記録し、次にそれらをサーバーにアップロードする方法を探しています。私が持っている主な問題 - 連結後のビデオ パーツ間の遅延。そして、レコーダーを停止せずにこのビデオパーツを取得する方法。
いくつかのことを試しています。まず、タイマー レコードの 20 秒のフラグメントを使用し、タイマーで停止し、新しいレコード サイクルを開始します。2番。私の考えは、AVURLAsset(現在の録画ビデオファイルを一時ディレクトリに取得するため)を使用し、AVAssetExportSessionによって最後に保存されていないビデオデータをその期間まで取得することでした。動作しているように見えます。いくつかのビデオを録画できますが、各ビデオの最後の 1 ~ 2 秒間でフリーズが発生します。連結した後は、1 つの映画のようには見えません。
-(void) startRecording
{
self.videoCounter=0;
self.videoTimer=[NSTimer scheduledTimerWithTimeInterval:lenghtTimer target:self selector:@selector(endRecoringVideo) userInfo:nil repeats:YES] ;
NSLog(@"timer started");
}
if ([[UIDevice currentDevice] isMultitaskingSupported]) {
[self setBackgroundRecordingID:[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{}]];
}
[self removeFile:[[self recorder] outputFileURL]];
[[self recorder] startRecordingWithOrientation:orientation];
}
-(void)saveVideoPart
{
NSUInteger count = 0;
NSString *filePath = nil;
do {
NSString *fileName = [NSString stringWithFormat:@"buf-%@-%u", AVAssetExportPresetLowQuality, count];
filePath = NSTemporaryDirectory();
filePath = [filePath stringByAppendingPathComponent:fileName];
filePath = [filePath stringByAppendingPathExtension:@"mov"];
count++;
} while ([[NSFileManager defaultManager] fileExistsAtPath:filePath]);
NSURL *outputURL = [NSURL fileURLWithPath:filePath];
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:[self tempFileURL] options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = outputURL;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
Float64 durationSeconds = CMTimeGetSeconds([videoAsset duration]);
CMTime start;
CMTime duration;
start = CMTimeMakeWithSeconds(self.videoCounter, 1);
duration = CMTimeMakeWithSeconds(durationSeconds-self.videoCounter, 1);
self.videoCounter+=durationSeconds-self.videoCounter;
NSLog(@"duration video %f,recorded %f",durationSeconds,self.videoCounter);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
NSLog(@"Exported");
break;
case AVAssetExportSessionStatusFailed:
//
NSLog(@"Failed:%@",exportSession.error);
break;
case AVAssetExportSessionStatusCancelled:
//
NSLog(@"Canceled:%@",exportSession.error);
break;
default:
break;
}
}];
}
ですから、アルゴリズムの提案をしたり、さらに進むべき正しい方向を示してくれたりすると、とてもうれしいです。私にとってのメイン - 録画中にビデオをパーツに分割します。例のビデオは一時停止なしで 10 分近くの長さになる場合があるため、バックグラウンドで 2 MB の長さの部分をいくつか作成してからアップロードする必要があります。