Feat/ Add Video::getDuration#2261
Conversation
…ion. 0 is typically header/first frame.
|
I wonder if there's a benchmark on how long |
|
I can check with the 3 videos I had how long they took.
What do you mean? Duration is calculated during init for a new instance of video, so I imagine there's at least some overhead. Though with these 3 videos calculations seemed instantaneous. I used the following to load and get the duration of these videos btw for this small "game": So don't know for sure about Edit: I'll check |
|
with Video::getDuration() without Video::getDuration() ( Note: actual The overhead seems relatively tiny, though growing linearly depending on the size of the video. Using .222 ms to load a 3 minute Without the duration calculation, similarly extrapolating linearly, it would take about .78 ms to load a 15 minute video. |
MikuAuahDark
left a comment
There was a problem hiding this comment.
Alright, code lgtm.
|
If the extra time for longer videos is unavoidable, is it possible to only pay that cost when using getDuration, so people who don't use it don't have the longer load times? I'm also thinking about situations where a hard drive is slower, which would multiply the extra costs if they're related to disk access. |
|
It's possible to move when this is calculated, it's been a bit but I think I can update when this is calculated to the first time getDuration is called, though there would be some delay at that first call. Should we have the method be explicitly async then? There are optimizations FFmpeg does that i haven't implemented yet, since it's more complicated given the .ogv format. That can be explored down the line if the delay for longer vids is too much, but ~1 second delay on a 15 min seems like it be more than okay |
It'd depend on the system, but videos are supposed to stream their data in general so I wouldn't expect newVideo to take significantly longer for longer videos compared to shorter ones, at least not by default. |
|
The delay is because video duration has to be calculated, it's not part of the metadata explicitly for this file format. |
|
I understand that, I'm just hoping there's a way to avoid the load-time regression for people who are not interested in the video duration. |
Fixes #2050
tldr;
Video::getDurationimplemented, do we want to truncate decimal points and do we want FFmpeg accuracy or "more" accurate?Description
Was a huge pain but opted for a linear scan of the entire
.ogvfile, while following roughly what FFmpeg does in its implementation (namely, the linear scan, skip invalid granulepos, track highest, restore position). Difference being that FFmpeg has start_time handling and seeks for the valid video location in the.ogvfile format so faster in much larger file sizes, among other internal orchestration logic.Opted for much simpler implementation and the results were accurate and still pretty fast. A 3 minute video didn't even cause any noticeable slowdowns, and duration is cached per video instance.
Discussion
I tested the changes in a local Love2D project and used the :01 second video (
sample.ogv) provided by this repo, and also used two.ogvvideos from https://filesamples.com/formats/ogv#google_vignette - the 3:03 video (sample_1280x720_surfing_with_audio) and the :13 video (sample_640x360.ogv).The changes in the PR outputted the following results:
I thought the slight difference may have been a bug, and comparing it with the
ffprobeCLI tool's output from FFmpeg, I'd get the following:Note:
sample_640x360.ogvhas the exact same duration calculated between the newVideo::getDurationAPI and FFmpeg's API.The reason for this is because FFmpeg's API's seem to get full container duration, which is the max between the video duration and the audio's duration if it exists.
Running the following confirms this behavior:
Decisions
1.022653->1.02) or have devs manually handle this?.ogvcontainer or keep what we have and get the actual video duration. I'm leaning towards how FFmpeg handles this. For example,sample.ogvis1.022653 secondslong however if we went with this current implementation, a dev would get0.833333 secondswhen calling this API which may be unexpected and cause some sync issues in their games.Lmk how you feel and I'll update accordingly.