Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: kursh on Sat 05/10/2024 08:50:02

Title: problems with ogv video
Post by: kursh on Sat 05/10/2024 08:50:02
Hi i made the an intro for my game.

First in mpeg, then i convert to ogv.. the video its perfect in windows sound and image syncro.

The thing is when i use PlayVideo in AGS, the video goes faster than the sound.. or the sound is slower (its not syncro). I tryed with ogv in 30 fps and 25 fps.. and windows plays it perfect but not AGS...

i used www.freeconvert.com

some clues? thanks

carlos.
Title: Re: problems with ogv video
Post by: Crimson Wizard on Sat 05/10/2024 12:54:30
This happened before, was reported couple of times.

I was going to check this out, but did not find much at the time, maybe I might try again. I still have someones video which demonstrates the problem.

My suspicion was that AGS uses an old decoding library that cannot handle certain video properties, and thus gives video frames at the wrong rate, but idk if that's exactly so.
It's just that some videos play properly and others not.
Title: Re: problems with ogv video
Post by: kursh on Sat 05/10/2024 15:02:45
Thanks... i've readed someone has convert mpeg to ogv with VLC, i have tried but.. nothing vlc cant export correctly in my case... its really anoying...

im going to "build" the game and execute normally in windows (maybe executing the game compiled works..)

