Movement by a single frame in CMTime and AVFoundation

后端 未结 2 991
花落未央
花落未央 2021-02-09 19:38

I\'m attempting to play a video with AVFoundation. I am using the following code for a button that advances the playback by one frame.

It works intermittently, on some e

相关标签:
2条回答
  • 2021-02-09 20:16

    The answer to your question is in the second line of code where you remove the "nominal" from nominalFrameRate.

    Your code assumes that the frame rate in your video is constant. This is incorrect.

    A video can have a constant fps, but it doesn't have to. E.g. if you shoot a film with your phone in variable lighting conditions then the frame exposure time can change and your frame rate will vary inversely.

    To "snap" to frame boundaries, you need to use an AVAssetReader to step through the individual frames. Each frame is tagged with a Presentation Time Stamp (its "t"), but if you're stepping that doesn't matter so much, unless you're updating a position marker.

    0 讨论(0)
  • 2021-02-09 20:39

    It isn't very obvious (since strangely it's only available in AVPlayerItem rather than AVPlayer) but if the AVPlayerItem returns YES for canStepForward/canStepBackward then you can call stepByCount:(NSInteger)stepCount: to move forwards or backwards by a certain number of frames.

    0 讨论(0)
提交回复
热议问题