2016-03-25 33 views
1

Video düzenleme üzerinde çalışıyorum ve şu işleri başarıyla yaptım: Birden çok videoya 1.merge. 2.Videonun hızını ayarlayın. 3. Video klibi.Dokunarak videoda bindirme iOS

SORUN 1: başarıyla video.But şekli üzerinde bindirme kısmı yani ekleyerek görüntüyü yapmış

Şimdi video üzerinde bir resim gösteren ve daha sonra iki sorun olduğunu video.I üzerinde bu görüntüyü taşımak gerekir Bu görüntüyü taşımam mı gerekiyor?

SORUN 2: Ayrıca, videonun önizlemesini bir resmin üzerine görüntüleyemiyorum. Bu videoyu yalnızca kaydedip kaydetmediğimi kontrol edebilirim. Bazı yollarda ve sonra bu yolu kullanarak oynatırım. . Ben net yerde aradık

composition_ = [[AVMutableComposition alloc]init]; 
AVMutableCompositionTrack *compositionTrack = [composition_ addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; 

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

[compositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, self.asset.duration) ofTrack:assetTrack atTime:kCMTimeZero error:nil]; 

AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; 
videoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, self.asset.duration); 

AVMutableVideoCompositionLayerInstruction *videoCompositionLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionTrack]; 

videoCompositionInstruction.layerInstructions = @[videoCompositionLayerInstruction]; 

[videoCompositionLayerInstruction setTransform:assetTrack.preferredTransform atTime:kCMTimeZero]; 

[videoCompositionLayerInstruction setOpacity:0.0 atTime:self.asset.duration]; 
CGSize naturalSize = CGSizeMake(assetTrack.naturalSize.height, assetTrack.naturalSize.width); 


videoComposition_ = [AVMutableVideoComposition videoComposition]; 
videoComposition_.renderSize = CGSizeMake(naturalSize.width, naturalSize.height); 
videoComposition_.instructions = @[videoCompositionInstruction]; 
videoComposition_.frameDuration = CMTimeMake(1, 30); 

//start image code from here 

CALayer *overlayLayer = [CALayer layer]; 
overlayLayer.contents = (__bridge id _Nullable)([[UIImage imageNamed:@"overlay_icon.png"]CGImage]); 
overlayLayer.frame = CGRectMake(naturalSize.width/2 , naturalSize.height/2, naturalSize.width/8, naturalSize.height/8); 
overlayLayer.opacity = 0.5; 
[overlayLayer setMasksToBounds:YES]; 
overlayLayer.backgroundColor = [[UIColor redColor]CGColor]; 

CALayer *parentLayer = [CALayer layer]; 
CALayer *videoLayer = [CALayer layer]; 
parentLayer.frame = CGRectMake(0 , 0, naturalSize.width, naturalSize.height); 
videoLayer.frame = CGRectMake(0 , 0, naturalSize.width, naturalSize.height); 
videoLayer.backgroundColor = [[UIColor redColor]CGColor]; 
[parentLayer addSublayer:videoLayer]; 
[parentLayer addSublayer:overlayLayer]; 

videoComposition_.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; 

cevap

0

ama solution.Even "Video Düzenleme" hakkında elma dokümanlar bulmak için görünmüyor: Aşağıda

Ben bindirme görevi başarmak için kullandık koddur bundan bahsetme.

1.I bir video yakalama ve üzerinde bir görüntü ile bir sonraki sayfaya geçer: Kendi logic.Here yapacağım ne ile

Sonunda geldi. 2. Videonun herhangi bir yerine taşımak için resme hareket ekleyin. 3. Sonra, bu görüntüyü video üzerinde birleştirmek için yukarıdaki kodu ekleyin.

Bu mükemmel bir çözümdür. Kodu yazdığımda 2 gün içinde yayınlayacağım. Fakat mantık oldukça düz ileri.

+0

. lütfen örnek kodunuzu verebilir misiniz? @Reckoner –

+0

Tabii ki yarın size – Reckoner

+0

kodunu vereceğim teşekkürler dostum .... bunu bekliyorum :) @Reckoner –

