У меня есть приложение, которое позволяет пользователю записывать видео с UIImagePickerController
, а затем загружать его на YouTube. Проблема в том, что видеофайл, создаваемый UIImagePickerController
, является ОГРОМНЫМ, даже если видео длится всего 5 секунд. Например, видеоролик длиной 5 секунд составляет 16-20 мегабайт. Я хочу сохранить видео в формате 540 или 720, но хочу уменьшить размер файла.
Я экспериментировал с AVFoundation и AVAssetExportSession
, чтобы попытаться получить меньший размер файла. Я пробовал следующий код:
AVAsset *video = [AVAsset assetWithURL:videoURL];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:video presetName:AVAssetExportPresetPassthrough];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.outputURL = [pathToSavedVideosDirectory URLByAppendingPathComponent:@"vid1.mp4"];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
NSLog(@"done processing video!");
}];
Но это не уменьшило размер файла вообще. Я знаю, что я делаю, потому что в приложении Apple Photos, когда вы выберите "поделиться на YouTube" , автоматически обработает видеофайл, чтобы он был достаточно мал для загрузки. Я хочу сделать то же самое в своем приложении.
Как я могу это сделать?