gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
33.61k stars 2.54k forks source link

provide a way to 'see' a position of a video via the python API #3965

Open pngwn opened 1 year ago

pngwn commented 1 year ago

Is your feature request related to a problem? Please describe.
A user was asking for a way to seek to a specific position of a video. Currently this is pretty difficult and requires some hacky javascript (which would probably break). It would be good if we could provide a cleaner way of doing this, preferably via python.

Describe the solution you'd like
Add a seek or currentTime kwarg to the update method of Video (and probably Audio too). This would allow users to change the position of the video or audio with a clean python API. We could also expose one or two other properties while we are doing this, if it makes sense.

kavincsekaran commented 10 months ago

Is there an update on this? This would greatly help me. I am currently using some timers that keep track of the duration of video played by measuring the time between event triggers from play and pause of the video. After measuring the duration between each play and pause segment, when I add them up, the time doesn't match the time showed in the video seek position; it is off by a few seconds. It might not seem like much but I am using it to track human activities(micro activities) performed in video and a few seconds off means the entire label is wrong. I don't know how to offset this shift. Please help! Thanks.

moussaKam commented 10 months ago

Hello, I'm also working on an app that requires this feature for audios. I have the same problem as @kavincsekaran. Additionally if the user changed the seek position manually it would be impossible to retrieve it.

kavincsekaran commented 10 months ago

@moussaKam I was able to achieve a janky manual version of this by creating a Custom Component based on Video. I modified the code in Player.svelte and added an text input element to the player to enter the desired seek time and added a seek button which can be used to set the value of currentTime. I also added an event so that whenever the currentTime changed, it updated an invisible text element in the player with the currentTime and accessed that element using custom javascript in the python gradio app. I haven't looked into the audio player though. If they're similar you could give it a try. I'd be happy to help.