GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Size and orientation of video in GPUImageMovie

Open TomCorwine opened this issue 14 years ago • 5 comments

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?

TomCorwine avatar Aug 06 '12 19:08 TomCorwine

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?

TomCorwine avatar Aug 06 '12 20:08 TomCorwine

Did you get anywhere with this?

I'm after the same thing so that I can rotate videos recorded in Portrait mode.

dansinclair25 avatar Oct 16 '12 14:10 dansinclair25

I've abandoned this for now. Any thoughts on what to do?

TomCorwine avatar Oct 16 '12 17:10 TomCorwine

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...

dansinclair25 avatar Oct 16 '12 20:10 dansinclair25

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.

dansinclair25 avatar Oct 17 '12 07:10 dansinclair25