# Converting VFR FLV (H264/AAC) to AVI (other) w/o sync issue

1. Hi everyone,

Really hoping you can help--I've been trying to get the audio and video to sync on this FLV file (after conversion) since 2/15 (working pretty much every day on it for several hours each day.* Finally I have admitted defeat and am turning to the exports!!

A little background:** This variable bit rate(?) H264/AAC FLV video is from a time of ministry when my friend (who I do the media for in my spare time) was in Brazil in 2011.* Mediainfo reports that it's 27.970 FPS (but also VBR) and 48000 audio.** The FLV file which I'm trying to convert to avi (or whatever format you suggest) constantly freezes itself to stay in sync with the audio but after converting all bets are off.

I've read numerous articles on Videohelp among other site to deal with the issue.* I believe this file is VBR because MediaInfo says "Frame rate mode:* Variable" but I know it can be wrong sometimes.** If indeed this is VBR, please let me know that as well.

What I have tried:

Converting the file with Avidemux, FormatFactory, SUPER, VirtualDub, VirtualDubMod, YAMB and AVS
Virtualdub (directly to FLV) using DirectShow Filter with ffdshow and the FLV splitter installed and registered via regsvr32
Virtualdub (using a converted AVI) with interleaving to make up for the audio (its not a constant change so this fails)
Virtualdub (using a converted AVI) with "change so video and audio durations match"
flvextract to raw .h264 and .aac and running:* mp4box.exe -add "filename.264:fps=29.970" -add "filename.aac" "filename_output.mp4"
Guessing at random values within the 27 to 30fps range for the outputted AVI and trying to sync up manually (for hours)
Resampling the audio from 48000 to 44100 in Goldwave
Opening the FLV as well as the AVI directly in Avidemux
The nightly builds for Avidemux because I heard they support VBR (but I don't know what settings to try really -- I made some guesses)
AVISynth using scripts for ConvertFPS, ChangeFPS, and AssumeFPS (but I wasn't able to specify "29.970" -- only 29 or 30)
A few other things I don't remember at the moment.

I've done my homework I believe and I am still stumped -- I AM THANKFUL FOR THESE FORUMS SO MUCH.* AND THANK YOU TO ANYONE WHO CAN HELP WITH THIS.** I need to have this sync'd up (if such a thing is possible) and preferably in an AVI so I can do some very simple fades and cuts in VirtualDub.** <b>* I don't mind converting this to CBR one bit </b>.** Thank you very very much to anyone who can help or tries to -- we are aiming to put this media out publically on March 1st.

*

http://www.kurt.dvian.net/webapps/video/ESC2011-Sat.flv

*

<b>MediaInfo

Reports the following</b>:

*
General
Complete name : C:\Users\Kurt\Desktop\ESC2011_Sat.flv
Format : Flash Video
File size : 426 MiB
Duration : 2h 18mn
Overall bit rate : 430 Kbps
_audiochannels : 2.000
_audiocodecid : mp4a
_audiodatarate : 128.000
_audiosamplerate : 48000.000
_duration : 8305.470
_framerate : 29.970
_height : 360.000
_lsChannelName : puentelargotv
_videocodecid : avc1
_videodatarate : 350.000
_videokeyframe_frequency : 240.000
_width : 640.000

Video
Format : AVC
Format profile : Main@L3.0
Format settings, CABAC : No
Format settings, ReFrames : 2 frames
Format settings, GOP : M=1, N=120
Codec ID : 7
Duration : 2h 18mn
Width : 640 pixels
Height : 360 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Color primaries : BT.601-6 525, BT.1358 525, BT.1700 NTSC, SMPTE 170M
Transfer characteristics : BT.709-5, BT.1361
Matrix coefficients : BT.601-6 525, BT.1358 525, BT.1700 NTSC, SMPTE 170M

Audio
Format : AAC
Format profile : LC
Codec ID : 10
Duration : 2h 18mn
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Compression mode : Lossy
Delay relative to video : 420ms

<b> Thank you so very much in advance! </b>

2. The FLV file which I'm trying to convert to avi (or whatever format you suggest) constantly freezes itself to stay in sync with the audio but after converting all bets are off.
Likely VFR is causing the problems, not VBR

Why do you need AVI container? AVI container doesn't support VFR

You said you've tried convertfps , but did you try: DirectShowSource("video.flv", fps=29.97, convertfps=true) , because that's the only semi-reliable way to convert it to pseudo-CFR

If what you describe is correct, the only way to keep it in sync would be to screen capture it in CFR recording mode, while it's playing (including the repeat frames). A true VFR file usually doesn't have encoded repeat frames, it's the VFR timecodes that tells the media player to speedup & slowdown display of frames. So a single frame might be displayed for a second in a VFR file, but for a CFR file, that same frame would actually be encoded as 30 frames. That's why it's out of sync when you use AVI - you don't have the corresponding timecodes, and don't encode the proper number of frames for CFR (you will be missing frames). You might try something like camtasia , camstudio or fraps to screen capture it
3. Yes, Sorry. I did mean VFR as opposed to VBR.

I did try this (see quoted line below) poisondeathray and I could save out but once imported into VirtualDub, it will not play--I can only save it out. Is this normal or am I missing a pluton/codec/library?

"DirectShowSource("video.flv", fps=29.97, convertfps=true)"

I AM TOTALLY FINE ENCODING TO SOMETHING OTHER THAN AVI IF THE AUDIO AND VIDEO IS SYNYED

Is there really no way to encode direct without using screen capture software?

Thank you very much!

4. I AM TOTALLY FINE ENCODING TO SOMETHING OTHER THAN AVI IF THE AUDIO AND VIDEO IS SYNYED
Why are you encoding it at all then? Why not leave it as flv ? I'm assuming it's in sync to begin with?

e.g You can try demux with flv extract and re-wrap with mkvmerge into mkv with TIMECODES. There is no re-encoding if you do that

I did try this (see quoted line below) poisondeathray and I could save out but once imported into VirtualDub, it will not play--I can only save it out. Is this normal or am I missing a pluton/codec/library?
I don't understand ? Does that .avs script open in vdub? is it in sync in vdub before saving out? Isn't the whole goal to save something out ?

EDIT: I see, you need "AVI" because you need to edit and insert fades in vdub. Well vdub cannot handle VFR video. AVI is CFR only, so your only option is to convert it to CFR before editing in vdub
5. Yes of course you cans save it. Create the Avisynth script as mentioned above (directshowsource ...)
and open the script with Virtualdub. Set the video and audio compression and save as AVI.

I have had good luck with ffvideosource using fpsnum and fpsden to set the returned frame rate
Here's an example:

Video = FFVideoSource("I:\SUMMER_WARS.mkv", track=-1, seekmode=0,fpsnum=30000,fpsden=1001)
6. EDIT: I'm plenty fine converting to CFR**. so long as it's in sync.

See my original post. The FLV skips and temporarily delays the video so that the audio can stay in sync. You can download the original FLV in my initial post to see this behavior.

Once the AVS script is successfully loaded and I can see a still image of the video, and I press play, the video does not play. but I can save out (still out of sync).

Hope this clears things up.

So, FLV to MKV could potentially work?
7. Dave,

I will absolutely try fpsnum--I haven't tried that yet! I can't wait to get home!

I assume it works with FLV? Thanks!
8. So, I tried using ConvertFPS and now I'm reminded of why it didn't work: the resulting outfile file has no audio.

and once again, I cannot play the video in virtualdub after it's been (successfully) imported.

What codecbam I missing? I'll try the fpsnum script in about 20m when I get home!!
9. Originally Posted by MediaInfo
Audio
Format : AAC
You need an AAC ACM decoder. Keep in mind that VirtualDub uses the older ACM audio, and VFW video systems. These are separate from DirectShow which most modern media players use.
10. Originally Posted by jagabo
Originally Posted by MediaInfo
Audio
Format : AAC
You need an AAC ACM decoder. Keep in mind that VirtualDub uses the older ACM audio, and VFW video systems. These are separate from DirectShow which most modern media players use.

Actually if he's using DirectShowSource in an avs script, he needs a directshow FLV splitter and directshow aac decoder (e.g. ffdshow or lav)

FFVideoSource won't get you audio either; you need FFVideoSource + FFAudioSource with audiodub
11. EDIT: I am home now available via gmail chat or others as well as remote access. Any takers?

Remember that the video doesnt play in VirtualDub once loaded via avs but I can save out (with no audio so it's pointless). So two glaring issues -- one, no video playing in virtualdub **but it loads "successfully" and shows the first frame of the video -- and no audio in or out of virtualdub.

Gentlemen, we have a problem.

I already have a directshow flv splitter (first the one on this site and then I unreg'd that and tried Gabest--neither worked) and ffdshow installed.

I also have an AAC ACM decoder installed but no dice.

I'm certainly willing to try this:

FFVideoSource won't get you audio either; you need FFVideoSource + FFAudioSource with audiodub
Can you provide example code for it?

Thank you VERY much. I am hopeful again...
12. Originally Posted by poisondeathray
Actually if he's using DirectShowSource in an avs script, he needs a directshow FLV splitter and directshow aac decoder (e.g. ffdshow or lav)
Sorry, missed the part about using the DirectShow source filter. I thought he was using the FLV source filter.

kwondra34, By the way, did you specify the DirectShow source filter when you opened the file? If not VirtualDub may have used a different source filter.
13. Originally Posted by kwondra34

FFVideoSource won't get you audio either; you need FFVideoSource + FFAudioSource with audiodub
Can you provide example code for it?
Code:
aud = FFAudioSource("video.flv")
vid = FFVideoSource("video.flv", fpsnum=30000, fpsden=1001)
audiodub(vid, aud)
It's not included with avisynth standard install

I already have a directshow flv splitter (first the one on this site and then I unreg'd that and tried Gabest--neither worked) and ffdshow installed.

I also have an AAC ACM decoder installed but no dice.
If you are using x64, you need x64 versions of codecs, splitters, vdub etc...

If you are using x86, you need x86 etc.. etc...
14. Digging into this now poison. Thank you for your continued assistance. I'll report back shortly.

And yep, everything is the same architecture so that still stumps me.
15. Alright, so a few things.

I am running all x64 of everything. I am able to create the following script and open it in Virtualdub:

aud = FFAudioSource("c:\edit\saturday.flv")
vid = FFVideoSource("c:\edit\saturday.flv", fpsnum=29970, fpsden=1001)
audiodub(vid, aud)
It opens in VirtualDub just fine however when I press Play I immediately get the following: (see attached)
The same message shows up immediately when I try to save out.

Can't say thank you enough -- this is very very important to me.
16. Switch to 32 bit versions of everything. There's no benefit to running 64 bit VirtualDub (it's not any faster) and it comes with a lot of drawbacks. Fewer filters available, more bugs, etc.

By the way, your numerator and denominator values are wrong. They should be 30000 and 1001. Or 29970 and 1000.
17. Jagabo,

Thanks for the quick response!

Before the *last* post when poisondeathray mentioned make sure everything is 32 bit or everything is 64 bit, I was using ENTIRELY 32 BIT.

I just moved over to 64 bit to see if it would work but it's the same result. I adjusted the num/denom and still receiving the same error message.

Willing to try whatever and allow anyone to remote in and have a look if needed -- or the file is still linked in my original post if you wanna have a direct stab at it. I will try anything.
18. Try deleting the index file that ffmpeg made, then open the AVS script in VirtualDub again (so a new index is created). Make sure ffAudioSource() is called before ffVideoSource(). If that still doesn't work, delete the index file again, and try just ffVideoSource().
19. If FLV is causing problems,
I would try AVIdemux to put the video into an MKV or MP4 container, then retry the script with that.
20. EDIT: Would one of you be willing to download the original flv (from my site here: http://www.kurt.dvian.net/webapps/video/ESC2011-Sat.flv) and see if you receive the same error message? Then we can rule out client-side issues or missing codecs, filters, etc. Thanks so much regardless!

Here's the code I'm using -- I deleted the index files.

aud = FFAudioSource("c:\edit\saturday.flv")
vid = FFVideoSource("c:\edit\saturday.flv", fpsnum=30000, fpsden=1001)
audiodub(vid, aud)
I also tried:

aud = FFAudioSource("c:\edit\saturday.flv")
vid = FFVideoSource("c:\edit\saturday.flv", fpsnum=30000, fpsden=1001)
audiodub(aud, vid)
Same message.

davexnet, if I convert to mkv/mp4 with AVIdemux, the audio is out of sync still so I dont think I'll be able to bring it back into sync by opening it through the script afterwards -- but I'll try.

Lastly, Just using the following code also results in the error when I attempt to hit play in virtualdub:

FFVideoSource("c:\edit\saturday.flv", fpsnum=30000, fpsden=1001)

Thanks for your continued support. I am NOT giving up
21. Going back to DirectShowSource("video.flv", fps=29.97, convertfps=true), what did VirtualDub say about the audio and video? File -> File Information.

You could also use DirectShowSource(..., audio=false) just for the video. Demux the audio to a separate file and convert it (if necessary) with another program like Audacity.
22. I have downloaded the file, I'll let you know what I find.
23. Thank you again and again. Couple things more to report:

aud = FFAudioSource("c:\edit\saturday.mkv")
vid = FFVideoSource("c:\edit\saturday.mkv", fpsnum=29970, fpsden=1000)
audiodub(aud, vid)
WILL allow the video and audio to both play within VirtualDub -- notice that this is for the MKV file that was outputted. The audio is still out of sync of course or this would be a giant win.

Is it possible there is an FLV component that I need to have that I dont. I have ffdshow, and THIS flv splitter (1.0.0.5 which supports H264 and AAC).

Going back to DirectShowSource("video.flv", fps=29.97, convertfps=true), what did VirtualDub say about the audio and video? File -> File Information.
--
24. Wow dave, Thanks for your support!

25. A little update as well, with the 1.0.0.5 FLVSplitter installed and registered, I am able to use this code:

DirectShowSource("video.flv", fps=29.97, convertfps=true),

To open the video in virtualdub and save it out. I'm saving it out now with no audio since FFMPEGSource just isnt working for me personally on that FLV file. If indeed it successfully converts the frames and we have a pseudo-CBR avi file outputted, i will then take the audio from the original stream in goldwave and save bring it into virtualdub and try to save it out again...

I'm be blown away if it works but I am feeling like anything is possible with you guys...

Thanks for the 100th time.
26. I tried ffmpeg command line just as another option and the outputted file plays just like the original flv when played in FLV -- delays itself so the audio and video stay in sync (still skips).

ffmpeg.exe -i c:\edit\saturday.flv -vcodec copy -acodec copy -timecode c:\path\to\extracted\timecode.txt output.mkv

Code:
aud=ffAudioSource("ESC2011-Sat.flv")
vid=ffVideoSource("ESC2011-Sat.flv", fpsnum=30000, fpsden=1001)
AudioDub(vid,aud)

The audio is out of sync with the video but I haven't looked at it closely yet. But it looks like there is an initial delay of about 800 ms and the true frame rate is less than 29.97 fps.
28. Alright, as always please let me know when you know something.

If you open the file you downloaded, it actually plays perfectly in windows media player (at least on my system) however it will ultimrately end up on our youtube channel and youtube reflects exactly what VLC does. Once we get it to play smoothly and in sync in VLC, the problem and nightmare is over!

Thanks!
29. If you look at the timecodes from flv extract, it is too variable (changes too much, too frequently) . So it will go in/out of sync all over with any of the avisynth methods . convertfps method will only work on videos that are minimally variable

You will probably have to use the screen capture method
30. Stupid question: did you try converting with VLC itself?

Statistics