0
-(void)prepareOverlayVideo{ 

composition_ = [[AVMutableComposition alloc]init];//correct 

AVMutableCompositionTrack *compositionTrack = [composition_ addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];//correct 

[compositionTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, self.asset.duration) ofTrack: 
[[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
          atTime:kCMTimeZero error:nil];//correct 

assetTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo]firstObject];//correct 

AVMutableVideoCompositionInstruction *videoCompositionInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];//correct 

videoCompositionInstruction.timeRange = CMTimeRangeMake(kCMTimeZero,self.asset.duration);//correct 

AVMutableVideoCompositionLayerInstruction *videoCompositionLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:assetTrack];//correct 

UIImageOrientation videoAssetOrientation_ = UIImageOrientationUp;//correct 
BOOL isVideoAssetPortrait_ = NO; 
CGAffineTransform videoTransform = assetTrack.preferredTransform; 
if (videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && 
    videoTransform.d == 0) { 

    videoAssetOrientation_ = UIImageOrientationRight; 
    isVideoAssetPortrait_ = YES; 
} 
if (videoTransform.a == 0 && videoTransform.b == -1.0 && videoTransform.c == 1.0 && videoTransform.d == 0) { 

    videoAssetOrientation_ = UIImageOrientationLeft; 
    isVideoAssetPortrait_ = YES; 
} 
if (videoTransform.a == 1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == 1.0) { 

    videoAssetOrientation_ = UIImageOrientationUp; 
} 
if (videoTransform.a == -1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == -1.0) { 

    videoAssetOrientation_ = UIImageOrientationDown; 
} 

    //[videoCompositionLayerInstruction setOpacityRampFromStartOpacity:1.f toEndOpacity:0.5f timeRange:CMTimeRangeMake(kCMTimeZero, assetTrack.timeRange.duration)]; 

// CGFloat FirstAssetScaleToFitRatio = 320.0/assetTrack.naturalSize.height; 
// CGAffineTransform FirstAssetScaleFactor = CGAffineTransformMakeScale(FirstAssetScaleToFitRatio,FirstAssetScaleToFitRatio); 
// [videoCompositionLayerInstruction setTransform:CGAffineTransformConcat(assetTrack.preferredTransform, FirstAssetScaleFactor) atTime:kCMTimeZero]; 

[videoCompositionLayerInstruction setTransform:assetTrack.preferredTransform atTime:kCMTimeZero]; 
[videoCompositionLayerInstruction setOpacity:0.0 atTime:self.asset.duration]; 

videoCompositionInstruction.layerInstructions = [NSArray arrayWithObjects:videoCompositionLayerInstruction,nil];//correct 

    if(isVideoAssetPortrait_){ 
    naturalSize = CGSizeMake(assetTrack.naturalSize.height, assetTrack.naturalSize.width); 
    } 
    else { 
    naturalSize = assetTrack.naturalSize; 
    } 

videoComposition_ = [AVMutableVideoComposition videoComposition]; 
videoComposition_.renderSize = CGSizeMake(naturalSize.width, naturalSize.height); 

videoComposition_.instructions = @[videoCompositionInstruction]; 
videoComposition_.frameDuration = CMTimeMake(1, 30); 
} 

