'Python - Set timestamp in video on keypress

I cannot find any solution online, so I resort to Stackoverflow to pose my question.

For a Python video-player implementation, I want to add an on key-press event. With this event, a timestamp will be written to a json file. This timestamp should be the exact time at which the key was pressed while watching the video (e.g. 05m22s).

I am wondering whether anybody knows how to do this with opencv, ffprobe/ffmpeg, moviepy, pyAV, or literally any other library that allows video processing? I am stuck on linking the "key pressed" action with the actual time that the video is playing at. All the rest I can handle.



Solution 1:[1]

I am not too familiar with pyqt5; I am using pygtk4 because I'm developing for linux and gnome, but that doesn't change the steps you need to take:

  • build your user interface and designate a container for your video. Here is an example for using pyqt; other libraries have analogous containers;

  • add a keypress signal handler to the container;

  • write a callback function when you click on the play button for your video that stores the current timestamp (for example, ts = time.time());

  • write a callback function to do whatever you want to happen when you press a key, i.e. compute the time difference between then and when you pressed play (for example, diff = time.time() - ts).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrej Prsa