Where can I find the size of a video frame?

I am reading a video file frame by frame, but not displaying it. I createt the following relevant objects:

  • AVURLAsset
  • AVAssetTrack
  • AVAssetReader
  • AVAssetReaderTrackOutput

but none of these gives me the (pixel x pixel) size ot the data returned by assetReaderTrackOutput.copyNextSampleBuffer()


The AVAssetTrack has a naturalSize variable, but it isn't in pixels; some of my video has a natural size of 853x480, but the pixel size is 704x480 according to the Finder. (Right now I just kludge the width value.) Is there a robust way to get this information? I can see that it is buried in the metadata, but why is it not exposed in any of the AV objects I'm using?

Answered by NoHalfBits in 341163022

Get the (first) format description from the AVAssetTrack, then use

CMVideoFormatDescriptionGetPresentationDimensions(…)
on it. This function has flags where you can specify if you want the result with or without pixel aspect ratios taken into account (what seems to be the "problem" in your case), among others.
Accepted Answer

Get the (first) format description from the AVAssetTrack, then use

CMVideoFormatDescriptionGetPresentationDimensions(…)
on it. This function has flags where you can specify if you want the result with or without pixel aspect ratios taken into account (what seems to be the "problem" in your case), among others.

Thanks! It's logical, but obscure.


I had a chuckle last night when I realized that the More Like This list was headed by H264 sizes puzzle me, a question I posed in 2015 when I first encountered this problem.

Where can I find the size of a video frame?
 
 
Q