add Lua function for movie duration

This retrieves the duration from the movie stream.  Thanks to @asarium for pointing me in the right direction.
This commit is contained in:
Goober5000 committed 2023-11-23 13:11:40 -05:00
1 parent ecc452088c
commit 072e802863
3 files changed
+22 -2

No files matched your search

+1
View File
@@ -52,6 +52,7 @@ struct MovieProperties {
FrameSize size;
float fps = -1.0f;
float duration = 0.0f;
FramePixelFormat pixelFormat = FramePixelFormat::Invalid;
};
+1
View File
@@ -503,6 +503,7 @@ MovieProperties FFMPEGDecoder::getProperties() const
props.size.height = static_cast<size_t>(m_status->videoCodecPars.height);
props.fps = static_cast<float>(getFrameRate(m_status->videoStream, m_status->videoCodecCtx));
props.duration = static_cast<float>(m_status->videoStream->duration * av_q2d(m_status->videoStream->time_base));
props.pixelFormat = getPixelFormat(getConversionFormat(m_status->videoCodecPars.pixel_format));
+20 -2
View File
@@ -53,10 +53,10 @@ ADE_VIRTVAR(FPS, l_MoviePlayer, "number", "Determines the frames per second of t
{
movie_player_h* ph = nullptr;
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
return ade_set_args(L, "i", -1);
return ade_set_args(L, "f", -1);
if (ph == nullptr || !ph->isValid()) {
return ade_set_args(L, "i", -1);
return ade_set_args(L, "f", -1);
}
if (ADE_SETTING_VAR) {
@@ -66,6 +66,24 @@ ADE_VIRTVAR(FPS, l_MoviePlayer, "number", "Determines the frames per second of t
return ade_set_args(L, "f", ph->player()->getMovieProperties().fps);
}
ADE_VIRTVAR(Duration, l_MoviePlayer, "number", "Determines the duration in seconds of this movie <b>Read-only</b>", "number",
"The duration of the movie or -1 if handle is invalid")
{
movie_player_h* ph = nullptr;
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
return ade_set_args(L, "f", -1);
if (ph == nullptr || !ph->isValid()) {
return ade_set_args(L, "f", -1);
}
if (ADE_SETTING_VAR) {
LuaError(L, "Tried to modify read-only member!");
}
return ade_set_args(L, "f", ph->player()->getMovieProperties().duration);
}
ADE_FUNC(update, l_MoviePlayer, "timespan step_time",
"Updates the current state of the movie and moves the internal timer forward by the specified time span.",
"boolean", "true if there is more to display, false otherwise")