Comments (6)
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.
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.
You transform the video frame effectively cropping it. Just scale it up.
from xbimagefilters.
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.
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.
@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)
- Very nice project. Any chance to attach a license? HOT 3
- Live camera view is mirror-inverted HOT 2
- Failed to create framebuffer HOT 2
- Low Light boost mode HOT 9
- Camera orientation issue. HOT 5
- XBFilteredImageView set new image not working HOT 6
- Video Play in Very fast speed HOT 1
- High resolution photo filtering
- Error at CVOpenGLESTextureCacheCreateTextureFromImage: -6683
- can't even run the project HOT 3
- Example of a jpg going wrong HOT 1
- Error in compiling XBImageFilters HOT 2
- Conversion Problem of C Pointer HOT 1
- XBFilteredCameraView takeScreenshot HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xbimagefilters.