iphone export - how to maintain FPS on videos > 30 FPS










2















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?










share|improve this question


























    2















    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?










    share|improve this question
























      2












      2








      2


      1






      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?










      share|improve this question














      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?







      ios video frame-rate avassetexportsession






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 23:11









      dreesdrees

      111




      111






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310142%2fiphone-export-how-to-maintain-fps-on-videos-30-fps%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310142%2fiphone-export-how-to-maintain-fps-on-videos-30-fps%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線