Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Zrezal on Tue 03/06/2025 18:37:01

Title: Video plays very slowly
Post by: Zrezal on Tue 03/06/2025 18:37:01
Hi.
I'm trying to put a video in my game, but when it comes to playback the video is slower than the audio.
I have tried with .Ogg and .Ogv formats, with identical results.
I have tried with 7 second and 1 minute videos and the same thing happens.
PlayVideo("Intro.ogv", eVideoSkipNotAllowed, 0);
How can I solve this?
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Tue 03/06/2025 19:06:15
There have been a similar report:

https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/sound-of-my-video-has-a-delay-that-is-getting-worse-every-second/


Unfortunately, the previous user did not provide any further information.

We need to know some details about video format and how did you make the video (which software, export settings).
If possible, could you upload a short video example that has this problem?
Also, which version of AGS are you using?
Title: Re: Video plays very slowly
Post by: Zrezal on Tue 03/06/2025 19:13:49
The AGS version is 3.6.2.
The video has been encoded with Shotcut with these characteristics: bitrate 12M, resolution 1920X1080.
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Tue 03/06/2025 19:42:44
Quote from: Zrezal on Tue 03/06/2025 19:13:49The video has been encoded with Shotcut with these characteristics: bitrate 12M, resolution 1920X1080.

That's a high resolution video; is your game also 1920x1080? What is the video's framerate (fps)?

If your video's fps is high enough (like 60 fps), then there's a real chance that AGS cannot handle this fast enough, because it's streaming video from the file realtime and not only has to load and decode a frame, but also has to convert each frame into the texture.

Could you upload any random short video that you've made and that does not work (previously you mentioned a 7 seconds video)? I'd like to check out what is happening with it.
Title: Re: Video plays very slowly
Post by: Zrezal on Tue 03/06/2025 20:28:06
I am modifying the bitrate to 2M and it seems to almost match the video to the audio.
I don't understand why AGS is having trouble playing a simple video.
Even if I reduce the video to 320x240, it still happens the same.
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Tue 03/06/2025 20:55:25
Quote from: Zrezal on Tue 03/06/2025 20:28:06I don't understand why AGS is having trouble playing a simple video.

I cannot answer this question without having a video that I may do tests with.
The two guesses I have is:
1. It does not process the video fast enough
2. AGS uses a pretty old video decoder library. It's possible that it cannot process certain video format properly.

