5

Core video experts, I'm creating a custom video player for .mov files. I have the .mov parser working and using the QTCoreVideo101 sample I am trying to play video.

The problem I have is the display link getFrameForTime I don't know how the time values can be used to find the correct frame.

The values contained in CVTimeStamp don't make any sense to me. Below is a sample of the values requested for a 1 second video. Can anyone explain how I use these values to find the correct frame in the .mov file?

First three requests - value of CVTimeStamp

  1. video time: 489150134353920.000000 hostTime: 2026048145326080.000000 videoTimeScale: 241500000.000000 rateScalar: 1.000000 videoRefreshPeriod: 4028320.000000

  2. video Time: 489150201462784.000000 hostTime: 2026048279543808.000000 videoTimeScale: 241500000.000000 rateScalar: 0.999985 videoRefreshPeriod: 4028320.000000

  3. video Time: 489156643913728.000000 hostTime: 2026074988871680.000000 videoTimeScale: 241500000.000000 rateScalar: 1.000000 videoRefreshPeriod: 4028320.000000

user1118321
  • 25,567
  • 4
  • 55
  • 86
user1127081
  • 161
  • 1
  • 3
  • 13

1 Answers1

2

CVTimeStamps are explained in the CVTimeStamp Reference Document. The videoTimeScale is the number of units that a second is divided into. So for 30 fps video, it would need to be at least 30 (though it could be any multiple of 30 - 60, 120, 30000, etc.). The videoTime is the time in the timescale where the current frame (or field) starts. So if your timebase is 30000, and you're on the 15th frame, your videoTimeScale would be 30000, and your videoTime would be 15000.

You can check that you've interpreted the value correctly by checking the smpteTime field and seeing if it matches what you expect. In the example above, it would be 0 hours, 0 minutes, 0 seconds, 15 frames (or 00:00:00:15).

Is there a reason why you can just use the OS's built-in video decoding facilities?

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • I can't use the built in decoding because my video file is encrypted. – user1127081 Jun 28 '12 at 13:21
  • smpteTime is always 0 (all values) Your explanation makes sense however, the data I receive does not. Based on your explanation I should see the same numbers for videoTime each time I play the video, correct? When I play my 1 second video the videotime differs each time I play the video. First run (first 2 frames requested) video Time: 490954255499264 video Time: 490954456825856 second run (first 2 frames requested) video Time: 491057066278912 video Time: 491057200496640 – user1127081 Jun 28 '12 at 14:33
  • 1
    *CVTimeStamps are explained in the CVTimeStamp Reference Document.* - No, they really aren't. That document does a very poor job of explaining the meaning of the fields. – finnw Nov 29 '13 at 08:50
  • @finnw More information is needed to properly answer this question any further. Which parameter are the values listed in the original post? The `timestampNow` or the `timestampOut`? Also, what are the flags for the timestamps? If the `kCVTimeStampSMPTETimeValid` flag is clear, then the SMPTE time won't be valid. But you might be able to call [`CVDisplayLinkTranslateTime()`](https://developer.apple.com/library/mac/documentation/QuartzCore/Reference/CVDisplayLinkRef/Reference/reference.html#//apple_ref/doc/uid/TP40010025-CH2-SW16) to get it. – user1118321 Nov 29 '13 at 16:18