Size and orientation of video in GPUImageMovie
I'm needing to detect the frame size and orientation of the frames sourced from GPUImageMovie. Currently, there seems to be no way of doing this - Am I missing something? Is there any implementation to get the texture size of a GPUImageOutput?
My initial thoughts are to change the processAsset method in GPUImageMovie from
AVAssetReaderTrackOutput *readerVideoTrackOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] outputSettings:outputSettings];
to
AVAssetTrack *videoTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
// #357
_frameSize = videoTrack.naturalSize;
_frameRate = videoTrack.nominalFrameRate;
_orientationTransform = videoTrack.preferredTransform;
AVAssetReaderTrackOutput *readerVideoTrackOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:videoTrack outputSettings:outputSettings];
But this only gets the frame rate, size and transform after the processing has started. I need at least the frame size and orientation before processing has started so I can pass this information on to GPUImageMovieWriter. As a note, I'm wanting to reduce the resolution of the output video if its dimensions are too large while still perserving the source video's aspect ratio, which is why I need the actually read the width/height of the source video.
Any thoughts if there's a better way to do this?
Did you get anywhere with this?
I'm after the same thing so that I can rotate videos recorded in Portrait mode.
I've abandoned this for now. Any thoughts on what to do?
I solved it earlier.
I got a UIImage of the first frame using MediaPlayer framework then compared the images width to the height to determine if its in Portrait mode - oddly enough some videos recorded in some apps seem to autorotate without my new code (videos from SloPro for example) whereas videos recorded in portrait in Apples own Camera app seem to need rotating...
When I'm back at my Mac I'll post the code I used and test videos recorded in more apps...
Here's my code;
MPMoviePlayerController *movie = [[MPMoviePlayerController alloc]
initWithContentURL:sampleURL];
//[movie setShouldAutoplay:YES];
UIImage *singleFrameImage = [movie thumbnailImageAtTime:0
timeOption:MPMovieTimeOptionExact];
if (singleFrameImage.size.height > singleFrameImage.size.width) {
NSLog(@"Portrait video");
I hope it helps you.