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

  • Home
  • SEARCH
  • 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 6327389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:16:14+00:00 2026-05-24T17:16:14+00:00

I am trying to change the video frame size to square i.e 100 x

  • 0

I am trying to change the video frame size to square i.e 100 x 100. Here is the code:

- (void) changeSize :(NSURL *) url
{

//Create audio/video Settings
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                               AVVideoCodecH264, AVVideoCodecKey,
                               [NSNumber numberWithInt: 100], AVVideoWidthKey, 
                               [NSNumber numberWithInt:100], AVVideoHeightKey, 
                               nil];

NSDictionary * audioSettings = [NSDictionary dictionaryWithObjectsAndKeys: 
                               [NSNumber numberWithFloat: 44100.0], AVSampleRateKey, 
                               [NSNumber numberWithInt: 2], AVNumberOfChannelsKey, 
                               [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey, 
                               [NSData data], AVChannelLayoutKey, nil];



//Read Asset 
AVURLAsset *myAsset = [AVURLAsset URLAssetWithURL:url options:nil];

NSArray *videoTracks = [myAsset tracksWithMediaType:AVMediaTypeVideo];
AVAssetTrack *audioTrack = [[myAsset tracksWithMediaType:AVMediaTypeAudio]objectAtIndex:0];


AVAssetReader *assetReader = [[AVAssetReader alloc]initWithAsset:myAsset error:nil];

AVAssetReaderOutput *videoOutput = [AVAssetReaderVideoCompositionOutput assetReaderVideoCompositionOutputWithVideoTracks:videoTracks videoSettings:nil];

AVAssetReaderOutput *audioOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:audioTrack outputSettings:nil];

[assetReader addOutput:videoOutput];
[assetReader addOutput:audioOutput];


//Create writer and set its properties
AVAssetWriterInput* writerInputVideo = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo
                                                                           outputSettings:videoSettings] retain];

AVAssetWriterInput* writerInputAudio = [[AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio
                                                                           outputSettings:nil] retain];


NSError *error = nil;
AVAssetWriter *writer = [[AVAssetWriter alloc]initWithURL:[NSURL fileURLWithPath:fullPath] fileType:AVFileTypeQuickTimeMovie error:&error];

[writer addInput:writerInputVideo];
[writer addInput:writerInputAudio];


//start reading/writting
[writer startWriting];
[assetReader startReading];

}

Now the problem is that when it reaches [assetReader startReading], it throws and exception saying “AVAssetReaderVideoCompositionOutput.videoComposition needs to be set”.

Anybody please guide me?

TIA

  • 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-24T17:16:15+00:00Added an answer on May 24, 2026 at 5:16 pm

    I made it myself. Check it out:

    - (void) resizeVideo:(NSURL *)videoPath outputPath:(NSURL *)outputPath
    {
    
    NSURL *fullPath = outputPath;
    
    NSURL *path = videoPath;
    
    
    NSLog(@"Write Started");
    
    NSError *error = nil;
    
    AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:fullPath fileType:AVFileTypeQuickTimeMovie error:&error];    
    NSParameterAssert(videoWriter);
    
    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                   AVVideoCodecH264, AVVideoCodecKey,
                                   [NSNumber numberWithInt:100], AVVideoWidthKey,
                                   [NSNumber numberWithInt:100], AVVideoHeightKey,
                                   nil];
    
    AVAssetWriterInput* videoWriterInput = [[AVAssetWriterInput
                                             assetWriterInputWithMediaType:AVMediaTypeVideo
                                             outputSettings:videoSettings] retain];
    
    NSParameterAssert(videoWriterInput);
    NSParameterAssert([videoWriter canAddInput:videoWriterInput]);
    
    videoWriterInput.expectsMediaDataInRealTime = NO;
    
    [videoWriter addInput:videoWriterInput];
    
    
    
    
    AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:path options:nil];
    NSError *aerror = nil;
    AVAssetReader *reader = [[AVAssetReader alloc] initWithAsset:avAsset error:&aerror];
    
    
    AVAssetTrack *videoTrack = [[avAsset tracksWithMediaType:AVMediaTypeVideo]objectAtIndex:0];
    
    NSDictionary *videoOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
    
    AVAssetReaderTrackOutput *asset_reader_output = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:videoOptions];    
    
    [reader addOutput:asset_reader_output];
    
    
    [videoWriter startWriting];
    [videoWriter startSessionAtSourceTime:kCMTimeZero];
    [reader startReading];
    
    CMSampleBufferRef buffer;
    
    
    while ( [reader status]==AVAssetReaderStatusReading )
    {
        if(![videoWriterInput isReadyForMoreMediaData])
            continue;
    
        buffer = [asset_reader_output copyNextSampleBuffer];
    
    
        NSLog(@"READING");
    
        if(buffer)
            [videoWriterInput appendSampleBuffer:buffer];
    
        NSLog(@"WRITTING...");
    
    
    }
    
    
    //Finish the session:
    [videoWriterInput markAsFinished];  
    [videoWriter finishWriting];
    NSLog(@"Write Ended");
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a video site that has a row of images
I am trying to resize a video so that if fills 100% of its
I'm trying to change video dimensions using ffmpeg. For example, user is uploading video
I'm trying to build the Flickr video player url from the flickr.photos.getInfo API call,
I am change an app over to WPF, it plays audio and video and
I'm trying the following code http://code.google.com/apis/ajax/playground/#change_the_playing_video It works well when runned from the playground
I'm trying change an input mask for textbox when the the check box has
Im trying to change images on click similar to what SO does with the
I´m trying to change a spring jsp example to use freemarker. I changed all
im trying to change font globally for whole application, the problem is, i am

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.