Note that there are some explanatory texts on larger screens.

plurals
  1. POadd wobble icon to a video
    primarykey
    data
    text
    <p>Could someone help me to merge an icon to a video which should wobble as the video play. I have added the animation to wobble icon but only a static icon gets merge to the video . I will really appreciate if someone could help me.</p> <p>I am giving you the code which I an using</p> <pre><code>//- (void)exportDidFinish:(AVAssetExportSession*)session{ NSLog(@"baseView subviews : %@", [baseView subviews]); UIGraphicsBeginImageContext(baseView.bounds.size); [baseView.layer renderInContext:UIGraphicsGetCurrentContext()]; //[self wobbleVideo:baseView]; UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); aLayer = [CALayer layer]; aLayer.frame = CGRectMake(0, 0, 320, 380); aLayer.bounds = CGRectMake(0, 0, 320, 380); aLayer.contents = (id) resultImage.CGImage; aLayer.opacity = 1; aLayer.backgroundColor = [UIColor clearColor].CGColor; aLayer.geometryFlipped = YES; [aLayer addAnimation:[self getShakeAnimation] forKey:@"transform"]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:rotatedVideoUrl options:nil]; cmp = [AVMutableComposition composition]; AVMutableCompositionTrack *videoComposition = [cmp addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; AVMutableCompositionTrack *audioComposition = [cmp addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid]; AVAssetTrack *sourceVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0]; AVAssetTrack *sourceAudioTrack = [[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0]; [videoComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, [asset duration]) ofTrack:sourceVideoTrack atTime:kCMTimeZero error:nil] ; [audioComposition insertTimeRange:CMTimeRangeMake(kCMTimeZero, [asset duration]) ofTrack:sourceAudioTrack atTime:kCMTimeZero error:nil] ; animComp = [AVMutableVideoComposition videoComposition]; animComp.renderSize = CGSizeMake(320, 360); animComp.frameDuration = CMTimeMake(1,30); CALayer *parentLayer = [CALayer layer]; CALayer *videoLayer = [CALayer layer]; parentLayer.frame = CGRectMake(0, 0, 320, 360); videoLayer.frame = CGRectMake(0, 0, 320, 360); [parentLayer addSublayer:videoLayer]; [parentLayer addSublayer:aLayer]; animComp.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; // to gather the audio part of the video NSArray *tracksToDuck = [cmp tracksWithMediaType:AVMediaTypeAudio]; NSMutableArray *trackMixArray = [NSMutableArray array]; for (NSInteger i = 0; i &lt; [tracksToDuck count]; i++) { AVMutableAudioMixInputParameters *trackMix = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:[tracksToDuck objectAtIndex:i]]; [trackMix setVolume:10 atTime:kCMTimeZero]; [trackMixArray addObject:trackMix]; } audioMix = [AVMutableAudioMix audioMix]; audioMix.inputParameters = trackMixArray; AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; instruction.timeRange = CMTimeRangeMake(kCMTimeZero, [asset duration]); AVMutableVideoCompositionLayerInstruction *layerVideoInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoComposition]; [layerVideoInstruction setOpacity:1.0 atTime:kCMTimeZero]; instruction.layerInstructions = [NSArray arrayWithObject:layerVideoInstruction] ; animComp.instructions = [NSArray arrayWithObject:instruction]; [self exportMovie:self]; } //WOBBLE ANIMATION------------------------------------- - (CAKeyframeAnimation*)getShakeAnimation { CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"]; CGFloat wobbleAngle = 0.06f; NSValue* valLeft = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(wobbleAngle, 0.0f, 0.0f, 1.0f)]; NSValue* valRight = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-wobbleAngle, 0.0f, 0.0f, 1.0f)]; animation.values = [NSArray arrayWithObjects:valLeft, valRight, nil]; animation.autoreverses = YES; animation.duration = 0.125; animation.repeatCount = HUGE_VALF; return animation; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload