Stellarium
24.3
|
StelVideoMgr provides a scriptable way to show videos embedded in the screen. More...
#include <StelVideoMgr.hpp>
Public Slots | |
void | init () override |
void | update (double deltaTime) override |
Update the module with respect to the time. More... | |
void | loadVideo (const QString &filename, const QString &id, const float x, const float y, const bool show, const float alpha) |
load a video from filename, assign an id for it for later reference. More... | |
void | playVideo (const QString &id, const bool keepVisibleAtEnd=false) |
play video from current position. If keepLastFrame is true, video pauses at last frame. | |
void | playVideoPopout (const QString &id, float fromX, float fromY, float atCenterX, float atCenterY, float finalSizeX, float finalSizeY, float popupDuration, bool frozenInTransition) |
Play a video which has previously been loaded with loadVideo() with a complex effect. More... | |
void | pauseVideo (const QString &id) |
Pause video, keep it visible on-screen. More... | |
void | stopVideo (const QString &id) |
Stop playing, resets video and hides video output window. | |
void | dropVideo (const QString &id) |
Unload video from memory. | |
void | seekVideo (const QString &id, const qint64 ms, bool pause=false) |
Seek a position in video id. More... | |
void | setVideoXY (const QString &id, const float x, const float y, const bool relative=false) |
move upper left corner of video id to x, y. More... | |
void | setVideoAlpha (const QString &id, const float alpha) |
sets opacity More... | |
void | resizeVideo (const QString &id, float w=-1.0f, float h=-1.0f) |
set video size to width w and height h. More... | |
void | showVideo (const QString &id, const bool show) |
show or hide video player More... | |
qint64 | getVideoDuration (const QString &id) const |
returns duration (in milliseconds) of loaded video. More... | |
qint64 | getVideoPosition (const QString &id) const |
returns current position (in milliseconds) of loaded video. More... | |
QSize | getVideoResolution (const QString &id) const |
returns resolution (in pixels) of loaded video. Returned value may be invalid before video has been fully loaded. | |
int | getVideoWidth (const QString &id) const |
returns native width (in pixels) of loaded video, or -1 in case of trouble. | |
int | getVideoHeight (const QString &id) const |
returns native height (in pixels) of loaded video, or -1 in case of trouble. | |
void | muteVideo (const QString &id, bool muteVideo=true) |
set mute state of video player More... | |
void | setVideoVolume (const QString &id, int newVolume) |
set volume for video. Valid values are 0..100, values outside this range will be clamped. | |
int | getVideoVolume (const QString &id) const |
return currently set volume (0..100) of media player, or -1 in case of some error. | |
bool | isVideoPlaying (const QString &id) const |
returns whether video is currently playing. More... | |
Public Member Functions | |
StelVideoMgr (bool withAudio) | |
Constructor. More... | |
Public Member Functions inherited from StelModule | |
StelModule () | |
Constructor. Every derived class MUST call setObjectName(className) in its constructor. | |
virtual void | init ()=0 |
Initialize itself. More... | |
virtual void | deinit () |
Called before the module will be deleted, and before the OpenGL context is suppressed. More... | |
virtual QSettings * | getSettings () |
Return module-specific settings. More... | |
virtual void | draw (StelCore *core) |
Execute all the drawing functions for this module. More... | |
virtual void | update (double deltaTime) |
Update the module with respect to the time. More... | |
virtual QString | getModuleVersion () const |
Get the version of the module, default is stellarium main version. | |
virtual QString | getAuthorName () const |
Get the name of the module author. | |
virtual QString | getAuthorEmail () const |
Get the email address of the module author. | |
virtual void | handleMouseClicks (class QMouseEvent *) |
Handle mouse clicks. More... | |
virtual void | handleMouseWheel (class QWheelEvent *) |
Handle mouse wheel. More... | |
virtual bool | handleMouseMoves (int x, int y, Qt::MouseButtons b) |
Handle mouse moves. More... | |
virtual void | handleKeys (class QKeyEvent *e) |
Handle key events. More... | |
virtual bool | handlePinch (qreal scale, bool started) |
Handle pinch gesture events. More... | |
virtual double | getCallOrder (StelModuleActionName actionName) const |
Return the value defining the order of call for the given action For example if stars.callOrder[ActionDraw] == 10 and constellation.callOrder[ActionDraw] == 11, the stars module will be drawn before the constellations. More... | |
virtual bool | configureGui (bool show=true) |
Detect or show the configuration GUI elements for the module. More... | |
Additional Inherited Members | |
Public Types inherited from StelModule | |
enum | StelModuleSelectAction { AddToSelection , ReplaceSelection , RemoveFromSelection } |
Enum used when selecting objects to define whether to add to, replace, or remove from the existing selection list. More... | |
enum | StelModuleActionName { ActionDraw , ActionUpdate , ActionHandleMouseClicks , ActionHandleMouseMoves , ActionHandleKeys } |
Define the possible action for which an order is defined. More... | |
Protected Member Functions inherited from StelModule | |
class StelAction * | addAction (const QString &id, const QString &groupId, const QString &text, QObject *target, const char *slot, const QString &shortcut="", const QString &altShortcut="") |
convenience methods to add an action (call to slot) to the StelActionMgr object. More... | |
class StelAction * | addAction (const QString &id, const QString &groupId, const QString &text, const char *slot, const QString &shortcut="", const QString &altShortcut="") |
convenience methods to add an action (call to own slot) to the StelActionMgr object. More... | |
StelAction * | addAction (const QString &id, const QString &groupId, const QString &text, QObject *contextObject, std::function< void()> lambda, const QString &shortcut="", const QString &altShortcut="") |
convenience methods to add an action (call to Lambda functor) to the StelActionMgr object. More... | |
StelVideoMgr provides a scriptable way to show videos embedded in the screen.
After experimental support with Qt4/Phonon library, this feature is available with native classes from Qt5 and Qt6. The latter seems much better. Videos can be scaled, paused, placed and relocated (shifted) on screen. Setting opacity seems not to do much in Qt5 unless setting it to zero, the video is then simply invisible. On Qt6 it mixes nicely. Therefore smooth fading in/out has not yet been developed or setting a semitransparent overlay does not work, but there is now an intro/end animation available: zooming out from a pixel position to a player frame position, and returning to that spot close to end of video playback.
However, support for multimedia content depends on the operating system, installed codecs, and completeness of the QtMultimedia system support, so some features or video formats may not work for you (test video and re-code it if necessary).
The listed functions have been tested and work on Ubuntu 15.04 with Qt5.4 with NVidia 9800M and Intel Core-i3/HD5500. You need to install GStreamer plugins. Most critical seems to be gstreamer0.10-ffmpeg from https://launchpad.net/~mc3man/+archive/ubuntu/gstffmpeg-keep, then it plays
In 2022 and with Qt6 (https://doc.qt.io/qt-6/videooverview.html) Qt requires:
According to https://wiki.qt.io/Qt_Multimedia, MinGW is limited to the decaying DirectShow platform plugin. The WMF platform plugin requires Visual Studio, so building with MSVC should provide better results. Some signals are not triggered under Windows, so we cannot use them, globally. There is partial success with MP4 files on MinGW, but also these are rendered badly. Often just shows an error on Windows/MinGW: DirectShowPlayerService::doRender: Unresolved error code 80040154 (number may differ, also seen: 80040228. Where is a list?) The formats tested on Windows are:
Update 2022: Seems to work with Qt5.12 and later. Does not show frame on Qt5.9. It also does not work in WSL/Ubuntu 20.04LTS/Qt5.12
Qt's API has changed, but much to the better. It finally seems to work as advertised. Even alpha transparency of the frame works.
Observations on macOS12.5: Works with Qt6, does not work with Qt5.
QtMultimedia is a bit tricky to use: There seems to be no way to load a media file to analyze resolution or duration before starting its replay. This means, configuring player frames either require absolute frame coordinates, or triggering necessary configuration steps only after replay has started. We opted for the latter solution because it allows scaled but undistorted video frames which may also take current screen resolution into account.
and non-appearing video frame, this seems to be https://bugreports.qt.io/browse/QTBUG-39567. This occurred on an Intel NUC5i3 with SSD, so loading the file should not be much of an issue.
To help in debugging scripts, this module can be quite verbose in the logfile if Stellarium is called with the command-line argument "--verbose".
StelVideoMgr::StelVideoMgr | ( | bool | withAudio | ) |
Constructor.
withAudio | usually true to allow audio output. |
|
slot |
returns duration (in milliseconds) of loaded video.
This may return valid result only after playVideo() or pauseVideo() have been called. Returns -1 if video has not been analyzed yet. (loaded, but not started).
|
slot |
returns current position (in milliseconds) of loaded video.
This may return valid result only after playVideo() or pauseVideo() have been called. Returns -1 if video has not been analyzed yet. (loaded, but not started).
|
slot |
returns whether video is currently playing.
id | name assigned during loadVideo(). |
|
slot |
load a video from filename, assign an id for it for later reference.
If id is already in use, replace it. Prepare replay at upper-left corner x/ y in native resolution, decide whether to show (play) the video already, and set opacity alpha. If you want non-native resolution, load with show set to false, and use resizeVideo() and showVideo().
|
slot |
set mute state of video player
muteVideo | true to silence the video, false to hear audio. |
|
slot |
Pause video, keep it visible on-screen.
Calling playVideo() continues replay, calling seekVideo() can move to a different position.
|
slot |
Play a video which has previously been loaded with loadVideo() with a complex effect.
The video appears to pop out from fromX/ fromY, grows within popupDuration to size finalSizeX/ finalSizeY, and shrinks back towards fromX/ fromY at the end during popdownDuration.
id | the identifier used when loadVideo was called |
fromX | X position of starting point, counted from left of window. May be absolute (if >1) or relative (0<X<1) |
fromY | Y position of starting point, counted from top of window. May be absolute (if >1) or relative (0<Y<1) |
atCenterX | X position of center of final video frame, counted from left of window. May be absolute (if >1) or relative (0<X<1) |
atCenterY | Y position of center of final video frame, counted from top of window. May be absolute (if >1) or relative (0<Y<1) |
finalSizeX | X size of final video frame. May be absolute (if >1) or relative to window size (0<X<1). If -1, scale proportional from finalSizeY. |
finalSizeY | Y size of final video frame. May be absolute (if >1) or relative to window size (0<Y<1). If -1, scale proportional from finalSizeX. |
popupDuration | duration of growing (start) / shrinking (end) transitions (seconds) |
frozenInTransition | true if video should be paused during growing/shrinking transition. |
|
slot |
set video size to width w and height h.
Use w=-1 or h=-1 for autoscale from the other dimension, or use w=h=-1 for native size of video. if w or h are <=1, the size is relative to screen dimensions. This should be the preferred use, because it allows the development of device-independent scripts. When native resolution is unknown at the time you call this, it will be evaluated at the next update() after resolution becomes known. Autoscaling uses viewport dimensions at the time of calling, so resizing the Stellarium window will not resize the video frame during replay.
|
slot |
Seek a position in video id.
Pause the video playing if pause=true.
|
slot |
sets opacity
alpha | opacity for the video (0=transparent, ... 1=fully opaque). |
|
slot |
move upper left corner of video id to x, y.
If x or y are <1, this is relative to screen size!
|
slot |
show or hide video player
id | name given during loadVideo() |
show | true to show, false to hide |
|
overrideslot |
Update the module with respect to the time.
This allows the special effects in playVideoPopout(), and may evaluate things like video resolution when they become available.
deltaTime | the time increment in second since last call. |