rs / SDAVAssetExportSession

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

Strange cropping after setVideoMirrored #50

Open ghost opened 8 years ago

ghost commented 8 years ago

I use AVCaptureMovieFileOutput to record videos. SDAVAssetExportSession works fine, I use it to compress my recorded videos. An issue appear when I setVideoMirrored to true , SDAVAssetExportSession crop the video.

code setVideoMirrored

        AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
        AVCaptureConnection *connection = [movieFileOutput connectionWithMediaType:AVMediaTypeVideo];
        [connection setVideoMirrored:true];

code SDAVAssetExportSession

 AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:myVideoURL options:nil];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* videoPath = [NSString stringWithFormat:@"%@/video.mov", [paths objectAtIndex:0]];
    NSURL * myNewVideoUrl = [NSURL fileURLWithPath:videoPath];

    [[NSFileManager defaultManager] removeItemAtURL: myNewVideoUrl error:nil];

    exportSession_convertVideo2 = [SDAVAssetExportSession.alloc initWithAsset:avAsset];
    exportSession_convertVideo2.outputFileType = AVFileTypeQuickTimeMovie;
    exportSession_convertVideo2.shouldOptimizeForNetworkUse = YES;
    exportSession_convertVideo2.outputURL = myNewVideoUrl; 
    exportSession_convertVideo2.videoSettings = @
    {
    AVVideoCodecKey: AVVideoCodecH264,
    AVVideoWidthKey: [NSNumber numberWithFloat: 540.0],
    AVVideoHeightKey: [NSNumber numberWithFloat: 960.0], 
    AVVideoCompressionPropertiesKey: @
     {
        AVVideoAverageBitRateKey: @1000000,
        AVVideoProfileLevelKey: AVVideoProfileLevelH264High40,
        },
    };
    exportSession_convertVideo2.audioSettings = @
    {
    AVFormatIDKey: @(kAudioFormatMPEG4AAC),
    AVNumberOfChannelsKey: @2,
    AVSampleRateKey: @44100,
    AVEncoderBitRateKey: @128000,
    };

    [exportSession_convertVideo2 exportAsynchronouslyWithCompletionHandler:^
    {
        if (exportSession_convertVideo2.status == AVAssetExportSessionStatusCompleted)
        {
            NSLog(@"Video export succeeded"); 
        }
        else if (exportSession_convertVideo2.status == AVAssetExportSessionStatusCancelled)
        {
            NSLog(@"Video export cancelled"); 
        }
        else
        {
            NSLog(@"Video export failed with error: %@ (%ld)", exportSession_convertVideo2.error.localizedDescription, (long)exportSession_convertVideo2.error.code);
        }
    }];

original img_0494

after use SDAVAssetExportSession

capture d ecran 2016-02-16 a 15 40 04
kylebrowning commented 8 years ago

Yup, this only happens when setVideoMirrored is true.

torrao commented 8 years ago

I'm having the same issue. @titiSbr Did you managed to solve it?