Synching video and audio [as SOLVED as possible]

Started by Rui 'Trovatore' Pires, Mon 23/05/2005 22:09:21

Previous topic - Next topic

Rui 'Trovatore' Pires

Ok, so I have this piece of video and this piece of audio. They're both the same length, and combining both in VirtualDub gives me a full movie.

But, when in AGS I try to do a, say,

PlaySoundEx(2,5);
PlayVideo("\data\\123.avi",3,11);Ã,  --> Audio muted

it STARTS in synch. But, as the movie progresses, the video must be playing FASTER or the sound SLOWER or both... because they get VERY out of synch. And it's gradual - you can SEE it happening. I need to do it this way because I need background midi files to be playing at the same time as most movies, and I also need to allow the player to control the volume - I can't do it to video files, so I just wanted to play them AND their audio at the same time as seperate things. So me and the player could have total control. BTW, the sound can be in OGG or WAV, it doesn't affect it, and the movie is DivX compressed.

Any idea why this happens? Can it be a mistake on my part? Or on AGS'? Cause I have to say it's pretty awkward - like I said, it STARTS in synch. But later on, gradually, it goes SO out of it it's painful.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

I presume the video is playing slightly faster than the sound. Quite frankly, I don't think there's much that can be done about this other than manually altering the frame rate of the video file.

Rui 'Trovatore' Pires

#2
Oh. There's no way to fix it, either? I mean, as far as behaviour goes, it's quite strange.

EDIT - On another note, I suppose altering the frame rate should be quite easy with a program such as VirtualDub and would mean no lack of quality, right? Sorry to know so little aobut these things... just tell me yay or neigh.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

I think when playing a video, the AGS engine passes all its control to DirectPlay (i.e. your system), so, in most cases, any phenomenon that can happen are mostly un-related to the engine, they mostly depend on:
1. Your system (configurations, drivers, etc.), in rare (well I think it's probably not that rare) cases it can be possible that other people's computers will act differently due to different settings, etc.
2. The media involved (movie files and voice clips say for example)
So, unless it's some rare engine bug, it won't help much changing anything in the engine.
Whether a movie clip can be edited to fit one's need is not an AGS technical question afterall. All I can suggest is, if you get hold of something that can do these modifications for you (like VirtualDub that you mentioned), just try it, and if it works, well..., it works.

Rui 'Trovatore' Pires

K, I'll try it out. The reason why I think it might be the engine is the fact that in VirtualDub synching both sound and wave gave positive results. If in AGS it didn't, after some further experimenting I assumed the problem way in the way AGS played back the video. And by that logic, it was something that could be fixed.

I'm honestly curious now - where did I go wrong in that line of reasoning?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

I don't know how VirtualDub previews a movie (in fact I don't even know what VD is), but a better approach is to drop that movie clip into media player and time its duration, it's probably more accurate if you check the movie clip using mplayer, as the played result should be identical to what you get using the AGS engine.
In case it's just caused by a slow delay in the sound clip while the movie clip was loading, try adding a split second pause at the beginning of the movie file and see if things can be improved.

Orieac

Try ffdshow program to replace divx decoder. If this doesn't work try to compress the video with another codec.

Sektor 13

or you can try to use Cool Edit 2.1 or newer, you can combine video and audio without any pain, and it works...(you can set in which format you want to save your audio file in movie too...as it is very important because of the lenght of the file..)

Ishmael

Quote from: Sektor 13 on Tue 24/05/2005 16:17:51
or you can try to use Cool Edit 2.1 or newer, you can combine video and audio without any pain, and it works...

Ahem...

Quote from: Rui "Brisby" Pires on Mon 23/05/2005 22:09:21
I need to do it this way because I need background midi files to be playing at the same time as most movies, and I also need to allow the player to control the volume - I can't do it to video files, so I just wanted to play them AND their audio at the same time as seperate things. So me and the player could have total control.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

hedgefield

#9
This is a known problem I think among dvd rips and such. I've heard of it before. Heck I've even had it once. There's a tut here detailling how to fix it with regular video files. It's in Dutch though.

In this case however, try ripping the WAV audio from the video under 'Streams > Stream List > Save Wav' in VirtualDub and play that instead of the track you have.

Rui 'Trovatore' Pires

I can't - VirtualDub says it can't find a decompresspor for the original file (it's encoded in DUK format). I'm using FFmpeg to extract the sound. WHen I combine them both in VirtualDub, it's a perfect match, it's on AGS that the synch goes off. Thanks for the tut, but I have not the least ouce of Dutch.

Gilbot, I didn't preview it with VirtualDub. What I'd meant was that if I played, in AGS, the same file in two ways, the first being a complete AVI with sound (largopredator - I did that by using VirtualDub's "Sound from source" option) and the second being the same avi and the same sound but played as separate though started at the same time (all this in AGS), the second one was out of synch - the first one wasn't.

Thankyall for your replies (even though I still fail to see why it happens at all - I guess that Dutch tut I'll never be able to read includes info on it). I'm experimenting with lowering the framerate. Experimentally, lowering from the original 15.000 to 14.000 proved to be too slow (hey, gimme a break, I'm new at this :) ), but 14.900 showed a definite, visible and radical difference. It still goes out of synch later, but careful trial and error should help me now.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

It's possible that AGS plays the video slightly faster or slower than media player, although this shouldn't be the case. The fact that the sound and video are correctly synced if you play an AVI with sound indiciates that the video is playing at the correct speed, so I'm not really sure what to suggest.

Rui 'Trovatore' Pires

Gah. Maybe the problem is with the sound. at any rate, more experimenting just showed me that it's not a "set" thing - if I pay close attention, I can, while watching it several times in a row, pick spots where the level of synch is extremely variable - at times almost spot on, at times VERY early (or late, depending on the frame rate I was experimenting with). It is even possible that the sound stutters minutely at random points and THAT causes it to be out of synch - in fact, the more I test, the more I get convinced of that. And that is probably due to my computer only...

So, thanks again and thanks anyway. I don't suppose there is a way to play the AVI audio AND keep the background music running? If that were possible, it would probably be the best... scratch that, the *only* workaround I see.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Pumaman

Unfortunately I haven't been able to make that work. Either AGS has to shut down its own sound system and allow DirectShow to play the sound, or AGS keeps its sound system running and doesn't use DirectShow's. I haven't had any luck making them both work together.

Rui 'Trovatore' Pires

Ah well. Thanks anyway. If anyone else can shed any light on this matter, be my guest - if not, this project's for the trashbin.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk