Closed TheSquad closed 11 years ago
Ok I have fixed it... on your code if you wish to update it, here it is...
(AVMutableVideoComposition )buildDefaultVideoComposition { AVMutableVideoComposition videoComposition = [AVMutableVideoComposition videoComposition]; AVAssetTrack *videoTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
// get the frame rate from videoSettings, if not set then try to get it from the video track, // if not set (mainly when asset is AVComposition) then use the default frame rate of 30 float trackFrameRate = 0; if (self.videoSettings) { NSDictionary videoCompressionProperties = [self.videoSettings objectForKey:AVVideoCompressionPropertiesKey]; if (videoCompressionProperties) { NSNumber maxKeyFrameInterval = [videoCompressionProperties objectForKey:AVVideoMaxKeyFrameIntervalKey]; if (maxKeyFrameInterval) { trackFrameRate = maxKeyFrameInterval.floatValue; } } } else { trackFrameRate = [videoTrack nominalFrameRate]; }
if (trackFrameRate == 0) { trackFrameRate = 30; }
videoComposition.frameDuration = CMTimeMake(1, trackFrameRate); videoComposition.renderSize = [videoTrack naturalSize];
// Make a "pass through video track" video composition. AVMutableVideoCompositionInstruction *passThroughInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction]; passThroughInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, self.asset.duration);
AVMutableVideoCompositionLayerInstruction *passThroughLayer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:videoTrack];
CGAffineTransform videoTransform = videoTrack.preferredTransform;
BOOL isVideoAssetPortrait = NO; UIImageOrientation videoAssetOrientation = UIImageOrientationUp;
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;}
CGFloat FirstAssetScaleToFitRatio = videoTrack.naturalSize.height / videoTrack.naturalSize.width;
if(isVideoAssetPortrait_) { CGFloat SecondAssetScaleToFitRatio = videoTrack.naturalSize.width/videoTrack.naturalSize.height; CGAffineTransform FirstAssetScaleFactor = CGAffineTransformMakeScale(SecondAssetScaleToFitRatio,FirstAssetScaleToFitRatio); [passThroughLayer setTransform:CGAffineTransformConcat(videoTrack.preferredTransform, FirstAssetScaleFactor) atTime:kCMTimeZero]; }else{ [passThroughLayer setTransform:videoTrack.preferredTransform atTime:kCMTimeZero]; }
passThroughInstruction.layerInstructions = @[passThroughLayer]; videoComposition.instructions = @[passThroughInstruction];
return videoComposition; }
Pull request?
Sorry I have no idea how to do that... I'm not a big github user
I also have this issue and had to copy @TheSquad 's code. I can try submitting a pull request it if I get a chance
Hi, First of all thank you for your work, it is a great drop-in replacement !
Compressing Landscape video works great, fast, and painless... However Portrait video does not seems to be as painless ;-)
I'm having issue with result video being strechted, but more than a thousand words here the original and result screens...
Original
Result
Has you can see, is it streched down on the width, and streched up on the height... I cannot seems to find out why...
My code using your class is :
Is there something wrong with my code ?