• <bdo id='VgCTf'></bdo><ul id='VgCTf'></ul>
  • <legend id='VgCTf'><style id='VgCTf'><dir id='VgCTf'><q id='VgCTf'></q></dir></style></legend>
  • <tfoot id='VgCTf'></tfoot>
    <i id='VgCTf'><tr id='VgCTf'><dt id='VgCTf'><q id='VgCTf'><span id='VgCTf'><b id='VgCTf'><form id='VgCTf'><ins id='VgCTf'></ins><ul id='VgCTf'></ul><sub id='VgCTf'></sub></form><legend id='VgCTf'></legend><bdo id='VgCTf'><pre id='VgCTf'><center id='VgCTf'></center></pre></bdo></b><th id='VgCTf'></th></span></q></dt></tr></i><div id='VgCTf'><tfoot id='VgCTf'></tfoot><dl id='VgCTf'><fieldset id='VgCTf'></fieldset></dl></div>

      <small id='VgCTf'></small><noframes id='VgCTf'>

        如何使用 iOS SDK 修剪视频文件并转换为 15 秒视频

        时间:2023-06-01
        <tfoot id='S6FQY'></tfoot>

        <small id='S6FQY'></small><noframes id='S6FQY'>

          <legend id='S6FQY'><style id='S6FQY'><dir id='S6FQY'><q id='S6FQY'></q></dir></style></legend>

            <tbody id='S6FQY'></tbody>
            • <bdo id='S6FQY'></bdo><ul id='S6FQY'></ul>

                1. <i id='S6FQY'><tr id='S6FQY'><dt id='S6FQY'><q id='S6FQY'><span id='S6FQY'><b id='S6FQY'><form id='S6FQY'><ins id='S6FQY'></ins><ul id='S6FQY'></ul><sub id='S6FQY'></sub></form><legend id='S6FQY'></legend><bdo id='S6FQY'><pre id='S6FQY'><center id='S6FQY'></center></pre></bdo></b><th id='S6FQY'></th></span></q></dt></tr></i><div id='S6FQY'><tfoot id='S6FQY'></tfoot><dl id='S6FQY'><fieldset id='S6FQY'></fieldset></dl></div>

                  本文介绍了如何使用 iOS SDK 修剪视频文件并转换为 15 秒视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想修剪视频文件.我只想从画廊中挑选视频并将其转换为 15 秒视频.如果我使用选择器视图控制器进行正常修剪,它不会指定时间而只显示帧,但我需要固定 15 秒.我怎样才能做到这一点?

                  I want to trim a video file. I want to just pick the video from a gallery and convert it to a 15-second video. If I use normal trimming with picker view controller, it does not specify a time and just shows the frames, but I need to be fixed for 15 seconds. How can I achieve this?

                  推荐答案

                  Objective-C

                  -(void)cropVideo:(NSURL*)videoToTrimURL{
                      AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoToTrimURL options:nil];
                      AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
                  
                      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                      NSString *outputURL = paths[0];
                      NSFileManager *manager = [NSFileManager defaultManager];
                      [manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
                      outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"];
                      // Remove Existing File
                      [manager removeItemAtPath:outputURL error:nil];
                  
                  
                      exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
                      exportSession.shouldOptimizeForNetworkUse = YES;
                      exportSession.outputFileType = AVFileTypeQuickTimeMovie;
                      CMTime start = CMTimeMakeWithSeconds(1.0, 600); // you will modify time range here
                      CMTime duration = CMTimeMakeWithSeconds(15.0, 600);
                      CMTimeRange range = CMTimeRangeMake(start, duration);
                      exportSession.timeRange = range;
                      [exportSession exportAsynchronouslyWithCompletionHandler:^(void)
                       {
                           switch (exportSession.status) {
                               case AVAssetExportSessionStatusCompleted:
                                   [self writeVideoToPhotoLibrary:[NSURL fileURLWithPath:outputURL]];
                                   NSLog(@"Export Complete %d %@", exportSession.status, exportSession.error);
                                   break;
                               case AVAssetExportSessionStatusFailed:
                                   NSLog(@"Failed:%@",exportSession.error);
                                   break;
                               case AVAssetExportSessionStatusCancelled:
                                   NSLog(@"Canceled:%@",exportSession.error);
                                   break;
                               default:
                                   break;
                           }
                  
                           //[exportSession release];
                       }];
                  }
                  

                  在 Swift 4.0 中

                      static func cropVideo(atURL url:URL) {
                      let asset = AVURLAsset(url: url)
                      let exportSession = AVAssetExportSession.init(asset: asset, presetName: AVAssetExportPresetHighestQuality)!
                      var outputURL = URL(string:NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last!)
                  
                      let fileManager = FileManager.default
                      do {
                          try fileManager.createDirectory(at: outputURL!, withIntermediateDirectories: true, attributes: nil)
                      } catch {
                  
                      }
                  
                      outputURL?.appendPathComponent("output.mp4")
                      // Remove existing file
                      do {
                          try fileManager.removeItem(at: outputURL!)
                      }
                      catch {
                  
                      }
                  
                      exportSession.outputURL = outputURL
                      exportSession.shouldOptimizeForNetworkUse = true
                      exportSession.outputFileType = AVFileTypeQuickTimeMovie
                      let start = CMTimeMakeWithSeconds(1.0, 600) // you will modify time range here
                      let duration = CMTimeMakeWithSeconds(15.0, 600)
                      let range = CMTimeRangeMake(start, duration)
                      exportSession.timeRange = range
                      exportSession.exportAsynchronously {
                          switch(exportSession.status) {
                          case .completed: break
                              //
                          case .failed: break
                              //
                          case .cancelled: break
                              //
                          default: break
                          }
                      }
                  }
                  

                  这篇关于如何使用 iOS SDK 修剪视频文件并转换为 15 秒视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 iOS 中捕获 Wi-Fi 网络变化事件 下一篇:iOS:访问设备硬件音量控制

                  相关文章

                  最新文章

                    <bdo id='Yyr9L'></bdo><ul id='Yyr9L'></ul>
                2. <tfoot id='Yyr9L'></tfoot>
                  <legend id='Yyr9L'><style id='Yyr9L'><dir id='Yyr9L'><q id='Yyr9L'></q></dir></style></legend>

                    <small id='Yyr9L'></small><noframes id='Yyr9L'>

                  1. <i id='Yyr9L'><tr id='Yyr9L'><dt id='Yyr9L'><q id='Yyr9L'><span id='Yyr9L'><b id='Yyr9L'><form id='Yyr9L'><ins id='Yyr9L'></ins><ul id='Yyr9L'></ul><sub id='Yyr9L'></sub></form><legend id='Yyr9L'></legend><bdo id='Yyr9L'><pre id='Yyr9L'><center id='Yyr9L'></center></pre></bdo></b><th id='Yyr9L'></th></span></q></dt></tr></i><div id='Yyr9L'><tfoot id='Yyr9L'></tfoot><dl id='Yyr9L'><fieldset id='Yyr9L'></fieldset></dl></div>