Closed OlyRice closed 12 years ago
I was looking at the framework and noticed "GPUImageRotationMode", do I need to use this to set the rotation?
Thanks
If you still need to rotate the video for output to a video writer, you'll need to have at least one filter in there. Right now, the GPUImageMovieWriter doesn't obey the rotation input and just writes out what is passed into it.
What you can do is use an inexpensive filter, like a GPUImageBrightnessFilter with the brightness set to the normal level of 0.0, to act as a passthrough. That filter will perform the appropriate rotation within it so that the movie writer is fed the proper rotated frames.
Hi Brad,
Thanks for the feedback, I did stumble upon that during some testing. I think I will use a filter as mentioned with a simple effect in.
One thing I have noticed is that with the following code the portrait mode works great but the landscape modes are different in the view compared to what is saved. For example, in Landcape "3" the saved video is perfect but the video that appears in the view is rotated by -90 degrees. With the new rotation system Is there a way of manually setting the rotation for the video display?
int orientation = [[UIDevice currentDevice] orientation];
NSLog(@"%d",orientation);
if( orientation == 1){
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:self.moviePath size:CGSizeMake(480, 640)];
}else if( orientation == 2 ) {
videoCamera.outputImageOrientation = UIInterfaceOrientationPortraitUpsideDown;
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:self.moviePath size:CGSizeMake(480, 640)];
}
else if( orientation == 3 ) {
//videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeRight;
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:self.moviePath size:CGSizeMake(640, 480)];
}
else {
//videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:self.moviePath size:CGSizeMake(640, 480)];
}
[videoCamera addTarget:filter];
[filter addTarget:videoWindow];
[filter addTarget:movieWriter];
Thanks for the feedback, nice software.
The camera is mounted landscape left, so if you want to display that in a portrait view, it needs to be rotated. The outputImageOrientation property lets you specify the desired orientation of the interface you'll be displaying the camera feed into. Without that set, it just passes the camera input into the filters without rotation, and the image will appear in landscape left within a portrait orientation.
What you're trying to do in that third case, if I understand correctly, is to take the camera input and record it as landscape video while displaying it within a portrait interface. One way to do that would be to have a dummy filter after the camera input that only goes to the view, not to the movie. For that filter, explicitly use -setInputRotation:atIndex: with an index of 0 and a rotation of kGPUImageRotateRight. Every filter can apply rotation as part of its actions now, so you can just do this manually if you want two different rotations as outputs.
Thanks for the feedback Brad, I think I understand what you are saying. I am going to apply the rotation to the filter and UIView using setInputRotation:atIndex.
Cheers Oliver
Hi please help me. UIInterfaceOrientationLandscapeRight my video but save and output is always Vertical.
// // CameraViewController.m // AkcarayGreenScreen // // Created by Burçin Azaklı on 02/03/15. // Copyright (c) 2015 Artechin Production. All rights reserved. //
@interface Video ()
@end
@implementation Video
(id)initWithImagePath:(NSString *)imagePath { if ((self = [super init])) {
self.imagePath = imagePath;
}
return self; }
(void)viewDidLoad { [super viewDidLoad];
//videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack]; // videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront]; // videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
GPUImagePicture *inputImage = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:self.imagePath]];
videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1920x1080 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeRight;
videoCamera.horizontallyMirrorFrontFacingCamera = NO; videoCamera.horizontallyMirrorRearFacingCamera = NO;
filter = [[GPUImageChromaKeyBlendFilter alloc] init]; [(GPUImageChromaKeyBlendFilter *)filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
// filter = [[GPUImageTiltShiftFilter alloc] init]; // [(GPUImageTiltShiftFilter )filter setTopFocusLevel:0.65]; // [(GPUImageTiltShiftFilter )filter setBottomFocusLevel:0.85]; // [(GPUImageTiltShiftFilter )filter setBlurSize:1.5]; // [(GPUImageTiltShiftFilter )filter setFocusFallOffRate:0.2];
// filter = [[GPUImageSketchFilter alloc] init]; // filter = [[GPUImageColorInvertFilter alloc] init]; // filter = [[GPUImageSmoothToonFilter alloc] init]; // GPUImageRotationFilter *rotationFilter = [[GPUImageRotationFilter alloc] initWithRotation:kGPUImageRotateRightFlipVertical];
[videoCamera addTarget:filter]; filterView = (GPUImageView *)self.view;
self.sourcePicture = inputImage; [self.sourcePicture processImage]; [self.sourcePicture addTarget:filter];
[filter addTarget:filterView];
///////// GPUImageView filterView = (GPUImageView )self.view; // filterView.fillMode = kGPUImageFillModeStretch; // filterView.fillMode = kGPUImageFillModePreserveAspectRatioAndFill;
// Record a movie for 10 s and store it in /Documents, visible via iTunes file sharing NSString prefixString = @"HisarHatirasi"; NSDate *time = [NSDate date]; NSDateFormatter df = [NSDateFormatter new]; [df setDateFormat:@"ddMMyyyyhhmmss"]; NSString timeString = [df stringFromDate:time]; timeString = [timeString stringByReplacingOccurrencesOfString:@":" withString:@""]; NSString filename = [NSString stringWithFormat:@"Documents/%@%@.m4v", prefixString, timeString];
NSString pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:filename]; unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie NSURL movieURL = [NSURL fileURLWithPath:pathToMovie]; movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1080.0, 1920.0)]; movieWriter.encodingLiveVideo = YES; // movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 480.0)]; // movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(720.0, 1280.0)]; // movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1080.0, 1920.0)]; [filter addTarget:movieWriter]; [filter addTarget:filterView];
[videoCamera startCameraCapture];
// set portrait orientation
double delayToStartRecording = 5.0;
// UIAlertView alert = [[UIAlertView alloc] initWithTitle:@"Video Başlangıç" message:@"5 saniye içinde video çekimi başlayacaktır.Videonuz kaydedildi uyarısına kadar çekime devam ediniz." // delegate:self cancelButtonTitle:@"Tamam" otherButtonTitles:nil]; //[alert show]; dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording \ NSEC_PER_SEC); dispatch_after(startTime, dispatch_get_main_queue(), ^(void){ NSLog(@"Start recording"); videoCamera.audioEncodingTarget = movieWriter; [movieWriter startRecording];
// NSError *error = nil;
// if (![videoCamera.inputCamera lockForConfiguration:&error])
// {
// NSLog(@"Error locking for configuration: %@", error);
// }
// [videoCamera.inputCamera setTorchMode:AVCaptureTorchModeOn];
// [videoCamera.inputCamera unlockForConfiguration];
double delayInSeconds = 10.0;
dispatch_time_t stopTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(stopTime, dispatch_get_main_queue(), ^(void){
[filter removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
NSLog(@"Movie completed");
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:movieURL])
{
[library writeVideoAtPathToSavedPhotosAlbum:movieURL completionBlock:^(NSURL *assetURL, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Video Saving Failed"
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Video Kaydedildi." message:@"Videonuz kaydedilmiştir."
delegate:self cancelButtonTitle:@"Tamam" otherButtonTitles:nil];
[alert show];
}
VideoPlay *resultViewController = [[VideoPlay alloc] initWithMovieURL:movieURL ];
[self.navigationController pushViewController:resultViewController animated:YES];
});
}];
}
// [videoCamera.inputCamera lockForConfiguration:nil];
// [videoCamera.inputCamera setTorchMode:AVCaptureTorchModeOff];
// [videoCamera.inputCamera unlockForConfiguration];
});
}); }
(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { // Map UIDeviceOrientation to UIInterfaceOrientation. UIInterfaceOrientation orient = UIInterfaceOrientationPortrait; switch ([[UIDevice currentDevice] orientation]) { case UIDeviceOrientationLandscapeLeft: orient = UIInterfaceOrientationLandscapeLeft; break;
case UIDeviceOrientationLandscapeRight:
orient = UIInterfaceOrientationLandscapeRight;
break;
case UIDeviceOrientationPortrait:
orient = UIInterfaceOrientationPortrait;
break;
case UIDeviceOrientationPortraitUpsideDown:
orient = UIInterfaceOrientationPortraitUpsideDown;
break;
case UIDeviceOrientationFaceUp:
case UIDeviceOrientationFaceDown:
case UIDeviceOrientationUnknown:
// When in doubt, stay the same.
orient = fromInterfaceOrientation; // sen burayı ne yaptım demiştin bana :D
break;
} videoCamera.outputImageOrientation = orient;
}
@end
Hi
I am trying to sort out the rotation, its seems that when the video file is created and then copied to the camera roll the rotation is completely out. Videos that are produced in portrait mode seem to be rotated to the right, the code below is an example of the live video recording.
@interface VideoScreen : UIViewController {
}
The following is the part of the code that is run in the .m file.
-(void)startCamera {
}
Am I missing something? I know there used to be a rotation filter but I think that was taken out.
I have a UIView the height and width of the IPhone, my goal would be to mimic the display and output of the in-built camera.
Thanks
Oliver