GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Output orientation

Open stevemckenzie opened this issue 14 years ago • 11 comments

I see the changes you made over the weekend to GPUImageMovieWriter and startRecordingInOrientation.

I'm a bit confused why before the update, I was always getting my video files created in the right orientation but now I'm not?

Also with a quick test of applying my own transform using the new method, I'm noticing my video is stretched.

Can you provide some info on how to best handle this and as well, flipping the frames if using the front facing camera?

stevemckenzie avatar Aug 08 '12 17:08 stevemckenzie

You're going to have to ask Tom why he changed the way orientation was handled. I didn't even catch that part of the code when I merged in his other changes.

BradLarson avatar Aug 08 '12 17:08 BradLarson

Sorry if my changes caused any problems. Perhaps I should not set any kind of orientationTransform at all if the startRecording method is called, rather than setting it to a transform of zero.

I need to add the startRecordingInOrientation: method because I was having problems with video not being in the proper orientation, as GPUImage had no idea what orientation the device was in while recording. I thought about just checking the device orientation within GPUImageMovieWriter, but then non-live video (video sourced with GPUImageMovie) would be erroneously oriented based on how the user was holding the device.

As far as the movie being stretch, I'm not seeing that on my end.

TomCorwine avatar Aug 08 '12 19:08 TomCorwine

I'll dig more into the stretching issue.

As for the orientation handling, I think it would be better if you could just provide a UIInterfaceOrientation or AVCaptureVideoOrientation value vs a transform value. Have GPUImageMovieWriter handle the transform for you.

What do you think?

startRecording could even just take the [[UIDevice currentDevice] orientation] and handle it that way by default but startRecordingWithOrientation could allow you to specify it still.

I think it would also be nice if GPUImageView / GPUImageMovieWriter had a property that you could set to automatically handle flipping for the front facing camera but that's another issue :)

stevemckenzie avatar Aug 08 '12 19:08 stevemckenzie

My intention was to not change the functionality of startRecording, since people may already be relying on its curent behavior. I made a fix to insure its functionality stays the same which I will open a pull request for.

I implemented the startRecordingInOrientation method using a CGAffineTransform because that's what AVAssetWriterInput accepts as an input, and the mapping of a device orientation to a transform is dependent on what sort of rotation is being applied to the image. Rather than get into all that, I'm simply exposing a property that already exists in AVAssetWriterInput.

As a side note, the one big problem with just reading the [UIDevice currentDevice].orientation is it only works if the user doesn't have their orientation locked.

TomCorwine avatar Aug 08 '12 20:08 TomCorwine

Ah. thanks for pointing that out.

Does your app support all orientations? I was wondering if I could see your implementation of setting the transform.

stevemckenzie avatar Aug 08 '12 20:08 stevemckenzie

I'm simply doing this:

#define degreesToRadian(x)  (M_PI * (x) / 180.0)
...
    CGAffineTransform orientationTransform = CGAffineTransformIdentity;

    switch (orientation)
    {
        default:
        case UIImageOrientationUp:
            orientationTransform = CGAffineTransformMakeRotation(degreesToRadian(0));
            break;

        case UIImageOrientationDown:
            orientationTransform = CGAffineTransformMakeRotation(degreesToRadian(180));
            break;

        case UIImageOrientationLeft:
            orientationTransform = CGAffineTransformMakeRotation(degreesToRadian(-90));
            break;

        case UIImageOrientationRight:
            orientationTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
            break;
    }

Where UIImageOrientation is determined by the device's orientation and orientationTransform is what I pass in to startRecordingInOrientation:.

TomCorwine avatar Aug 08 '12 20:08 TomCorwine

hmm so ya, that's basically the same as what I had. cool and thanks for showing me.

will have to continue digging into the stretching of the frames.

stevemckenzie avatar Aug 08 '12 20:08 stevemckenzie

Can you confirm for me that the commit in my pull request fixes any problems you had with startRecording?

TomCorwine avatar Aug 08 '12 21:08 TomCorwine

I must have mixed something up with what I experienced befor on this one but everything seems fine with your latest change.

stevemckenzie avatar Aug 08 '12 21:08 stevemckenzie

Okay, thanks!

TomCorwine avatar Aug 08 '12 21:08 TomCorwine

I'm closing this issue.

Also Tom, I sent you an email to your tomisiphoneapps address.

Thanks for looking into this.

stevemckenzie avatar Aug 08 '12 23:08 stevemckenzie