Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6720383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:12:20+00:00 2026-05-26T09:12:20+00:00

I am writing an iPhone app which takes video from the camera, runs it

  • 0

I am writing an iPhone app which takes video from the camera, runs it through some OpenGL shader code and then writes the output to a video file using AVFoundation. The app runs in lanscape orientation (either) and therefore all video recorded should be landscape.

The current code I use before starting recording to get the video the right way round is:

[[self videoWriterInput] setTransform:CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI), -1.0, 1.0)];

where videoWriterInput is an instance of AVAssetWriterInput and the aim is to compensate for the landscape mode and the reveresed orientation of OpenGL.

This produces video which when downloaded and played on Quicktime player plays correctly. However, if I add the recorded video to the iPhone photo library, the thumbnail displays correctly but the video plays rotated 90 degrees if the phone is held in landscape. If the phone is held in portrait the video plays correctly but is cropped horizontally to fit the portrait dimensions.

According to this Apple tech note the capture output for AVCaptureVideoDataOutput, which I use for processing the video frames, does not support setting the video orientation.

Has anyone successfully recorded landscape generated video which can be added to the iPhone library and plays correctly in landscape and if so how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:12:20+00:00Added an answer on May 26, 2026 at 9:12 am

    Your post opened my eyes about how Apples Videos app plays back video. I recorded several items with my app with the device in the four orientations. They all played back properly oriented. I just noticed that the Videos app doesn’t support rotation like the player in the Photos Album app. The Videos app expects you to hold the device (at least my iPod touch) in landscape. I did some portrait recordings, added them to iTunes, and all, including the one created with Apple’s camera app, did not rotate when rotating the device to portrait orientation.

    Anyway…

    My app is a time lapse app that does not do any extra processing on the frames like you are doing, so YMMV on the following. I have my app set up so that it does not rotate the window as the device is rotated. This way I’m always dealing with one orientation of the device. I use AVFoundation to grab every Nth frame from the video stream and write that out.

    As I set up for recording, I do the following.

    inputWriterBuffer = [AVAssetWriterInput assetWriterInputWithMediaType: AVMediaTypeVideo outputSettings: outputSettings];
        // I call this explicitly before recording starts. Video plays back the right way up.
    [self detectOrientation];
    inputWriterBuffer.transform = playbackTransform;
    

    That detectOrientation calls the following method. I’ve reduced the actual code for clarity here. In my app I also rotate some buttons, so notice they do not get the same transformation. The thing to pay attention to is how I’m setting up the playbackTransform ivar.

    -(void) detectOrientation {
    CGAffineTransform buttonTransform;
    
    switch ([[UIDevice currentDevice] orientation]) {
        case UIDeviceOrientationUnknown:
            NULL;
        case UIDeviceOrientationFaceUp:
            NULL;
        case UIDeviceOrientationFaceDown:
            NULL;
            break;
        case UIDeviceOrientationPortrait:
            [UIButton beginAnimations: @"myButtonTwist" context: nil];
            [UIButton setAnimationDuration: 0.25];
            buttonTransform = CGAffineTransformMakeRotation( ( 0 * M_PI ) / 180 );
            recordingStarStop.transform = buttonTransform;
            [UIButton commitAnimations];            
    
            playbackTransform = CGAffineTransformMakeRotation( ( 90 * M_PI ) / 180 );
            break;
        case UIDeviceOrientationLandscapeLeft:
            [UIButton beginAnimations: @"myButtonTwist" context: nil];
            [UIButton setAnimationDuration: 0.25];
            buttonTransform = CGAffineTransformMakeRotation( ( 90 * M_PI ) / 180 );
            recordingStarStop.transform = buttonTransform;
            [UIButton commitAnimations];            
    
            // Transform depends on which camera is supplying video
            if (theProject.backCamera == YES) playbackTransform = CGAffineTransformMakeRotation( 0 / 180 );
            else playbackTransform = CGAffineTransformMakeRotation( ( -180 * M_PI ) / 180 );
    
            break;
        case UIDeviceOrientationLandscapeRight:
            [UIButton beginAnimations: @"myButtonTwist" context: nil];
            [UIButton setAnimationDuration: 0.25];
            buttonTransform = CGAffineTransformMakeRotation( ( -90 * M_PI ) / 180 );
            recordingStarStop.transform = buttonTransform;
            [UIButton commitAnimations];
    
            // Transform depends on which camera is supplying video
            if (theProject.backCamera == YES) playbackTransform = CGAffineTransformMakeRotation( ( -180 * M_PI ) / 180 );
            else playbackTransform = CGAffineTransformMakeRotation( 0 / 180 );
    
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            [UIButton beginAnimations: @"myButtonTwist" context: nil];
            [UIButton setAnimationDuration: 0.25];
            buttonTransform = CGAffineTransformMakeRotation( ( 180 * M_PI ) / 180 );
            recordingStarStop.transform = buttonTransform;
            [UIButton commitAnimations];
    
            playbackTransform = CGAffineTransformMakeRotation( ( -90 * M_PI ) / 180 );
            break;
        default:
            playbackTransform = CGAffineTransformMakeRotation( 0 / 180 ); // Use the default, although there are likely other issues if we get here.
            break;
    }
    }
    

    As a side note, since I want the method called when ever the device is rotated, and I’ve turned off automatic rotation, I have the following in my viewDidLoad method.

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    

    That’s a tip I found in this SOF Q&A.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iPhone app which downloads a tar-gzipped file from a Webserver, then
I am writing an iPhone app which gets data from a mysql database. I
Im writing an iPhone app which retrieves data from a web service as XML.
I'm writing an iPhone app which fetches an XML file, parses it and then
I’m writing a new iPhone app which doesn’t depend on any of the 3.0
I'm writing a simple iPhone app which lets a user access a series of
I'm writing an iPhone app with a UIWebView which should display various html files
I am writing an iPhone app – a client for some social network. The
I'm writing my first iphone app and through several examples I've got a UITableView
I'm writing an iPhone app. Starting from a view controller in a navigation stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.