1

I have this camera app I am developing. At some point I am trying to write to video, so I am creating an assetWriter and I have these lines:

  CGFloat videoFrameWidth = size.width;
  CGFloat videoFrameHeight  = size.height;

  NSUInteger numPixels = videoFrameWidth * videoFrameHeight;
  NSUInteger bitsPerSecond;

  NSUInteger bitsPerPixel = 11.4; // This bitrate matches the quality produced by AVCaptureSessionPresetHigh... this was copied from a code from Apple

  bitsPerSecond = numPixels * bitsPerPixel;

  NSDictionary *videoCompressionSettings = @{AVVideoCodecKey                  : AVVideoCodecH264,
                                             AVVideoWidthKey                  : @(videoFrameWidth),
                                             AVVideoHeightKey                 : @(videoFrameHeight),
                                             AVVideoCompressionPropertiesKey  : @{ AVVideoAverageBitRateKey      : @(bitsPerSecond),
                                                                                   AVVideoMaxKeyFrameIntervalKey : @(fps)}
                                             };

  if ([_assetWriter canApplyOutputSettings:videoCompressionSettings forMediaType:AVMediaTypeVideo])

if I am recording at 1080p @30 fps this method works perfectly but if I switch to 720p @ 60 fps this last line fails.

Duck
  • 34,902
  • 47
  • 248
  • 470
  • what happens if you remove the `AVVideoMaxKeyFrameIntervalKey` key? I think you're saying 1 keyframe every 60 frames with that. – Rhythmic Fistman Apr 11 '17 at 20:40
  • 1
    it makes sense what you say... I will try that and get back to here. All these things are so poorly document that you never know. I wish Apple fires satan, that today is the responsible for creating their develop tools and docs... – Duck Apr 12 '17 at 08:18
  • removing that key did the trick but now the video is created but always at 30 fps even if I shoot at 60 or higher fps... – Duck Apr 12 '17 at 08:40
  • Can you show some more code? Ideally how you're capturing and writing the frames. – Rhythmic Fistman Apr 12 '17 at 08:41
  • Please make your first comment an answer so I can accept. To tackle the other problem I have created [another question](http://stackoverflow.com/questions/43365266/how-do-i-control-avassetwriter-to-write-at-the-correct-fps) because you asked to see more code and the involved code is huge, I ask you what do you want to see specifically... please use the other question to answer... thanks and don't forget to make your comment the answer of this... thanks – Duck Apr 12 '17 at 09:17
  • Ok, done - now for the new question. – Rhythmic Fistman Apr 12 '17 at 10:56

1 Answers1

1

What happens if you remove the AVVideoMaxKeyFrameIntervalKey key? I think you're saying 1 keyframe every 60 frames with that.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159