Giter Club home page Giter Club logo

Comments (6)

xissburg avatar xissburg commented on September 17, 2024

What are you doing exactly? Do you want to crop the video? You can do that using AVFoundation http://stackoverflow.com/questions/5198245/how-do-i-use-avfoundation-to-crop-a-video

from xbimagefilters.

NeerajBhakuni1410 avatar NeerajBhakuni1410 commented on September 17, 2024

Actually that link does not crop the video, it just shrink the video frame.
I want to crop the Video , Just like Instagram and vine application did.

from xbimagefilters.

xissburg avatar xissburg commented on September 17, 2024

You transform the video frame effectively cropping it. Just scale it up.

from xbimagefilters.

NeerajBhakuni1410 avatar NeerajBhakuni1410 commented on September 17, 2024

I am Using that code for merge all Video Clips. Can u Please Tell me What i have to do for crop the video frame from center with frame size 320 x 320.

Please Help me.
I really appreciate you.

  • (AVMutableComposition* )mergeAllVideoClip:(NSArray* )videoFilePaths orientation:(NSNumber*)orientation
    {
    AVMutableComposition
    composition = [AVMutableComposition composition];

    AVMutableCompositionTrack* videoCompositionTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];

    AVMutableCompositionTrack* audioCompositionTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

    // Make it square
    AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition];
    videoComposition.renderSize = CGSizeMake(320, 320);
    videoComposition.frameDuration = CMTimeMake(1, 30);

    AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
    instruction.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(60, 30) );

    // Merge All Track.
    NSError* error = nil;
    NSMutableArray* timeVideoRanges = [NSMutableArray arrayWithCapacity:videoFilePaths.count];
    NSMutableArray* videoTracks = [NSMutableArray arrayWithCapacity:videoFilePaths.count];

    //audio files
    NSMutableArray* timeAudioRanges = [NSMutableArray arrayWithCapacity:videoFilePaths.count];
    NSMutableArray* audioTracks = [NSMutableArray arrayWithCapacity:videoFilePaths.count];

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], AVURLAssetPreferPreciseDurationAndTimingKey, nil];

    for (NSURL* videoPathUrl in videoFilePaths)
    {
    AVURLAsset *assetClip = [AVURLAsset URLAssetWithURL:videoPathUrl options:options];

    AVAssetTrack *clipVideoTrack = [[assetClip tracksWithMediaType:AVMediaTypeVideo] lastObject];
    AVAssetTrack *audioAssetTrack = [[assetClip tracksWithMediaType:AVMediaTypeAudio] lastObject];
    
    if (clipVideoTrack == nil || audioAssetTrack == nil)
        continue;
    
    // rotate to portrait
    AVMutableVideoCompositionLayerInstruction* compositionLayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:clipVideoTrack];
    
    CGAffineTransform videoTransform = clipVideoTrack.preferredTransform;
    
    if(videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && videoTransform.d == 0)  {
        DebugLog(@"right");
    
        *orientation = [NSNumber numberWithInteger:UIImageOrientationRight];
    
        CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(M_PI_2);
        videoCompositionTrack.preferredTransform = rotationTransform;
    }
    if(videoTransform.a == 0 && videoTransform.b == -1.0 && videoTransform.c == 1.0 && videoTransform.d == 0)  {
        DebugLog(@"left");
    
        *orientation = [NSNumber numberWithInteger:UIImageOrientationLeft];
    }
    if(videoTransform.a == 1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == 1.0)   {
        DebugLog(@"up");
        *orientation = [NSNumber numberWithInteger:UIImageOrientationUp];
    }
    if(videoTransform.a == -1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == -1.0) {
        DebugLog(@"down");
        *orientation = [NSNumber numberWithInteger:UIImageOrientationDown];
    }
    
    
    instruction.layerInstructions = [NSArray arrayWithObject:compositionLayerInstruction];
    videoComposition.instructions = [NSArray arrayWithObject: instruction];
    
    // Merge Video Files
    [timeVideoRanges addObject:[NSValue valueWithCMTimeRange:CMTimeRangeMake(kCMTimeZero, assetClip.duration)]];
    [videoTracks addObject:clipVideoTrack];
    
    // Merge Audio Files
    [timeAudioRanges addObject:[NSValue valueWithCMTimeRange:CMTimeRangeMake(kCMTimeZero, assetClip.duration)]];
    [audioTracks addObject:audioAssetTrack];
    

    }

    BOOL compositionTrack = [videoCompositionTrack insertTimeRanges:timeVideoRanges ofTracks:videoTracks atTime:kCMTimeZero error:&error];
    DebugLog(@"compositionTrack :%d == error :%@",compositionTrack,error);

    BOOL audiocompositionTrack = [audioCompositionTrack insertTimeRanges:timeAudioRanges ofTracks:audioTracks atTime:kCMTimeZero error:&error];
    DebugLog(@"audiocompositionTrack :%d == error :%@",audiocompositionTrack,error);

    return composition;
    }

from xbimagefilters.

NeerajBhakuni1410 avatar NeerajBhakuni1410 commented on September 17, 2024

Can you tell me how to use CGAffineTransform for cropping the video from the center with frame size 320 x 320

CGAffineTransform finalTransform = // setup a transform that grows the video, effectively causing a crop
[transformer setTransform:finalTransform atTime:kCMTimeZero];

@xissburg Please Help.
Thanks

from xbimagefilters.

antonyjoemathew avatar antonyjoemathew commented on September 17, 2024

@NeerajBhakuni1410 Hi I am also facing the same issue.Are you able to crop the image.? if so can you please share your code
Thanks

from xbimagefilters.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.