tested: Doesnt work (audio sounds 2 o 3 seconds later than should ...) :___(
Title: Re: problems with ogv video
Post by: Khris on Sat 05/10/2024 15:48:22
I recommended VLC, which has always worked fine for me. What exactly do you mean by "can't export correctly"?
Title: Re: problems with ogv video
Post by: kursh on Sat 05/10/2024 16:47:10
in vlc i convert to ogg, video codec theora, audio codec vorbis... the result didnt play this morning.....

but now i make another one conversion and i saw that the exported file is .ogg, i changed to .ogv and now is working in ags but without sound!.

i select audio codec Vorbis (if i select "same audio track original" doesnt works neither)

and other thing is the quality of the conversion is not good (i put in video bit rate 25000 kb/s)

Title: Re: problems with ogv video
Post by: kursh on Sat 05/10/2024 17:05:51
Quote from: Khris on Sat 05/10/2024 15:48:22I recommended VLC, which has always worked fine for me. What exactly do you mean by "can't export correctly"?

could you say how exactly do you convert? i start from a .mp4 video "Códec: H264 - MPEG-4 AVC (part 10) (avc1)" (maybe is the problem)
Title: Re: problems with ogv video
Post by: Rik_Vargard on Mon 07/10/2024 17:14:21
Do you use fades in or out or fades to black in your video editing?

For what I experienced back then when talking about this in the beginners forum is this:
It's just me but at this point of my "testing ogv in AGS" : it feels like AGS doesn't like black screens.

If you have black screen parts you might notice that in AGS, those are somewhat "ignored", which makes the video "go faster" than the audio.
I used different converters so I don't think those are the problem.

So, the black screens was my last observation before I moved on, and had to make three different files (Video,Music,SFX) and then go back and forward from editor to AGS to place the sounds and music until I got somewhat what I wanted in AGS.

I now use AGS v3.6.1 (Build 3.6.1.23) and haven't tested it again, yet, but that time will come. :-D
Title: Re: problems with ogv video
Post by: Khris on Tue 08/10/2024 06:52:33
Quote from: kursh on Sat 05/10/2024 17:05:51could you say how exactly do you convert? i start from a .mp4 video "Códec: H264 - MPEG-4 AVC (part 10) (avc1)" (maybe is the problem)
In my tests I don't really mess with the settings, just pick Video (Vorbis) and hit the button. Plus, if the ogv file plays fine in VLC, the issue is with AGS and needs to be fixed there.

I don't really have experience here; I simply knew that the free and very good VLC can convert video files, so recommended that instead of online conversion services with file size limits, etc.
Title: Re: problems with ogv video
Post by: Crimson Wizard on Tue 08/10/2024 12:39:08
Quote from: Khris on Tue 08/10/2024 06:52:33Plus, if the ogv file plays fine in VLC, the issue is with AGS and needs to be fixed there.

AGS uses particular library to decode, if that library does not support certain codec or settings, then it won't be able to play the video properly, or at all. So settings may matter. I do not know the acceptable range of settings though.
Title: Re: problems with ogv video
Post by: kursh on Fri 11/10/2024 14:52:15
Sorry i didnt saw your answers. thanks to all.

Quote from: Rik_Vargard on Mon 07/10/2024 17:14:21Do you use fades in or out or fades to black in your video editing?


yes Rik_Vargard, i made the intro in after effects and i used a fade out at the end... only at the end (the sounds go slower from the beginning) whatever.. im going to try something different.. or export another format from what to use VLC to get final Ogv...

its sad, all is working perfect for me but this... :D

thanks all
Title: Re: problems with ogv video
Post by: eri0o on Fri 11/10/2024 15:37:21
The sound decoding in AGS implementation is not done from libogg, but instead using SDL_Sound, which has a different implementation inside. This is done because we do decode the video images through the traditional Xiph library but pass the sound through the AGS sound system - this is for better sound control in our system, not in ags4 we have decoding multiple videos and other things supported there for video.

Anyway, my guess is you are hitting something that can be an issue in SDL_Sound, if it would be possible to get the video file, I could split the audio through a different program and run on SDL_Sound alone (without AGS) to try to figure it out what is happening.
Title: Re: problems with ogv video
Post by: Crimson Wizard on Fri 11/10/2024 16:23:40
Quote from: eri0o on Fri 11/10/2024 15:37:21The sound decoding in AGS implementation is not done from libogg, but instead using SDL_Sound, which has a different implementation inside. This is done because we do decode the video images through the traditional Xiph library but pass the sound through the AGS sound system - this is for better sound control in our system, not in ags4 we have decoding multiple videos and other things supported there for video.

This is not true, the video's sound is decoded by the libogg libvorbis (apparently), and only played by our general sound output (MojoAL).
SDL_Sound library is not used in case of video.

You may see the sound frame retrieval here:
https://github.com/adventuregamestudio/ags/blob/0d6194bff20633eca557793829738909131cff59/Engine/media/video/theora_player.cpp#L175-L191
Title: Re: problems with ogv video
Post by: Crimson Wizard on Fri 11/10/2024 16:41:43
@kursh , @Rik_Vargard , could any of you please make a short video that demonstrates this problem?
I have an old Rik_Vargard's video, but it's pretty long and has lots of stuff happening in it, it's difficult to understand at which point the problem appears, so not very convenient for a test.

Ideally, it could be a video with visual cues (visual element appearing/dissapearing/changing) synced with certain points on sound track, like beats.

I am interested what the actual problem is that results in video-sound desync:
- is it that the sound is playing literally slower, like slower tempo.
- is it that sound is played with pauses.
- is it that video frames are changing too fast, more frequently than required.
Title: Re: problems with ogv video
Post by: eri0o on Fri 11/10/2024 16:46:11
That's unexpected, why is the mpeg audio decoding code disabled there? This means the only type of audio track supported is strictly ogg - additionally, the libraries can't be the issue since they are the same libraries used by VLC.
Title: Re: problems with ogv video
Post by: Crimson Wizard on Fri 11/10/2024 17:15:29
The Theora video decoding was mostly untouched in many years, with the exception of small fixes.
The process of retrieving and decoding data is controlled by APEG library, everything happens inside of it. This is a very old library, and may have limitations, and, in theory, there may be cases that it simply does not know how to handle.
In order to decode an audio using SDL_Sound, for example, we would need to split the process into sound packet read and decoding steps. I suppose it might be possible to hack this inside APEG. But at the same time it may be beneficial to get rid of APEG and write a completely new video decoder, which will use SDL_Sound either directly, or through some interface.

Quote from: eri0o on Fri 11/10/2024 16:46:11why is the mpeg audio decoding code disabled there?

I have no idea, it may be a remains of times when MP3 was under a patent.

Title: Re: problems with ogv video
Post by: kursh on Sat 12/10/2024 14:05:47
Quote from: Crimson Wizard on Fri 11/10/2024 16:41:43I am interested what the actual problem is that results in video-sound desync:
- is it that the sound is playing literally slower, like slower tempo.
- is it that sound is played with pauses.
- is it that video frames are changing too fast, more frequently than required.

the 3rd one option i think whats happening because the sound is good tempo (not slower) video goes faster than music and effects.

I solved it yesterday... a video without sound, and then the sound in an independient mp3 file, i play it in a channel just before the PlayVideo (with "10" flag) and solved. It works now perfect for me. thanks.

Title: Re: problems with ogv video
Post by: Crimson Wizard on Sat 12/10/2024 14:15:09
I'd like to figure out what is happening, and look for a possible fix, that's why I've been asking for a test video with such problem. If we manage to fix it, then users won't have to stumble on this, or separate audio from video.
Title: Re: problems with ogv video
Post by: kursh on Sat 12/10/2024 14:37:19
Quote from: Crimson Wizard on Sat 12/10/2024 14:15:09I'd like to figure out what is happening, and look for a possible fix, that's why I've been asking for a test video with such problem. If we manage to fix it, then users won't have to stumble on this, or separate audio from video.

sorry. yes, i'll send you the video.
Title: Re: problems with ogv video
Post by: Crimson Wizard on Sat 12/10/2024 18:12:00
I received this video, and can observe the problem, where video is running faster than it should.

But I also noticed that there's a noise in the sound playback, which is not present when playing with a regular video player. I don't know if these two issues are connected or not.

EDIT: I found a previous topic by Rik_Vargard:
https://www.adventuregamestudio.co.uk/forums/beginners-technical-questions/ogv-video-images-going-faster-than-the-mucic-in-ags/

Rik_Vargard's video was 24 FPS, kursh's video is 25 FPS, idk if that matters.

EDIT2: I've been comparing first 5 seconds of intro, because that's roughly the time that makes the title text go upwards beyond the screen.
In AGS these 5 seconds are played roughly in 3.5 seconds, for some reason.

I have few proposals:
1. Video lies about its FPS (but then, how does the video player do it right?).
2. Video contains some "filler" frames that are supposed to be interpreted as "repeat previous frame", but the decoder in AGS ignores these.
3. Video frames are tagged with timestamps, i.e. playback is not supposed to rely on times calculated from FPS, but use each frame's timestamp instead.
Title: Re: problems with ogv video
Post by: Crimson Wizard on Sat 12/10/2024 20:07:41
It's curious, I tried the same video with the SpriteVideo plugin that uses a different TheoraPlayer library, and it seems to have same effect as AGS, with faster video playback.

There must be something specific in how the video is encoded, which standard theora playing lib cannot handle.

EDIT:
Since I have very little idea what to look at in OGG Theora, I will try downloading VLC player's source code and find how it interprets this video's parameters...

EDIT2:
Another curious thing: i tried to convert original video to Theora + OGG type using VLC itself, and the resulting video has exact same problem now...
Title: Re: problems with ogv video
Post by: kursh on Sat 12/10/2024 22:41:29

Thanks for your time. I have readed that post of 2023. It seems a problem of ags or the way we created de ogv file. ( i used vlc)

Im watching here..
Title: Re: problems with ogv video
Post by: Rik_Vargard on Sun 13/10/2024 08:57:25
If I may, I'd like to insist on the "pitch black screen" again. And I mean when the screen is 100% black (#000000) .  :P

I made a quick 20 secs video that I exported in MP4 and converted in OGV.
And as always, it looks perfect in VLC.

Please notice the long black screen moment around the 9th second.

>> https://www.mediafire.com/file/e0d62n14m96ka3y/_AGStest03.ogv/file

Then, I recorded how that video plays in AGS.
And there you will see that the black screen moment is "ignored" and that at the end the video stops at the last frame, waiting for the music to finish.

>> https://www.mediafire.com/file/61o8mwm6vdbgy73/AGStest03inEDITOR.mp4/file

And that's why we have the illusion that the movie goes faster than the sound, when in fact those black frames are skipped.
Maybe they're considered "empty" or something?


Title: Re: problems with ogv video
Post by: Crimson Wizard on Mon 14/10/2024 00:33:57
@Rik_Vargard could you please make a video that contains only black frames, and then a single non-black frame in the end?
(or a single frame at start, then black frames, and single frame at end)
With such video it will be much easier to investigate what the video decoder is doing.
Title: Re: problems with ogv video
Post by: kursh on Mon 14/10/2024 07:43:50
The thing is that my video has only few black frames (less than a second) at the start.. but sound goes about 2 o 3 seconds later. i hope you can detect whats really happening! :D
Title: Re: problems with ogv video
Post by: Rik_Vargard on Mon 14/10/2024 08:57:50
Quote from: Crimson Wizard on Mon 14/10/2024 00:33:57@Rik_Vargard could you please make a video that contains only black frames, and then a single non-black frame in the end?
(or a single frame at start, then black frames, and single frame at end)
With such video it will be much easier to investigate what the video decoder is doing.

I made a 2 seconds video with one colored frame at the beginning and one colored frame at the end.

>> https://www.mediafire.com/file/1wsrvrs6tyep3ce/AGStest04.mp4/file

I hope this is what you asked?
Title: Re: problems with ogv video
Post by: Crimson Wizard on Mon 14/10/2024 14:36:03
Quote from: Rik_Vargard on Mon 14/10/2024 08:57:50>> https://www.mediafire.com/file/1wsrvrs6tyep3ce/AGStest04.mp4/file

Please tell, how do you normally convert this to ogv? I'd like to use exact same method and settings, to be certain that i'm testing same situation.
Title: Re: problems with ogv video
Post by: kursh on Mon 14/10/2024 15:59:13
While we wait for Rik answer... i used VLC convert with Theora video codec and vorbis sound codec.

Title: Re: problems with ogv video
Post by: Rik_Vargard on Mon 14/10/2024 16:48:04
Ah yes, I sent you the MP4 file... here's the converted OGV >> https://www.mediafire.com/file/iav9sldg5g7q0ja/AGStest04.ogv/file

I use this website to convert the videos >> https://video.online-convert.com/convert-to-ogv
The only setting I fill in is the first; the bitrate, I set it at 20000 kbps

And this is the info about their compression >> https://www.theora.org/
Title: Re: problems with ogv video
Post by: Crimson Wizard on Thu 17/10/2024 09:05:46
I was only able to confirm the problem, and found an old mail-list entry about a very similar error in Theora decoding:
https://ffmpeg.org/pipermail/libav-user/2011-June/000212.html

From my understanding, it goes down into libogg (OGG reading library). It's not likely that anything in the engine code itself is causing this, but libogg skips certain data packets for some reason.
... OR our code that uses libogg does not react and handle specific result.

But I never used libogg library myself, so cannot tell yet.

I still have a backup variant of comparing with VLC code, but I will need more time to figure out how to read it and what to compare...
Title: Re: problems with ogv video
Post by: Rik_Vargard on Thu 17/10/2024 17:29:55
Quote from: Crimson Wizard on Thu 17/10/2024 09:05:46I was only able to confirm the problem, and found an old mail-list entry about a very similar error in Theora decoding:
https://ffmpeg.org/pipermail/libav-user/2011-June/000212.html

From my understanding, it goes down into libogg (OGG reading library). It's not likely that anything in the engine code itself is causing this, but libogg skips certain data packets for some reason.
... OR our code that uses libogg does not react and handle specific result.

But I never used libogg library myself, so cannot tell yet.

I still have a backup variant of comparing with VLC code, but I will need more time to figure out how to read it and what to compare...

Thank you for that report and for taking the time to look into this  (nod)

I guess that for now, we'll just have to avoid black frames  :)
Title: Re: problems with ogv video
Post by: kursh on Fri 18/10/2024 15:21:28
thanks you both for your time. Maybe its time to try some near "black" RGB(10,10,10) frames.. maybe it works.. maybe no.... :D
Title: Re: problems with ogv video
Post by: CrashPL on Fri 03/01/2025 19:04:10
Sorry to necrobump the topic, but we've just hit this particular "bug" while doing final versions of ZJ cutscenes... and also found a workaround that works.

It was especially baffling, as I clearly remember encoding OGV videos for Zniw Adventure, with everything working fine, yet today neither mine, nor my video editor's files seemed to play properly. Both were skipping all duplicate frames. Nothing worked - VLC export (with various settings), Shortcut on Mac, even using ffmpeg via cmd.

The solution? Use ffmpeg2theora instead.

The very same files that caused issues with plain ffmpeg worked absolutely fine on ffmpeg2theora, without any changes to videos themselves.
Title: Re: problems with ogv video
Post by: Rik_Vargard on Fri 03/01/2025 21:33:43

And then what do you use to convert your file to .OGV? And are there also settings you change?
Title: Re: problems with ogv video
Post by: CrashPL on Sat 04/01/2025 19:14:21
Quote from: Rik_Vargard on Fri 03/01/2025 21:33:43And then what do you use to convert your file to .OGV? And are there also settings you change?

Nothing actually, just converting the source *.mov/*.mp4 file to *.ogv via ffmpeg2theora. We only specify the highest quality and target FPS:

ffmpeg2theora -v 10 -F 24 /path/to/source/file.mov