July 24, 2006

The wonderful tale of VFR FLV1 to CFR AVI to 3GP

WARNING: Needlessly long tech ramble follows.

So, browsing Youtube, like you do, I come across Interpretation of Trivium
Now, I quite like Trivium, and even though the video disses them a bit, I still like it. “Boat, Rudder, Strange Mountain!”

Anyway. Saving it for posterity, it goes into an flv (Flash Video). VLC player can play these quite easily. “Magic”, I thought, “FFMpeg can convert this no problem”.

Unfortunately, I was wrong. For some strange reason, the video was randomly sped up in places. So, I found FFDShow, which can understand FLV1 files, and uses DirectShow. The files played fine in MPC, Media Player, VLC – but as soon as they were converted they messed up. Moyea Flash to Video converter worked fine, but there was a massive watermark over the picture, as it was a demo.

I installed AviSynth. This is where the fun began. AviSynth’s DirectShowSource filter was giving me the same output as my AVIs. “Strange”, I thought. Googling led me to my problem: VFR.
Variable Frame Rate. The AVI container format is quite happy working with CFR (Constant Frame Rate) but as soon as you start going variable, it messes up. “No matter!” thought I, reading the documentation for DirectShowSource. “ConvertFPS will solve it!”
Err.. No.
So, after more googling, this lead me to Graphedit, which is possibly the coolest bit of kit Microsoft has done. You can chain together DirectShow filters and output them anywhere.
Another google found a forum post recommending Matroska as a halfway house to AVI. So, I set up Graphedit – FLV->FFDShow Decoder->Xvid Encoder->AviMux->File Writer.
Success! The video played fine! This was because MKV is a clever little format that understands VFR.
Fuelled by this development, I frantically Googled for VFR MKV to CFR AVI solutions. The AviSynth page didn’t really help with this, but I found a tool called mkv2vfr. This would give me an AVI, and Timecodes of the frames. Using TVITC, I could create a proper AVI!
Except, mkv2vfr didn’t work. Disheartened, I instead looked at MKVtoolnix. MKVExtract has a function that gives out V2 Timecodes. mkv2vfr gives out V1 Timecodes, which are easier to work with. convert-timecodes.exe sorted this little hiccup up.
Another google found Timecode2AVS – A brilliant idea. Since V1 timecodes are in the format
frameX,frameY,framerateFromXtoY

you can convert every one of the lines in the file to the form
source.trim(X,Y).AssumeFPS(framerate).ChangeFPS(119.88)

The ChangeFPS is because it’s the LCM of 24 and 30. At the end of the file, you have to glue all the bits of files together, and then FDecimate(targetFramerate). In my case, I originally used 24. Having problems, I disregarded this method. Noticing later that my frames were around 30fps, I changed the setting from 23.976 to 29.97. It worked!

Now, all I had to do was set source to DirectShowSource(“Interpretation of Trivium.mkv”) and hope… Thankfully, it worked!
The last steps were academic really… VirtualDubMod can handle avs files, so I imported it and turned it into an XVid. The project that had me banging my head on the wall was complete! I’d turned a VFR FLV/MKV into a CFR AVI. The final step was to throw it at 3gp_Converter (which runs FFMpeg under the bonnet). Being CFR, it had no such problems this time.
Finally, I had my 3GP FLV :p Now I can take the best of YouTube to the pub with me.

In short:
1. Open FLV with Graphedit (with FFDShow installed and FLV1 activated)
2. XVidise the video and mux it with Matroska
3. Extract the V2 Timecodes
4. Convert the timecodes to avs, and edit the filenames, etc
5. Import the avs into VDubMod
6. Export as AVI
7. Import into 3GPConverter
8. Play your brand spanking new 3GP file!


- No comments Not publicly viewable


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Trackbacks

  1. I'll take languages you shouldn't write complex programs in for 100 please Alex...

    I almost forgot I was going to write this update, but meh. I wrote a script in PHP (that’s probably worth more if written in C, but unfortunately I don’t know how to write C) that negates the need for c...

    Shine on, you crazy Dymond - 23 Sep 2006, 20:11

July 2006

Mo Tu We Th Fr Sa Su
Jun |  Today  | Aug
               1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31                  

Tags

Galleries

Most recent comments

  • Two years have passed since I wrote comment 26. I haven’t se… by on this entry
  • WHATS EVEN FREAKIER KEN IS THAT YOUR BROTHER ALSO FOUND THIS PAGE!!... by Michael Dymond on this entry
  • It is indeed an awesome name! When people hear my name, they genera… by Ken Dymond on this entry
  • This is a good entry. by James Miles on this entry
  • I’ve always heard it as die–mond. by joe dymond on this entry

Blog archive

Loading…

Current Info




Not signed in
Sign in

Powered by BlogBuilder
© MMXII