Log in

View Full Version : Doubled framerate video slightly faster than audio


gitch
2nd September 2012, 08:45
Hi all

I'm sure there's a better way to do what I am trying to do, but after spending a lot of time on trial and error, this has gotten me the closest to my end goal.

I have a whole bunch of mp4 videos that are recorded in 14fps, 320x240 and I'm wanting to make a DVD out of them. I have an avisynth script to resize them to 640x480 and double the frame rate, which looks something like this:

DirectShowSource("video.mp4").LanczosResize(640,480)
super = MSuper(pel=2)
backward_vec = MAnalyse(super, overlap=4, isb = true, search=3)
forward_vec = MAnalyse(super, overlap=4, isb = false, search=3)
MFlowFps(super, backward_vec, forward_vec, num=2*FramerateNumerator(last), \
den=FramerateDenominator(last))

The script works great when I play it using MPC, and of course there's audio played as well.

I am using ffmpeg to play the avs file and save the output, except the first thing I noticed was that there was no audio in the doubled frame rate output file. So to work around that, I strip the audio out of the original using vlc. Then, I run ffmpeg to double the frame rate:

ffmpeg -i avs2.avs -acodec libmp3lame -an -vcodec copy vid.avi

And finally, I combine the two (audio and video) together:

ffmpeg -i audio.wav -i vid.avi -acodec wmav2 -vcodec mpeg2video -qscale 3 vid2.avi

This gives me a pretty good match... to begin with. Except as the video goes on, the video creeps further and further ahead of the audio. By the end, on a 30 second video, it will have crept so far ahead that it needs a 4 second pause of the video in order to sync the audio, before playing the last few frames.

I wondered if it was to do with the fact that the source video is variable frame rate, so I added in a changeFPS(14) to fix the whole video at a constant rate. Still same effect - video gets ahead of the audio.

Ideally, I'd like to be able to do the frame rate conversion without having to strip the audio using vlc and merge the two together, but I'd settle for any method that just gives me a finished product that looks as good as something played in MPC.

Thanks
Gitch

gitch
7th September 2012, 09:51
Due to the overwhelming amount of interest this post has generated, I thought I'd share the solution.

The original video was variable frame rate, so what I needed to do was fix the frame rate before doubling. The frame rate is either 15 fps or 7.5fps during some brief moments.

DirectShowSource("video.mp4", fps=15, convertfps=true).LanczosResize(640,480)

Guest
7th September 2012, 13:47
Then you misled us by saying "The script works great when I play it using MPC".

gitch
7th September 2012, 22:04
The audio never went out of sync when I used MPC and it rendered the extra frames in real time.

Guest
7th September 2012, 23:20
When you played the script??? How could that be?

gitch
8th September 2012, 02:56
When I played the video whilst using an almost identical script in the Avisynth dialog under ffdshow video decoder configuration. The only difference was in the opening line (which obviously doesn't specify a filename in ffdshow).

Guest
8th September 2012, 04:42
So you misled us?