- Home /
Unity VideoPlayer play frame by frame;
I am creating a player and i need a functionality to change frame when playback is paused( play frame by frame, seeking when paused). I am using RenderTexture mode but it is not updating a RawImage. Frame changes only when app looses focus ( I switch to some other app like web browser).
How can overcome this issue?
Answer by bab202 · Sep 13, 2019 at 03:54 AM
@Micz84 This is what I do to make VideoPlayer play frame by frame on a RawImage:
First, set Playback speed of VideoPlayer to 0
Then in script:
private void Start() {
videoPlayer.prepareCompleted += OnVideoPrepared;
videoPlayer.Prepare();
}
private void OnVideoPrepared(VideoPlayer videoPlayer) {
rawImage.texture = videoPlayer.texture;
rawImage.gameObject.SetActive(true);
videoPlayer.Play();
Debug.Log("Video done prepared.");
}
private void Update() {
if (Input.GetKeyDown(KeyCode.RightArrow)) {
Debug.Log("Step forward 1 frame");
videoPlayer.frame++;
videoPlayer.Play();
}
if (Input.GetKeyDown(KeyCode.LeftArrow)) {
Debug.Log("Step backward 1 frame");
videoPlayer.frame--;
videoPlayer.Play();
}
}
Answer by ubaidkhaliq · Oct 08, 2021 at 11:14 AM
public void nextFrame() {
Debug.Log("Step forward 1 frame");
videoPlayer.frame++;
videoPlayer.Play();
videoPlayer.Pause();
}
public void previousFrame() {
Debug.Log("Step backward 1 frame");
videoPlayer.frame--;
videoPlayer.Play();
videoPlayer.Pause();
}
Answer by leavittx · Mar 08 at 02:11 PM
For everybody interested in network synced/manually-driven video playback: http://u3d.as/2KgC
Your answer
![](https://koobas.hobune.stream/wayback/20220612140119im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Video capture and use at runtime 0 Answers
RenderTexture with Video Player 0 Answers
How to synchronize laggy stereo VR video with AudioSources? 0 Answers
Unity WebGL video player on mobile 0 Answers