View Full Version : MPEG-2 VCM codec?
temporance
18th May 2003, 22:26
Has anyone ever coded a MPEG-2 VCM codec? In other words, is there a way of carrying MPEG-2 in an AVI file?
Technically there's no reason why this shouldn't be possible. It might be very useful: you could rip a DVD direct to an AVI file that could be read very fast Vdub (no frameserving).
edit: Also, it would be much easier to edit MPEG-2 material when in AVI file format, again, just using Vdub.
If no-one's done this yet, then I'll start up a project on sf.net to code VCM driver and DirectShow decoder for fourCC compression type "MPG2". Reckon it'll take about a month to get this off the ground - anyone wanna help?
Etymonix (http://www.etymonix.com) made a MPEG-2 VCM Codec some time ago.. it only stores I-Frames, though, so it's not really suitable for that.
Having a *real* MPEG-2 VCM Codec would be funny... not really useful, but funny at least ;)
Assault
18th May 2003, 22:50
Hmm...I'm not sure but can't ffvfw do that? I remember that you can choose mpeg2 there and I think it will be saved as avi. Perhaps you'll find some information in the ffvfw thread (http://forum.doom9.org/showthread.php?s=&threadid=42710).
Assault
Atamido
19th May 2003, 08:36
You couldn't place the MPEG-2 frames from a DVD directly into AVI because of the B-frames. The only reason that B-frames work with DivX/XviD in AVI is because they use a nasty little hack. But there isn't any reason that you couldn't make an MPEG-2 VCM codec that could store/read MPEG-2 in AVI as long as it was only I/P-frames.
Really, your time would probably be better spent creating a tool to move MPEG-2 streams directly into Matroska. Because it can handle all of the frame types natively, it should be a small matter to store it there. And once it is in Matroska, then it will be much easier for editing(once tools are fully developed).
temporance
19th May 2003, 08:51
Originally posted by Pamel
You couldn't place the MPEG-2 frames from a DVD directly into AVI because of the B-frames. The only reason that B-frames work with DivX/XviD in AVI is because they use a nasty little hack.I would use the same nasty little hack for MPEG-2 B-frames. Should work a treat - I don't know why no-one's done it before!
Atamido
19th May 2003, 09:25
The point with the B-Frames is that you couldn't store the DVD's MPEG-2 frames in AVI because you would be required to be able to store those B-Frames.
You could re-encode a stream (of whatever video type) to MPEG-2, using B-Frames, and store it in AVI using those same nasty hacks, but what would be the point? As soon as you use those hacks, it ceases to be a valid MPEG-2 stream. And if it isn't a real one, then what are you trying to do?
I know you might be thinking that if they could do it with MPEG-4, then you could do it. The problem is that when they store MPEG-4 with B-frames in AVI , it technically stops being a valid MPEG-4 stream. To be a valid MPEG-4 stream, the frames have to be handed to the codec in a certain way. But the way that the frames are stored means that they are handed to the decoder in a special way, a non-compliant way. Sure it is nice, and saves space, but it is still not a valid implementation. If it were, then any MPEG-4 compliant decoder could read the stream and decode it without problems.
If you want to store MPEG-2 from a DVD in a more convenient container for editing, store it in Matroska. If you want to create a VCM codec to encode to MPEG-2 in AVI, don't use B-frames. Keep the streams valid.
temporance
19th May 2003, 09:44
Hi Pamel,
No, I'm not talking about re-encoding, just repacketizing.
For example, with IPBBPBB (bitstream order) you would have:
[I] [PB] [B] [] [PB] [B] [] [PB] [B] []
where [] represents an AVI chunk.
I would write a simple DirectShow filter to translate from MPEG-2 demux output to a AVI-style stream with FourCC "MPG2".
IMO, the "hack" used by DivX to put B-frames in AVI does not break MPEG-4 compliancy. The MPEG-4 standard does not say how someone should put MPEG-4 video into an AVI container so DivX was free to design their own way. Compliant MPEG-4 ES can easily be extracted from a DivX AVI with B-frames. The reason it's not readible by any compliant decoder is that not every decoder understands how to do the extraction.
temp.
ChristianHJW
19th May 2003, 10:16
After all, its your choice what to do, but pls. consider the following :
When using AVI for MPEG2 you have to
1. The AVI DirectShow parser can not connect to MPEG2 DirectShow filters, because their output/input types are completely incompatible. So for playback on DirectShow, you either had to
- rewrite the AVI parser filter
- make a new MPEG2 DShow filter
2. MPEG2 is very often using non 1:1 Aspect Ratio's, like a pixel AR of 1:1.6 for SVCD, etc. . AVI can not handle this natively, so you had to make another hack storing the AR flag somewhere in the AVI subheaders
3. MPEG2 can be interlaced, again AVI cant hold this
4. If you would want to convert your MPEG2 video stream from the AVI into normal MPEG container, to make a SVCD or VCD, you would have to depack your packed bitstream, just like what we are trying to do with MPEG4 in AVI to make 'native' matroska MPEG4 video streams with correct frame order ( coding order ) and without dummy frames or the like. To do so you need the codec normally, or at least a special parser reading the stream headers and indicating where the frames are, just like what sysKin is coding for us now.
5. MPEG2, at least SVCD, allows VBR MP2 audio, and its more and more used for SVCD creation. I am not 100% sure here, but the trick that was used for VBR MP3 audio in AVI may fail for MP2.
When using matroska you can
- use the skeleton code that spyder has done already to mux any MPEG elementary stream into matroska, MPEG1 or MPEG2
- use normal frame order, and mark b-frames as such
- easily transmux the MPEG stream from matroska back into MPEG
- use Vorbis or AAC audio with your MPEG1/2, as well as MP2 VBR audio
- handle subtitles streams in the same file, be it image or text subs
- use the same DShow parser, we will gladly merge your MPEG2 codec ID mapping into our main code
- use interlacing
- edit the file in VdubMod, just like it were an AVI
Cant think or more reasons now, but you have to admit that deciding for AVI was more like a decision to NOT USE MATROSKA BY ALL MEANS ;) ....
temporance
19th May 2003, 10:47
To the matroska guys: I'm not interested in using your format right now - I want to play with seeing if the two established formats MPEG-2 and AVI will work togeter. Hopefully we can all learn from how I get on!
To answer your issues ChristianHJW:
1. I prefer a third option - make a DS filter that will go between AVI Splitter and existing MPEG-2 decoder filters.
2. Aspect ratio is an issue, just like it is when frameserving MPEG-2 video. AR info is not lost though, it's just harder to extract as it's embedded in the video stream.
3. AVI can hold interlace no problem. Look at DV in AVI if you don't believe me. The container and transport mechanisms shouldn't need to know about interlace - it's an issue for the decoder and renderer.
4. I see this as two processes: a. extracting compliant ES from the AVI container (needs to know about my format) and b. multiplexing the ES into MPEG-2 PS (needs to know about MPEG-2 only).
5. Not an issue - providing the chunking is done correctly, all MPEG-1/2 VBR audio can be put into AVI.
ChristianHJW
19th May 2003, 12:24
Originally posted by temporance To the matroska guys: I'm not interested in using your format right now
Thats exactly what i said above :) ... your answers sound like how to best find a reason not to have to use it, although all the ideas you are proposing above in the original post, like muxing MPEG2 into AVI for easier editing or to make frameserving into VdubMod easier are perfectly valid reasons IMHO, and would comply 1:1 with what we have in mind for matroska, and not only for MPEG1/2 but also for native MPEG4 ( from MP4 container, including AAC audio ). Editing MPEG files sucks bad time, because the MPEG container was never really made to be edited, so it was always in my mind to be able to transmux MPEG2 into matroska one day to edit it, and then remux for VCD/SVCD/DVD creation.
temporance, i am really sorry to understand you dont like our project at all, or you dont take it serious. You prefer to make a lot of work to get it done in old, outdated AVI, instead of going the much easier and sensible way with using matroska, thus supporting it also :( :( ....
I promise i stop pestering you now, and i wish you all the best with your project. If you ever should change your mind, you are more than welcome to join our team. We usually have a lot of fun coding our stuff, and its a very exciting phase we are in right now, motivating every member with the results the others achieve.
Best regards
Christian
Chris, Pamel, you can't stop it can't u? ;)
ChristianHJW
19th May 2003, 14:24
Originally posted by avih
Chris, Pamel, you can't stop it can't u? ;) ... you're right avih, i should really be old enough to know when i'm wasting my time, and stressing other people's nerves .... my sincere apologies for my misbehaviour ....
Atamido
19th May 2003, 19:20
I was suggesting Matroska as a better container to be able to handle the B-frames natively.
I have been interested in MPEG-2 in AVI for a long time though. But I still stand with my original stance that if the stream being read out of AVI is not fully MPEG-2 compliant, then it is not technically an MPEG-2 file. And if you use the same hack to store B-frames in AVI, then the stream won't be.
However, from a practical point, since your DS filter will likely be the only one that could connect to the MPEG-2 in AVI, it probably won't matter. I just wanted to make sure that you understood my point that it still wouldn't be a technicaly valid way to store the MPEG-2 with B-frames since a fully compliant stream is not returned.
Guys... you don't need packed bitstream to have working B-frames. Look at lavc and xvid. The only trouble is lag when you don't have closed GOP.
temporance
19th May 2003, 20:40
Originally posted by Pamel
But I still stand with my original stance that if the stream being read out of AVI is not fully MPEG-2 compliant, then it is not technically an MPEG-2 file.I will use {0x00} instead of the {0x7f} of DivX/xvid. I will use {0x00, 0x00} as the placeholder for the reference frame that is inserted after a sequence of B-frames. So, my stream will be 100% MPEG-2 syntax compliant.
I didn't want to offend anyone about matroska - I didn't go out of my way NOT to use it, just wanted to play with MPEG-2/AVI as it seems such an obvious thing to do and I wondered if anyone had done it before. I think that one of the reasons it won't work well is that almost all the GOPs are open GOPs giving me two choices:
1. I make only the first frame a keyframe (slow slow seeking)
2. I make all I-frames keyframes and accept corruption in the two B-frames after every I-frame when decoding in VfW.
Btw, Pamel, if you're such a stickler for compliance, bear in mind that, because it has no VBV buffer model checking, xvid cannot comply to any of the MPEG-4 profiles. And I'm sure I could find all sorts of other little examples of not-quite compliant code - perhaps matroska code isn't 100% compliant to the matroska specs either!!
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.