Невозможно конвертировать в mp4 в iOS 13 - PullRequest
2 голосов
/ 16 октября 2019

На устройстве под управлением iOS 13 [exportSession exportAsynchronouslyWithCompletionHandler: всегда происходит сбой с сообщением «Операция не может быть завершена» при преобразовании видео .MOV в mp4. Тем не менее, тот же код работает на iOS до 13, т. Е. 12. Я вставляю ниже моего полного метода

- (void)encodeVideo:(NSString *)videoURL
{
   // Create the asset url with the video file
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:videoURL] options:nil];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];

    // Check if video is supported for conversion or not
    if ([compatiblePresets containsObject: AVAssetExportPresetLowQuality])
    {
    //Create Export session
         AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetLowQuality];

    //Creating temp path to save the converted video
         NSString* documentsDirectory=     [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
         NSString* myDocumentPath= [documentsDirectory stringByAppendingPathComponent:@"temp.mp4"];
         NSURL *url = [[NSURL alloc] initFileURLWithPath:myDocumentPath];

    //Check if the file already exists then remove the previous file
         if ([[NSFileManager defaultManager]fileExistsAtPath:myDocumentPath])
         {
              [[NSFileManager defaultManager]removeItemAtPath:myDocumentPath error:nil];
         }
         exportSession.outputURL = url;
         //set the output file format if you want to make it in other file format (ex .3gp)
         exportSession.outputFileType = AVFileTypeMPEG4;
         exportSession.shouldOptimizeForNetworkUse = YES;

         [exportSession exportAsynchronouslyWithCompletionHandler:^{
         switch ([exportSession status])
         {
              case AVAssetExportSessionStatusFailed:
                   NSLog(@"Export session failed");
                   break;
              case AVAssetExportSessionStatusCancelled:
                   NSLog(@"Export canceled");
                   break;
              case AVAssetExportSessionStatusCompleted:
              {
                   //Video conversion finished
                   NSLog(@"Successful!");
              }
                   break;
              default:
                   break;
          }
         }];
    }
    else
    {
           NSLog(@"Video file not supported!");
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...