openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.98k stars 2.55k forks source link

ofVideoPlayer AVFoundation, setPosition can work with arbitrary frames. #8189

Open dimitre opened 1 week ago

dimitre commented 1 week ago

by lowering seekToTime tolerance to zero it will force the video frame to be displayed correctly.

Today if I load a video recorded with a camera, lets say Sony alpha 6500 in h264, it makes one keyframe each second. if I'm trying to setPosition in an arbitrary position it will only display one frame per second (the keyframe)

with this change we assure it will be positioned in the correct frame even if it takes more cpu cycles to calculate (in the case of random access or backwards access). it doesn't change anything for normal play because frame difference will be accumulating.

quick way of testing

    float pos = ofMap(mouseX, 0, ofGetWindowWidth(), 0, 1);
    video.setPosition(pos);
    video.update();
artificiel commented 1 week ago

it's great to be able to do that!

however it might also be good to have the option to maintain the current (default) to retrieve only keyframes as inter-frame decode presumably takes more CPU it will change the performance of existing code. ex:

video.setTolerance(ofVideoPlayer::TOLERANCE_ZERO);
video.setTolerance(ofVideoPlayer::TOLERANCE_INFINITY); // historical default
dimitre commented 1 week ago

We can optionally expose something like that if it is useful I can only see a setPosition that just works. the historical implementation is not good, I know people gave up using videoPlayer on macOS (which performs great btw)