Movement by a single frame in CMTime and AVFoundation

后端 未结 2 990
花落未央
花落未央 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.

提交回复
热议问题