AnimationTool Bölüm

 CGRect newRect = [self.view convertRect:overlayView.frame toView:videoRectView]; 
    CGFloat current_x = newRect.origin.x; 
    CGFloat current_y; 
    if(isSizeChanged && overlayView.frame.size.width>60) 
     current_y = newRect.origin.y+50; 
    else 
     current_y = newRect.origin.y; 
    overlayView.frame = newRect; 
    imageView_.frame = newRect; 

    CGPoint overlayPoint = [self mapSize:assetTrack.naturalSize withSize:playerLayer.videoRect.size forPoint:CGPointMake(current_x, current_y)]; 

    //invert Y-axis 
    CGFloat finalOverlayPoint_y = CGRectGetMaxY(CGRectMake(0, 0, naturalSize.width, naturalSize.height)) - overlayPoint.y-50; 
    CGPoint newOverlayPoint = CGPointMake(overlayPoint.x, finalOverlayPoint_y); 

    overlayView.layer.frame = CGRectMake(overlayPoint.x, newOverlayPoint.y,finalOverlayRect.size.width, finalOverlayRect.size.height); 
    imageView_.layer.frame = CGRectMake(overlayPoint.x, newOverlayPoint.y,finalOverlayRect.size.width, finalOverlayRect.size.height); 

    if(isShapeACircle) 
     imageView_.layer.cornerRadius = finalOverlayRect.size.height/2; 
    else 
     imageView_.layer.cornerRadius = 0.f; 
    imageView_.layer.borderWidth = 5.f; 

    overlayView.layer.contentsScale = [UIScreen mainScreen].scale; 
    [overlayView.layer setMasksToBounds:YES]; 

    //add animation 
    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"opacity"]; 
    [animation1 setDuration:0.5 ]; 
    [animation1 setFromValue:[NSNumber numberWithFloat:1.0]]; 
    [animation1 setToValue:[NSNumber numberWithFloat:1.0]]; 
    //[animation1 setBeginTime:[self.timeLabel.text floatValue]]; 
    [animation1 setBeginTime:_overlayTime]; 
    [animation1 setRemovedOnCompletion:YES]; 
    [animation1 setFillMode:kCAFillModeForwards]; 
    [imageView_.layer addAnimation:animation1 forKey:@"animateOpacity"]; 

    imageView_.layer.opacity = 0.0; 
    CALayer *parentLayer = [CALayer layer]; 
    CALayer *videoLayer = [CALayer layer]; 

    parentLayer.frame = CGRectMake(0 , 0, naturalSize.width, naturalSize.height); 
    parentLayer.backgroundColor = [[UIColor redColor]CGColor]; 
    videoLayer.frame = CGRectMake(0 , 0, naturalSize.width, naturalSize.height); 

    //CALayer *watermarkLayer = [self setWaterMarkInLayer:videoLayer]; 

    [parentLayer addSublayer:videoLayer]; 
    [parentLayer addSublayer:imageView_.layer]; 
    //[parentLayer addSublayer:watermarkLayer]; 



    videoComposition_.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; 

// bu yöntemi Not ..... Bu Bu overlay.I biliyoruz kodudur pigeon_39 @ başarı parçası

-(CGPoint)mapSize:(CGSize)assetTrack_size withSize:(CGSize)videoLayer_size forPoint:(CGPoint)overlay_point{ 

NSLog(@"%f",playerLayer.videoRect.size.width); 
NSLog(@"%f",playerLayer.videoRect.size.height); 
NSLog(@"%f",playerLayer.videoRect.origin.x); 
NSLog(@"%f",playerLayer.videoRect.origin.y); 


CGFloat assetTrack_width = assetTrack_size.width; 
CGFloat assetTrack_height = assetTrack_size.height; 

CGFloat videoLayer_width = videoLayer_size.width; 
CGFloat videoLayer_height = videoLayer_size.height; 

CGFloat ratio_width = assetTrack_width/videoLayer_width; 
CGFloat ratio_height = assetTrack_height/videoLayer_height; 

CGFloat new_width = overlay_point.x * ratio_width; 
CGFloat new_height = overlay_point.y * ratio_height; 

finalOverlayRect = CGRectMake(0, 0,overlayView.frame.size.width * ratio_width , overlayView.frame.size.height * ratio_height) ; 

CGPoint overlayPoint = CGPointMake(new_width, new_height); 
return overlayPoint; 
} 

olduğunu biraz geç oldu, ama bir süreliğine ara verdim ve bu sorunun ne olduğunu hatırlamamıştım. Şimdi size yardımcı oluyorsa, bu cevaba başvurabilirsiniz. Herhangi bir sorunla karşılaşırsanız, sohbete devam edebiliriz. Eğer burada sıkışmış olsun ama benim ilk biraz araştırma yapmak burada.Ask bana gerçek kodu sağlamak için bir çok düzenleme yapmak zorunda olacak gibi tam bir kod olmadığını unutmayın.Mod kodu bir sürü içerir Koşullar.All en iyi arkadaşı :-) aslında aynı sorunla karşı karşıyayım :-)

İlgili konular