10

AVCaptureVideoDataOutput has a field availableVideoCodecTypes that's supposed to tell you what codecs you can use to record a video, but it's always empty. Why is this?

I checked its value immediately after creating the VideoDataOutput, and after adding it to the session, but it's empty. I tried on an iPhone 5s running iOS 10, and an iPhone 7 Plus running iOS 11, and it's empty on both.

This question is about AVCaptureVideoDataOutput. AVCaptureMovieFileOutput has another field with the same name, which works, but the question isn't about that.

One could say that VideoDataOutput gives you the frames rather than recording to a file, so a codec isn't involved, which is why the property is nil, but in that case, why have the property at all?

Kartick Vaddadi
  • 4,818
  • 6
  • 39
  • 55

1 Answers1

1

I don't know why it's empty. I ran into the same problem myself, BUT you can call the following method on AVCaptureVideoDataOutput and get valid results:

- (NSArray<AVVideoCodecType> *)availableVideoCodecTypesForAssetWriterWithOutputFileType:(AVFileType)outputFileType;

example usage:

NSArray *availableVideoCodecTypes = [videoDataOutput availableVideoCodecTypesForAssetWriterWithOutputFileType:AVFileTypeQuickTimeMovie];

on iPhone XR running iOS 12 this returns

hvc1, // AKA HVEC or H.265
avc1, // AKA H.264
jpeg

on iPhone 6s+ running iOS 12 it returns

avc1, // AKA H.264
jpeg
Cortis Clark
  • 169
  • 1
  • 5