Player features
TVideoGrabber includes an advanced player that plays video clips, captures video frames and performs frame overlay when the frame grabber is enabled.
Multiple video clips can be played seamlessly with the Seamless playback feature.
4K clips up to 120 fps and 8K clips up to 60 fps are decoded by the GPU and played in NV12, with text and image overlays and frame capture: see 4K and 8K playback (by default, the OnFrameBitmap event is not raised for these clips).
Opening / pausing / running / closing the clip
- Set the PlayerFileName property to the fully qualified path or the URL of the video clip.
- Open the clip with OpenPlayer.
When the clip is opened, the OnPlayerOpened event occurs. From this event, the PlayerDuration and PlayerFrameCount properties can be read, e.g. to set up a trackbar (see "Player trackbar" below).
To open a clip in a paused state:
VideoGrabber.PlayerFileName = "myclip.avi"
VideoGrabber.AutoStartPlayer = false
VideoGrabber.OpenPlayer()
To open and play a clip immediately:
VideoGrabber.PlayerFileName = "myclip.avi"
VideoGrabber.AutoStartPlayer = true
VideoGrabber.OpenPlayer()
To pause a clip during playback:
VideoGrabber.PausePlayer()
To resume the playback when the clip is paused:
VideoGrabber.RunPlayer()
To close the clip, invoke ClosePlayer:
VideoGrabber.ClosePlayer()
Player seeking
Note
- If seeking is slow in a video clip, invoke MultipurposeEncoder_ReindexClip to reindex it (requires the optional Datastead Multipurpose Encoder to be installed).
- To determine whether an MP4 video clip needs reindexing, invoke MP4NeedsReindexing.
After the video clip is opened, a new position can be set by assigning:
- either the PlayerFramePosition property, in the 1..PlayerFrameCount range,
- or the PlayerTimePosition property, in the 0..PlayerDuration range (expressed in 100 ns units, e.g. 2 seconds = 20000000).
To set the current position to frame #500:
VideoGrabber.PlayerFramePosition = 500
To set a new position located at "15 seconds":
VideoGrabber.PlayerTimePosition = 150000000
Frame counting and frame seeking
By default, the frame counting / frame seeking starts from 1 (the 1st frame is frame #1).
To let TVideoGrabber start from frame #0 instead, enable the FrameNumberStartsFromZero property.
Frame stepping
When the clip is paused, invoke PlayerFrameStep (1) to step to the next frame.
Specify a value > 1 to skip n-1 frames, e.g. PlayerFrameStep (10) skips the next 9 frames and displays the 10th frame.
Seeking
If the clip is seekable, it can be played backwards with RunPlayerBackwards; however, the playback is not as smooth as normal playback.
To scan the clip quickly:
- forwards, use FastForwardPlayer,
- backwards, use RewindPlayer.
The scan speed can be modified with PlayerFastSeekSpeedRatio.
Keeping the last video frame visible while opening the next video clip
By default, after ClosePlayer is invoked, the video window is closed until the next clip is opened.
Enable the VideoVisibleWhenStopped property to keep the video window active after the previous video ends: the last video frame then remains displayed until OpenPlayer is invoked and the new video clip starts playing.
Playback boundaries
Instead of invoking OpenPlayer:
- invoke OpenPlayerAtFramePositions to open a clip at the specified start frame,
- invoke OpenPlayerAtTimePositions to open a clip at the specified start time.
If the KeepBounds parameter is true, the clip is played within the specified start and stop boundaries.
When the clip is already opened and the CloseAndReopenIfAlreadyOpened parameter is false, invoking OpenPlayerAtFramePositions or OpenPlayerAtTimePositions modifies the playback boundaries without reopening the clip.
Playback progress
During playback, information about each video frame is reported by the OnFrameProgress2 event, through the TFrameInfo structure.
End of stream
When the end of the stream is reached, the OnPlayerEndOfStream event occurs. Any task can be performed from this event, e.g. invoking RunPlayer to restart the playback from the beginning.
Paused player and CPU consumption
When a video clip is paused and both the PlayerRefreshPausedDisplay and FrameGrabber properties are enabled, the display is refreshed periodically, at the frame rate specified by PlayerRefreshPausedDisplayFrameRate, to refresh the text and graphic overlays.
However, this feature uses CPU. To reduce the CPU consumption when a video clip is paused:
- specify a lower PlayerRefreshPausedDisplayFrameRate value,
- or disable the PlayerRefreshPausedDisplay property.
Playback speed
A clip is played at its normal speed when PlayerSpeedRatio = 1.
Video clips can be played at different speeds; however, the playback speed range is larger if the audio rendering is disabled. To play a clip at a different speed:
- with audio rendering, enable PlayerAudioRendering and modify PlayerSpeedRatio in the 0.5 to 2.0 range,
- without audio rendering, disable PlayerAudioRendering and modify PlayerSpeedRatio in a larger range.
Playing clips at max speed without clock
The clips can be played without a clock; this guarantees, e.g., that all the frames are captured in burst mode (when BurstMode = true and BurstCount = 0).
To enable this feature, disable UseClock before invoking OpenPlayer.
Player trackbar
TVideoGrabber automatically handles a player trackbar (Delphi and C++Builder versions only).
Put a trackbar on the form, then associate it by assigning it to the PlayerTrackBar property from the Object Inspector. See the PlayerTrackBar and PlayerTrackBarScale properties for more information.
Frame capture during playback
Video frames can be captured during playback. See the Frame capture chapter.
Audio playback
For video clips that have an audio stream (when IsPlayerAudioStreamAvailable returns ts_True), the rendering of the audio stream can be disabled by setting PlayerAudioRendering to false. This can help to play video clips slower than 0.5 or faster than 2.
Selecting the audio sound card
To specify the sound card used for the playback rendering, set the AudioRenderer property to the index of the sound card in the AudioRenderers list.
E.g., if the index in the list is 2:
VideoGrabber.AudioRenderer = 2
Or, if the name in the list is "Speakers (Blackmagic Audio":
VideoGrabber.AudioRenderer = VideoGrabber.AudioRendererIndex ("Speakers (Blackmagic Audio")
Selecting only the right or left audio channel
AudioChannelRenderMode makes it possible to convert the right channel or the left channel to "mono", to mute the left, right or both channels, or to convert a mono channel into stereo.
Selecting one audio stream when the clip has multiple audio streams
When the clip has multiple audio streams, only one audio stream can be selected with AudioStreamNumber.
Codec used during playback
To force the use of a given codec, assign a codec name or a codec GUID to PlayerForcedCodec.
The local clips are opened first by the built-in Media Foundation source (decoding on the GPU with PlayerHwAccel = hw_Auto), also when the LAV Filters are installed: the LAV Filters open the clips that the Media Foundation source cannot play. PlayerForcedCodec = "LAVFIRST" restores the order of the previous versions (LAV Filters first), see 4K and 8K playback.
The video codec and audio codec used during playback are reported by the PlayerVideoCodec and PlayerAudioCodec properties.
Specifying the buffering time when playing a streaming URL
The buffering time can be adjusted by invoking ShowDialog (dlg_NetShowConfig).
Authentication
If authentication is required to connect to a streaming URL, the required username and password can be set in 2 ways:
- either by invoking SetAuthentication (at_StreamingUrl, "...username...", "...password...") before invoking OpenPlayer,
- or through the OnAuthenticationNeeded event, which occurs when connecting if SetAuthentication has not been invoked yet.