4

We are trying to export videos and maintain their FPS. What is happening:

For 1 second video clip example:

  • regular motion videos shot at 30 FPS - export at 30 FPS - 30 frames total
  • regular motion videos shot at 60 FPS - export at 30 FPS - 30 frames total
  • slow motion videos set in camera roll to play in slow motion, export at 30 fps - but export every frame to cover the longer play period (e.g., 1 second video at 240 fps exports 8 seconds of video at 30 fps) - so 120 or 240 total
  • slow motion videos (120 or 240) set to play in native speed (or 1 second) - export at 30 fps - 30 frames total

What we want - export to match camera roll FPS in all cases. We are also compressing videos.

We have tried to solve unsuccessfully by reviewing these and others:

How do I control AVAssetWriter to write at the correct FPS

How to set expected framerate to AVAssetWriterInput

I'm guessing we may need an entirely different approach - haven't been able to solve - here is code used to try to upload a 240 fps video that is set to play it native speed - result is a 30 fps 1 second video (instead of 240 fps 1 second video):

    PHVideoRequestOptions *options = [PHVideoRequestOptions new];
    options.version = PHVideoRequestOptionsVersionCurrent;

    [[PHImageManager defaultManager] requestAVAssetForVideo:_phasset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * 

    _Nullable audioMix, NSDictionary * _Nullable info) 

    {
    if(([asset isKindOfClass:[AVComposition class]] && ((AVComposition *)asset).tracks.count == 2)) {
        SDAVAssetExportSession *encoder = [[SDAVAssetExportSession alloc] initWithAsset:asset];
        encoder.outputFileType = AVFileTypeQuickTimeMovie;
                            encoder.outputURL = url;
                            encoder.videoSettings = @
                            {
                            AVVideoCodecKey: AVVideoCodecH264,
                            AVVideoWidthKey: [NSNumber numberWithInteger:newWidth],
                            AVVideoHeightKey: [NSNumber numberWithInteger:newHeight],
                            AVVideoCompressionPropertiesKey: @
                                {
                                    //                                AVVideoAverageBitRateKey: [NSNumber numberWithInteger:bitrate * 1024],
                                AVVideoAverageBitRateKey: [NSNumber numberWithInteger:bitrate * 1024],
                                AVVideoProfileLevelKey: AVVideoProfileLevelH264High40,
//                                    AVVideoMaxKeyFrameIntervalKey: [NSNumber numberWithInt:240],
                                AVVideoExpectedSourceFrameRateKey: [NSNumber numberWithInteger:240]
                                },
                            };

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

            [encoder exportAsynchronouslyWithCompletionHandler:^{
                if (encoder.status == AVAssetExportSessionStatusCompleted) {
                    NSURL *URL = encoder.outputURL;
                    // exported video's fps is not 240 fps on here
                }
            }];
    } else {
        …
    }
}

Any suggestions on how to fix current code - or how to approach in a different way that works?

drees
  • 61
  • 4
  • Did you ever solve this issue? I am having the same issue, I just want to convert a 5 second 240fps video to a slomo video at 30 frames per second that is 8 times as long. – johnrechd Apr 22 '20 at 23:46

0 Answers0