Video Playback Function

Describes the video playback functions supported by Kirikiri Z.

Table of Contents

Specifications
Modes
Special Playback Functions
About Video Playback Preparation ( preparevideo )
About Layer Specification in Layer Mode
Behavior at the End of Video
Regarding the Phenomenon Where Video is Not Displayed in Layer Mode
Mixing Playback
Keyframes and Seeking



Mode Overlay Mode Mode that displays video using video overlay
Layer Mode Mode that plays video on a layer within Kirikiri
Mixer Mode Mode that displays video using VMR9 + Direct3D
Special Playback Functions Segment Loop Function to loop between specified frames
Period Event Function to trigger events at specified frames
Playback Speed Specification Function to specify the playback speed of the video
Multi-Audio Function to select and play one of the multiplexed audio streams
Audio Balance
(Panning)
-100000 to 0
to 100000
-100000 is completely left, 0 is center, 100000 is completely right.
When playing stereo sources, panning is achieved by
attenuating either the left or right channel.
Audio Volume 0 to 100000 0 is complete mute, 100000 is 100% volume
Audio Stream Content dependent Select the audio stream to play
Playback Speed >0 The settable range depends on the DirectShow filter.
With audio: 2.0 ≥ speed > 0.
1.0 is normal speed.
Getable Values Frame Rate Number of frames per second
Current Frame The frame currently being displayed.
There is no guarantee that it perfectly matches the displayed frame number.
Current Playback Time Elapsed time within the video from the beginning.
Image Size Width and height
Number of Audio Streams Number of multiplexed audio streams
Total Frames Total number of frames held by the video
Total Time Total duration of the video
Events Frame Update Occurs after a video frame is updated
Period Event Occurs at normal loop ends, segment loop ends,
set period events, and when playback preparation is complete.
Status Change Occurs when the playback state changes



TypeDescription
Overlay Mode A mode that displays video using video overlay.
It is displayed in front of any other layers within Kirikiri.
In most cases, movie playback will be the lightest in this mode.
If you just want to play and stop a video, using Overlay Mode is recommended.
However, it has been reported that on some environments using Windows Vista and Windows XP when Kirikiri's drawing mode is DirectDraw, scaling in Overlay Mode does not look clean (jaggies occur).
For this reason, it is better to avoid Overlay Mode on Windows Vista.
Layer Mode A mode that plays video on a specified layer within Kirikiri.
It has low environment dependency, and functions such as looping between specified frames (Segment Loop) and processing at specified frames (Period Event) are available.
However, it has the disadvantage of higher CPU load than other modes.
Also, scaling is not possible.
Mixer Mode Added as an alternative to Overlay Mode, this mode displays video using VMR9 + Direct3D.
If the video card has video playback acceleration features and the codec supports it, it can be played using the video card's hardware acceleration.
The jaggy issue when scaling on Windows Vista is also avoided.
Additionally, mixing with specified layers and scaling are possible.
DirectX 9 or later is required to use this mode.



TypeDescription
Segment Loop A function that loops between specified frames.
To use this function, you must set a keyframe in the video file itself at the frame where the loop returns.
If there is no keyframe, it will not loop as expected.
Period Event A function that can trigger an event at a specified frame to perform some processing.
By seeking to a distant frame when an event occurs, it is possible to skip intermediate frames and make the video look as if it is continuous.
Also, if you want to display subtitles synchronized with the video, you can achieve this by setting a period event at the starting frame of the subtitles and waiting for the event to display the text.
Additionally, using this function, you can play sounds using SE at specified frames without including audio in the video itself.
Playback Speed Control The video playback speed can be specified.
Specifying 1.0 results in normal playback speed, 0.5 results in half speed, and 2 results in double speed.
The values that can be set depend on the DirectShow filter (Codec).
Multi-Audio In MPEG I, multiple audio streams can be multiplexed, and this function utilizes that.
With this function, any audio stream can be played.
For example, you can prepare streams such as BGM only or BGM + Voice, allowing the user to specify which mode to play in.
However, because there is a time lag of about 2 seconds when switching audio streams, it is not very suitable for highly interactive purposes.
It can be used for purposes such as user selection or changing video audio depending on the scene as mentioned above.


preparevideo draws the first frame of the video onto the specified layer.
This is used to prevent unintended images (memory garbage, previous images, etc.) from being displayed on the screen.
In other words, by hiding the target layer, opening the video with openvideo, calling preparevideo, waiting for preparation with wp, and then making the target layer visible after preparation is complete, you can display the first frame of the video the moment it is shown.
Note that this function is only meaningful in Layer Mode.



When playing video in Layer Mode, use videolayer to specify the drawing target layer.
In videolayer, you can specify slot, channel, page, and layer.
The slot is equivalent to the buf in se, and is used to identify which video the operation is for when playing different videos simultaneously.
Since it is unlikely that multiple videos will be played at the same time, it is usually fine to omit the description and let 0 be specified.
The channel exists to specify the layer to output to.
Up to two layers can be specified per video, so it is used to identify which of those two is being specified.
The reason two can be specified is to utilize transitions.
If a transition is executed while a video is playing, the front and back layers are swapped, so if it is only outputting to one side, the video will disappear.
To avoid this, when performing a transition during video playback, set the front and back layers to channels 1 and 2. If you are not performing transitions, specifying only the front side is sufficient.



If you play a video without specifying a loop, the video will stop once it plays to the end.
If you want to proceed with the game while displaying the last frame of the video, this behavior is not ideal.
The easiest way to avoid this is to use Layer Mode.
In Layer Mode, since the video is drawn to a layer, the image of the last frame remains on the layer as is.
Therefore, you can proceed with the game while displaying the last frame without any special consideration.
In the case of Overlay or Mixer, the display disappears when stopped, so you must pause before reaching the final frame.
This can be achieved with a period event, but since it might stop if it hits the absolute final frame, it is better to include a few dummy frames at the end of the video so that it's okay even if it overshoots slightly.



If the display type of the layer targeted for video playback is set to alpha or similar, the video may not be displayed.
This is because if the video does not have an alpha channel, undefined data is written to the alpha channel position.
If the layer display type is set to alpha, this undefined data is treated as the alpha value, which can make it completely transparent.
To avoid this, set the display type of the target layer to opaque.
Doing so will make the video visible.
However, since it is difficult to use opaque in KAG, calling freeimage instead seems to achieve a similar effect.



As the name suggests, Mixer Mode allows you to mix and play video with other layers.
Things that can be specified regarding mixing in Mixer Mode are background color, blend ratio, and target mixing layer.
The target mixing layer mixes the video with the image at the moment it was set.
Therefore, even if the target mixing layer is updated, the content will not be updated unless it is set again.
However, calling the setting at every frame update will result in quite high CPU load.
To keep CPU load down, it is better to limit settings to only when updates occur.
The background color is the color blended when the blend ratio is less than 1.0.
By setting the background color to black or similar and changing the blend ratio, fade-in/out can be achieved.
Naturally, fade-in/out with the target mixing layer is also possible.
The blend ratio and layer position for the target mixing layer use the layer's information.
That is, the display position depends on the layer's position and the blend ratio depends on the layer's opacity.
However, due to the specification that blending with the layer must be specified every time, performing a fade-in/out with a layer will increase CPU load.



In Kirikiri, to perform seeking quickly, seekable positions are limited to keyframes.
If a frame other than a keyframe is specified, a seek operation to the keyframe closest to the specified frame is performed.
However, since this behavior depends on the Codec, unintended behavior often occurs.
Therefore, it is better to always set a keyframe at the frame where you intend to seek.