Title: Re: Video plays very slowly
Post by: Crimson Wizard on Tue 03/06/2025 21:09:32
I haven't done many tests of videos in AGS, so I don't have enough experience to tell which parameters to use.
Quickly checked couple of AGS games that had video cutscenes in them.
For example, "Zniw Adventure" (https://store.steampowered.com/app/904750/Zniw_Adventure/) (a 640x480 game) has videos with following parameters:
- 640x480
- Framerate: 13 fps
- Bitrate: 1 to 1.5 Mbps (varies between videos)
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Tue 03/06/2025 21:16:52
I found another example in recent "Old Skies" (https://store.steampowered.com/app/1346360/Old_Skies/), it has following videos:
- 1920 x 1080
- Framerate: 24 - 36 fps
- Bitrate: 25 - 34.0 Mbps

But these are very short (few seconds only).
Title: Re: Video plays very slowly
Post by: Zrezal on Tue 03/06/2025 21:20:59
I can't give you a video because I am constantly changing parameters and recompiling it.
Tomorrow I will post more results by lowering the bitrate and fps a bit from 24 to 20.
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Tue 03/06/2025 21:23:47
Quote from: Zrezal on Tue 03/06/2025 21:20:59I can't give you a video because I am constantly changing parameters and recompiling it.

Well, you could post any of them that did not work?
Title: Re: Video plays very slowly
Post by: Zrezal on Wed 04/06/2025 09:52:40
It can be seen that the video at the beginning is unbalanced video and audio. In the introduction animation it is unbalanced later on.
The only solution I see is to do as with the menu, create a gif.

Title: Re: Video plays very slowly
Post by: Crimson Wizard on Wed 04/06/2025 10:43:22
Zrezal, I'm sorry if I was not clear, by "posting a video" I meant uploading it somewhere as a file which I could download and test in the engine.

I need to actually see the video file, see its parameters, see what the engine is doing.
Title: Re: Video plays very slowly
Post by: Zrezal on Wed 04/06/2025 11:45:38
Ok.
https://www.mediafire.com/file/mocsphsf5f2plma/3x3+Eyes+Kyuusei+Koushu+S.zip/file (https://www.mediafire.com/file/mocsphsf5f2plma/3x3+Eyes+Kyuusei+Koushu+S.zip/file)
Title: Re: Video plays very slowly
Post by: Zrezal on Wed 04/06/2025 19:40:44
I have already solved it. I reduced the resolution from 1080p to 640X480, so videos under 7 seconds play without problems.
The bad thing is that I have to keep editing.
I think this AGS problem should be worked on and it has been going on for too long.
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Wed 04/06/2025 20:06:46
I tried the project that you linked above, and I see a different problem where video plays in a good rate (or so it seems), but sound is delayed by 1-1.5 seconds. This may be a general desync issue. Of course I cannot tell if this is the original video, or it's already an edited one, so maybe the situation with it is different from the earlier one that you tried.

(On a side note, I have a question whether the choice of 1920x1080 resolution is optimal for the game, as both the video and backgrounds that I see in this project were probably converted from lower res.)

Quoteso videos under 7 seconds play without problems

What about videos longer than 7 seconds?

QuoteI think this AGS problem should be worked on and it has been going on for too long.

Unfortunately a number of problems in AGS have been going for too long, as it's been developed by a tiny number of people working in their spare time. Videos are not used often in games made by AGS, so the video playback support has always been low priority.

Apparently, I will have to look into video playback closely this year.
Title: Re: Video plays very slowly
Post by: Zrezal on Thu 05/06/2025 09:14:26
Quote from: Crimson Wizard on Wed 04/06/2025 20:06:46I tried the project that you linked above, and I see a different problem where video plays in a good rate (or so it seems), but sound is delayed by 1-1.5 seconds. This may be a general desync issue. Of course I cannot tell if this is the original video, or it's already an edited one, so maybe the situation with it is different from the earlier one that you tried.

(On a side note, I have a question whether the choice of 1920x1080 resolution is optimal for the game, as both the video and backgrounds that I see in this project were probably converted from lower res.)

Quoteso videos under 7 seconds play without problems

What about videos longer than 7 seconds?

QuoteI think this AGS problem should be worked on and it has been going on for too long.

Unfortunately a number of problems in AGS have been going for too long, as it's been developed by a tiny number of people working in their spare time. Videos are not used often in games made by AGS, so the video playback support has always been low priority.

Apparently, I will have to look into video playback closely this year.

If they exceed 7 seconds, they start to get out of sync.
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Thu 05/06/2025 13:26:13
Alright, since this is a clear observable problem, and I now have an actual video that demonstrates this, I'll address this now and try to fix this within one of the next 3.6.2 patches.
Title: Re: Video plays very slowly
Post by: Crimson Wizard on Thu 12/06/2025 01:07:35
I've spent some time investigating this case.

There are two potential issues here. One is when the video is playing too slow. This may happen if AGS cannot decode and render it fast enough. This also depends on many factors like player's PC (may be slow on one PC and fast on another). But that's an obvious problem. It does not happen to me with the particular video which was linked above though.

There's another issue that I observe with that particular video. I wrote gathering of statistics in AGS's video player, and judging by what the statistics say, this video is not played much differently from the videos in other games where they work fine. There's also no observable discrepancy between amount of audio played and number of video frames displayed over the time.

This might mean that the problem (in this particular case) is not in the AGS video player, but somewhere in the video decoder that it uses. There was another known issue with it, where it would skip a sequence of black frames and display only 1 of them. Which may cause desync with audio (video going faster than the audio).
https://www.adventuregamestudio.co.uk/forums/advanced-technical-forum/problems-with-ogv-video/msg636666228/#msg636666228
Maybe this, or something similar, is contributing to the problem with your video.

I cannot tell why the video behaves like this, possible there's something about how it was encoded.
Unfortunately, I also do not know how does the regular player manage to recognize this situation.
I will continue investigating.


Title: Re: Video plays very slowly
Post by: Crimson Wizard on Fri 13/06/2025 00:07:38
@Zrezal
I started experimenting with your video file using ffmpeg program, and when reading it it prints numerous warnings like:

"Broken file, non-keyframe not correctly marked".

Idk if it relates to the syncing issues or not.

I made a further experiment by simply reconverting OGV into OGV using ffmpeg, like this:
ffmpeg.exe -i input.ogv -c:v libtheora -q:v 7 -c:a libvorbis -q:a 4 output.ogv

And after using the resulting output video instead, it started playing considerably better in AGS, with no visible desync.
This proves my theory that there's something off in the way the video was encoded, perhaps it has mistakes or non-standard encoding. The decoder that AGS uses is quite simple and does not know how to "fix" the video (unlike sophisticated video players).
Title: Re: Video plays very slowly
Post by: Zrezal on Tue 17/06/2025 10:59:38
I don't understand why that happens. I've made the opening video, which is more than two minutes long and with the same characteristics, and it works perfectly. Is it because of the subtitles?
Well, the thing is that I've been able to solve it in this sloppy way that is hardly noticeable.
Title: Re: Video plays very slowly
Post by: Eon_Star on Tue 24/06/2025 11:20:17
Hi,

Did you try Theora software and convert your video to ogv?

Even if the video is in ogv format Theora helps compiling or adapting the video to AGS.

I will make a tutorial on this topic.

 :)