rs / SDAVAssetExportSession

AVAssetExportSession drop-in replacement with customizable audio&video settings
MIT License
805 stars 212 forks source link

Issue with portrait video #6

Closed TheSquad closed 11 years ago

TheSquad commented 11 years ago

Hi, First of all thank you for your work, it is a great drop-in replacement !

Compressing Landscape video works great, fast, and painless... However Portrait video does not seems to be as painless ;-)

I'm having issue with result video being strechted, but more than a thousand words here the original and result screens...

Original 720x1280

Result result

Has you can see, is it streched down on the width, and streched up on the height... I cannot seems to find out why...

My code using your class is :

    AVAsset *asset = [AVAsset assetWithURL:[info objectForKey:@"UIImagePickerControllerMediaURL"]];
    AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];

    CGSize renderSize = [PMVideoTools getVideoSize:asset]; // Aware of orientation

    NSLog(@"Transfer RenderSize %f - %f", renderSize.width, renderSize.height);

    SDAVAssetExportSession *encoder = [SDAVAssetExportSession.alloc initWithAsset:asset];
    encoder.outputFileType = AVFileTypeMPEG4;
    encoder.outputURL = [PMVideoTools createURLWithFileName:@"output.mp4"];

    NSLog(@"Exporting to : %@", encoder.outputURL.path);
    encoder.videoSettings = @
    {
    AVVideoCodecKey: AVVideoCodecH264,
    AVVideoWidthKey: [NSNumber numberWithFloat:(renderSize.width)],
    AVVideoHeightKey: [NSNumber numberWithFloat:(renderSize.height)],
    AVVideoCompressionPropertiesKey: @
        {
        AVVideoAverageBitRateKey: [NSNumber numberWithInt:videoTrack.estimatedDataRate],
        AVVideoProfileLevelKey: AVVideoProfileLevelH264BaselineAutoLevel,
        },
    };

    encoder.audioSettings = @
    {
        AVFormatIDKey: @(kAudioFormatMPEG4AAC),
        AVNumberOfChannelsKey: @2,
        AVSampleRateKey: @44100,
        AVEncoderBitRateKey: @128000,
    };

Is there something wrong with my code ?

TheSquad commented 11 years ago

Ok I have fixed it... on your code if you wish to update it, here it is...

rs commented 11 years ago

Pull request?

TheSquad commented 11 years ago

Sorry I have no idea how to do that... I'm not a big github user

GabeRoze commented 9 years ago

I also have this issue and had to copy @TheSquad 's code. I can try submitting a pull request it if I get a chance