2 Replies
      Latest reply on Aug 7, 2019 1:47 AM by TianYing
      TianYing Level 1 Level 1 (0 points)

        - My app implement transitions animation between two video with AVFoundation's AVVideoComposition.

          In iOS13 after export to local file,it has no  transitions animation in video.

             - I used AVMutableVideoComposition build transform in video layer.

             - playerItem.videoComposition: play playerItem has transitions animation

             - but used AVAssetExportSession.videoComposition export to loacl file, has NO any effect In iOS 13.

         

         

        My sample code for verify the question:

         

         

         

         

        - (void)testTransformPlayerImage {

            NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"111" ofType:@"MP4"];

            AVAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:moviePath]];

            AVAssetTrack *origAssetTrack = [asset tracksWithMediaType:AVMediaTypeVideo].firstObject;

          

            AVMutableComposition *composition = [AVMutableComposition composition];

            composition.naturalSize = CGSizeMake(KVideoPixelsWidth, kVideoPixelsHeight);

          

            AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];

            videoComposition.frameDuration = CMTimeMake(1, 30);

            videoComposition.renderSize = CGSizeMake(KVideoPixelsWidth, kVideoPixelsHeight);;

          

            //////////////////////////

          

            AVMutableVideoCompositionInstruction *transformInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];

            transformInstruction.timeRange = origAssetTrack.timeRange;

          

            AVMutableVideoCompositionLayerInstruction *transformLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:origAssetTrack];

          

            CGAffineTransform startTransform = CGAffineTransformIdentity;

            CGAffineTransform endTransform = CGAffineTransformIdentity;

            endTransform = CGAffineTransformTranslate(endTransform, 0, 500);

            [transformLayerInstruction setTransformRampFromStartTransform:startTransform toEndTransform:endTransform timeRange:origAssetTrack.timeRange];

          

            transformInstruction.layerInstructions = [NSArray arrayWithObject:transformLayerInstruction];

            videoComposition.instructions = @[transformInstruction];

          

            /* has effect

            AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];

            playerItem.videoComposition = videoComposition;

          

            combineResultTestViewController *vc = [[combineResultTestViewController alloc] initWithPlayerItem:playerItem];

            [self.navigationController pushViewController:vc animated:YES];

             */

          

            //export no effect

            NSString *outputPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"828.mp4"];

            AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset1280x720];

            exportSession.outputURL = [NSURL fileURLWithPath:outputPath];

            exportSession.outputFileType = AVFileTypeQuickTimeMovie;

            exportSession.videoComposition = videoComposition;

            [exportSession exportAsynchronouslyWithCompletionHandler:^{

                dispatch_async(dispatch_get_main_queue(), ^{

                    AVAsset *outputAsset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:outputPath]];

                    combineResultTestViewController *vc = [[combineResultTestViewController alloc] initWithAsset:outputAsset];

                    [self.navigationController pushViewController:vc animated:YES];

                });

            }];

        }

         

         

        What did I do wrong?

        • Re: AVAssetExportSession.videoComposition has no transform animation effect in local video file.
          TianYing Level 1 Level 1 (0 points)

          Today I continue check the question. find zhat only call

           

          [transformLayerInstruction setTransform:startTransform atTime:kCMTimeZero];

           

          after export also has no transform effect.

           

          More simple code.

           

          - (void)testTransformEffectExport {

              NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"111" ofType:@"MP4"];

              AVAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:moviePath]];

              AVAssetTrack *origAssetTrack = [asset tracksWithMediaType:AVMediaTypeVideo].firstObject;

           

              AVMutableComposition *composition = [AVMutableComposition composition];

              composition.naturalSize = CGSizeMake(KVideoPixelsWidth, kVideoPixelsHeight);

           

              AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];

              videoComposition.frameDuration = CMTimeMake(1, 30);

              videoComposition.renderSize = CGSizeMake(KVideoPixelsWidth, kVideoPixelsHeight);;

           

              //////////////////////////

           

              AVMutableVideoCompositionInstruction *transformInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];

              transformInstruction.timeRange = origAssetTrack.timeRange;

           

              AVMutableVideoCompositionLayerInstruction *transformLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:origAssetTrack];

           

              CGAffineTransform startTransform = CGAffineTransformIdentity;

              startTransform = CGAffineTransformTranslate(startTransform, 100, 200);

              [transformLayerInstruction setTransform:startTransform atTime:kCMTimeZero];

           

              transformInstruction.layerInstructions = [NSArray arrayWithObject:transformLayerInstruction];

              videoComposition.instructions = @[transformInstruction];

           

              NSString *outputPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"828.mp4"];

              AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPreset1280x720];

              exportSession.outputURL = [NSURL fileURLWithPath:outputPath];

              exportSession.outputFileType = AVFileTypeQuickTimeMovie;

              exportSession.videoComposition = videoComposition;

              [exportSession exportAsynchronouslyWithCompletionHandler:^{

                  dispatch_async(dispatch_get_main_queue(), ^{

                      AVAsset *outputAsset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:outputPath]];

                      combineResultTestViewController *vc = [[combineResultTestViewController alloc] initWithAsset:outputAsset];

                      [self.navigationController pushViewController:vc animated:YES];

                  });

              }];

            

          }