Log in

View Full Version : MPEG2 in MKV


Pages : [1] 2

spyder
15th January 2004, 21:01
Well, after a long time and a lot of badgering by ChrisHJW and robUx4 to get it done, here is the first working alpha of mpeg2mkv. RIght now it is highly experimental. We may yet change the method for storing it so DO NOT use it for archiving or anything really important ;) I think we are doing it correctly but just to be on the safe side don't rely on it until it becomes beta :)

This version has been known to fail on large files rather often and sometimes on small ones. It has to do with the changing of timecodes in the middle of the file. I have been unable to fix this yet because it seems to be either a problem in the files themselves or in libavformat. either way I have decided to perform my own timestamping hopefully in the next version. It DOES NOT work on mpeg elementary streams yet, you will get a bunch of 0 timecode frames. It does however work with mpeg1, as a side effect of mpeg2 being an extension of 1, but it doesn't use the correct codec ID (V_MPEG1). The current version of this program uses an experimental media framework to perform the multiplexing and does not yet support muxing streams other than the mpeg2 video yet. Also, it doesn't yet set the aspect ratio in the MKV file though the files should play back in correct AR as it is stored in the video bitstream itself. Expect the next version to do this. This tool will eventually work on Linux, the only thing holding it back at the moment is that Milk(the media api) only has plugin handling code for windows. It is GPL and the source will be available from the VFRE CVS from corecodec within the next few days. I am currently cleaning the source up and will soon put Milk in it's own CVS too.

In order to play the files you need to replace(or install for the first time :) ) your MatroskaSplitter.ax with the one in this package. It maps the MPEG2 codec ID to the correct DShow media type etc. to allow playback with most mpeg2 decoders. Please let me know if you have problems with a particular decoder. MPEG1 will play out of it also. mpeg2mkv doesn't support muxing audio yet as I said above so you need the newest build of mkvmerge from http://www.bunkus.org/videotools/mkvtoolnix/win32/pre/ or if 0.8.2 has been released, http://www.bunkus.org/videotools/mkvtoolnix/ . The first link is to pre-builds and these aren't meant to be stable ;) But Mosu just added the feature to allow muxing these mpeg2 mkv's with audio yesterday. Every type I have tried has worked perfectly. Please tell me the results.

One last thing, you will probably see a bunch of "Dropping frame..." messages at the beginning of the muxing if you use a source that has been clipped out of another bitstream, ie a DVB broadcast or a cut out of a DVD/SVCD. This is due to the first GOP being open or broken. The frames which are lacking a reference are automatically dropped to close the first GOP. Becase of this, there's no easy way to sync the audio with the video except to manually try ;)

Here it is:

http://corecodec.org/project/showfiles.php?group_id=30&release_id=120

Spyder

PS: Mirror provided thanks to Insolit: http://moolabs.dcc.online.pt/atm/index.php?&direction=0&order=&directory=matroska

If you speak portuguese and like matroska, check out his site ;)

ChristianHJW
15th January 2004, 22:03
Finally :D ....

spyder
15th January 2004, 22:13
I forgot that the splitter is a debug version so you will need the DLLs in the system32_dlls.rar in order for it to even register. I put it on the release page with mpeg2mkv now.

KpeX
15th January 2004, 22:15
Thanks for that, Spyder.

The matroskasplitter.ax included with the package fails to regsvr32 on my box - error message is "LoadLibrary("matroskasplitter.ax")failed - The specified module could not be found."

The filesize seems a little off too - 804 kb for the included Splitter vs 320 kb for Gabest's last release.


Edit: Beat me to it, thanks :).

tiki4
15th January 2004, 22:47
First, thanks for something new to play with...

@KpeX: I think the splitter doesn't register because of missing debug dll's. This happened to me once. The filesize maybe off because Gabest usually compresses his stuff with UPX (at least MPC).

tiki4

Atamido
15th January 2004, 22:51
I just watched a music video with MPEG-2 for video and Vorbis for audio inside of MKV. How often do you see that?

spyder
15th January 2004, 22:54
The filesize is off because the DLLs are debug builds. Toff built them and he said he didn't know how to get the release ones to build.

robUx4
16th January 2004, 10:06
Originally posted by Pamel
I just watched a music video with MPEG-2 for video and Vorbis for audio inside of MKV. How often do you see that?

Not often... Yet :)

lazyn00b
17th January 2004, 01:37
Great news! I've been lurking in wait for MPEG2-in-MKV for a long time. My dream is to be able to store MPEG-2 (DVD or HD) and AC3 in Matroska for convenient viewing AND the easy ability to transcode to smaller files (MPEG-4 + AAC, VP6 + HE-AAC, etc) as needed - maybe using some super version of VirtualDubMod... all without dickering around with a lot of intermediary tools like DVD2AVI. Is such a scheme possible?

ChristianHJW
17th January 2004, 06:54
Originally posted by lazyn00b Great news! I've been lurking in wait for MPEG2-in-MKV for a long time. My dream is to be able to store MPEG-2 (DVD or HD) and AC3 in Matroska for convenient viewing AND the easy ability to transcode to smaller files (MPEG-4 + AAC, VP6 + HE-AAC, etc) as needed - maybe using some super version of VirtualDubMod... all without dickering around with a lot of intermediary tools like DVD2AVI. Is such a scheme possible? ... yes, i was bugging Cyrius already about that. He mentioed we could maybe use FFvFw to decode MPEG2 in VdubMod for editing/transcoding of MKV files with MPEG2, he will maybe look into this soon ....

spyder
18th January 2004, 03:39
One big plus is that it makes seeking very nice. Especially when the source file was b0rked in that respect. I love these music video in MPEG2 in MKV. :)

scrat
19th January 2004, 13:39
Hey!

I don't see much sense in muxing MPEG2 into matroska because MPEG4 makes smaller files and if I wanna have MPEG2 I burn a DVD for playback on a DVD-player.
If a DVD-player were able to play Matroska at the moment the muxing of MPEG2 into MKV would be great but in my opinion it's to early for MPEG2 in MKV and some other things would be more important (menus)...


greetings,
scrat

opsis81
19th January 2004, 17:35
I could capture MPEG-2 video with a reliable container.They I could remove the commercials very easily without using those awful MPEG Editors,demux the new streams and author my DVDs.
This makes a lot of sense for me...

Wilbert
19th January 2004, 22:41
Playback of my transport streams with a 2.0ch aac stream also sounds nice :D I guess hdtv mpeg2 streams are not supported yet?

ChristianHJW
20th January 2004, 03:11
Originally posted by Wilbert Playback of my transport streams with a 2.0ch aac stream also sounds nice :D I guess hdtv mpeg2 streams are not supported yet? ... i couldnt see why matroska should have a limit here, but maybe the existing MPEG2 decoders will have problems decoding HDTV ?

Originally posted by opsis81 I could capture MPEG-2 video with a reliable container.They I could remove the commercials very easily without using those awful MPEG Editors,demux the new streams and author my DVDs. This makes a lot of sense for me... ... YES !!! I was bugging TimJansen, the author of the XviD DirectShow encoder filter already about a realtime MPEG2 encoder filter based on FFMPEG, but he had to upgrade the XviD encoder to latest xvidcore.dll first ( done, will be uploaded as soon as i'm home from Asia ), and i dont knwo when he will have the time to do it.

Just imagine :

- capture with MPEG2 and FLAC into MKV ( to be able to invest all CPU in the video capture )
- edit the files in VirtualdubMod
- reencode into anything you like, using any video and audio codec
- convert the final MKV into a MPEG for DVD or SVCD burning

What you say :D ?

spyder
20th January 2004, 03:15
Well, I can't test with HDTV as i don't really have any samples. I did get one from a site recently but I haven't played with it yet. It's really likely that I am missing some headers or something with the current implementation.

PS: this only applies to HDTV. Other types of files should be muxed fine.

Wilbert
20th January 2004, 10:50
... i couldnt see why matroska should have a limit here, but maybe the existing MPEG2 decoders will have problems decoding HDTV ?
The problem is not the decoding of the video stream (although like Spyder says a normal mpeg2 decoder can't decode hdtv streams).

The problem is the splitting of video and the AAC stream (I think there is not dshow filter which can do that, although there exist programs which can: TSDemux and DVD2AVI_aac). Elecard has a dshow splitter for hdtv and AC3. I guess there are dshow decoders for AAC, but I'm not sure about that. That's why you can't play those files, at least not if you want to hear the audio :)

@spyder,

I will put a sample on my webpage this evening.

bill_baroud
20th January 2004, 14:11
mpeg2 + aac in matroska, with the matroska splitter, it should connect AAC to CoreAAC and the mpeg2 to a mpeg2 decoder, no :confused:

or i've missed something ?

opsis81
20th January 2004, 16:25
Just imagine :

- capture with MPEG2 and FLAC into MKV ( to be able to invest all CPU in the video capture )
- edit the files in VirtualdubMod
- reencode into anything you like, using any video and audio codec
- convert the final MKV into a MPEG for DVD or SVCD burning

What you say :D ?

ChristianHJW,this is :eek: :D :) :cool: :eek: :D .I think you understand what I mean!

Atamido
20th January 2004, 19:50
@bill_baroud: You are correct. I have no idea what Wilbert is talking about. There is no splitter that I can think of that decodes both MPEG-2 and any type of audio stream. All the streams in Matroska are split by the Matroska splitter and handled by individual DShow filters. (Hence the reason I could play MPEG-2 and Vorbis together.)

spyder
20th January 2004, 21:44
@Wilbert: do you mean you can't play the mkv files you made or did you not know this should work form mpeg transport streams too? :)

spyder
20th January 2004, 22:09
OK, I tested a little with the clip I found on the net. It was a TS but the TS doesn't work in mpeg2mkv. I used VLC to convert it to a PS and then it muxed. However, this file has strange timecodes. I am beginning to see that libavformat is broken in this respect and I will have to code a replacement for the timecoding :(. The good news is that the file played ;)

Wilbert
20th January 2004, 22:43
There is no splitter that I can think of that decodes both MPEG-2 and any type of audio stream. All the streams in Matroska are split by the Matroska splitter and handled by individual DShow filters.
I know ... Sorry, if I didn't make my self clear.

do you mean you can't play the mkv files you made
I didn't mean that, because I didn't try it. All I was asking is, is it possible to use hdtv transport streams instead of normal mpeg2 streams.

Then Spyder answered:

OK, I tested a little with the clip I found on the net. It was a TS but the TS doesn't work in mpeg2mkv. I used VLC to convert it to a PS and then it muxed.
Ok. Btw, what is VLC?

I will put some samples on my homepage later this evening.

After reading the first page I saw that audio muxing (contrary to what I assumed) is not supported yet, and you have to use mkvmerge. Sorry, that I didn't read it more carefully.

Atamido
21st January 2004, 08:09
Originally posted by Wilbert
Btw, what is VLC? VideoLAN Client (http://www.videolan.org/) Its a handy cross-platform video player that will stream across networks.

Saiya-Jin
21st January 2004, 20:42
Hmm, I was just wondering, maybe a feature could be included in a DVD ripping program such as DVD Decrypter, making possible for you to decrypt the DVD and save as .mkv instead of .vob, with all the audio, subtitles (can you attach a DVD subtitle in matroska, as they are?) and menus (in the future when menus is supported in matroska of course).

That would eliminate the need for demuxing the .ac3 tracks and making a .d2v project. And also it would be playable right of the bat (I know you can play .vob files, but playback seems a little weird at least in my system)

I'm not sure about the menus, does it have to be converted in order to be usable in matroska, or can you just put them there as they are?

Wilbert
21st January 2004, 22:17
Great program this VLC! It's able to play my ts+aac file :)

A small part of the ts file can be found here:

http://www.geocties.com/wilbertdijkhof/test.ts

I converted it to a ps file:

VLC -> streaming wizard ->

step 1: open the ts file
step 2: output methods: file -> incapsulated method (mpeg ps)
(I hope this is correct, but I wasn't sure.)
step 3: start streaming ...

I converted the ps file to a mkv file, but the playback stuttered.

ps, other hdtv files can be downloaded from this site:

http://206.159.116.24/public.htm

spyder
22nd January 2004, 05:33
I will try to work on fixing the muxer tomorrow so that it writes AR info and corrects timecodes. I just started back to school today so I fear I won't have much time for a little while.

Spyder

ChristianHJW
22nd January 2004, 15:10
Originally posted by Saiya-Jin Hmm, I was just wondering, maybe a feature could be included in a DVD ripping program such as DVD Decrypter, making possible for you to decrypt the DVD and save as .mkv instead of .vob, with all the audio, subtitles (can you attach a DVD subtitle in matroska, as they are?) and menus (in the future when menus is supported in matroska of course).
That would eliminate the need for demuxing the .ac3 tracks and making a .d2v project. And also it would be playable right of the bat (I know you can play .vob files, but playback seems a little weird at least in my system) ... :O :O !! Actually, thats a new, brilliant idea how MPEG2 in matroska could be used. the files could be directly opened in VirtualdubMod, no need to make a .d2v file anymore with DVD2AVI, so one complete step could be skipped, and at least one audio track ( i dont think VdubMod can handle more than audio for transcoding ) could be processed directly into MP3 ( not Vorbis though ), which could be quite nice in GKnot.
I'm not sure about the menus, does it have to be converted in order to be usable in matroska, or can you just put them there as they are? .. there is only a draft of our menue system so far, nothing usable yet, sorry ....

Saiya-Jin
23rd January 2004, 07:15
Originally posted by ChristianHJW
... :O :O !! Actually, thats a new, brilliant idea how MPEG2 in matroska could be used.

Well, thank you :D:D:D

.. there is only a draft of our menue system so far, nothing usable yet, sorry ....

Yea, kinda figured that. Oh well, nice to dream though ;)

E-Male
27th January 2004, 16:14
i can't register the splitter
it's the first time a .ax file doesn't work for me

spyder
27th January 2004, 18:33
Well, you need the debug dll's too, they are on the download page also.

E-Male
27th January 2004, 20:39
ok, my bad

tiki4
31st March 2004, 12:26
What's up? Quite some time now that no one posted in this thread. Are there any news?

tiki4

ChristianHJW
31st March 2004, 16:14
We are more or less waiting for S_O, who was in contact with spyder some time ago and told him he was working on a new, improved MPEG2 in MKV muxer .....

tiki4
31st March 2004, 16:26
Hm. Good news. You Matroska guys really have some plan of world domination :D

tiki4

S_O
31st March 2004, 18:42
We are more or less waiting for S_O, who was in contact with spyder some time ago and told him he was working on a new, improved MPEG2 in MKV muxer .....IŽm working on it, IŽll set up a corecodec project and release a new version in the next days/weeks, currently I have a lot of work to do because I have to author/set up the new homepage/server of my school (also I have no idea how to do that, which makes things even more difficult and time-consuming).

Lobuz
15th June 2004, 02:04
Any news on mpeg2(.ts) in Matroska? Would it be possible to immitate multifile dvd structure with 1080i ts mpeg2? Or would it require finished control tracks?

Reagdrs
Lobuz

ChristianHJW
15th June 2004, 22:14
Spyder quit working on that as S_O had told him he had been working on a really nice app to mux MPEG2 into MKV. S_O hasnt been to the channel since some time now, i will ask him about the status as soon as i get hold of him.

S_O
15th June 2004, 22:23
Spyder quit working on that as S_O had told him he had been working on a really nice app to mux MPEG2 into MKV. S_O hasnt been to the channel since some time now, i will ask him about the status as soon as i get hold of him.Sorry, I havenŽt continued work on it now, IŽm very busy at the moment, I have to code the new homepage of my school (with PHP+SQL!), also there are a lot of exams etc. Also my PC was broken (the Elkos on my mainboard broke and the guy from ebay needed several weeks to send me the board I bought) for over a month and I only had my very old 350MHz system. But I didnŽt forgot and IŽll continue the work when I find the time (probably in summer holidays).

spyder
21st August 2004, 22:27
I have attached a new version of mpeg2mkv. This is a complete rewrite from the last version I released which used libavformat to do the dirty work. It was really broken at the time. I wrote(or rather finished) my own MPEG video bitstream packetizer and this is the result. So far I'm quite pleased with it. I haven't found any files that gave it problems yet. It works on both MPEG-1 and MPEG-2. Please verify that the codec ID displayed by the program matches the format of your video because the detection of that could be wrong. The files are perfectly valid structure wise. They do lack proper cues but as the program can't process audio anyway, add the audio with mkvmerge and it will write proper cues.

The coolest feature is the fast seeking. Seeking in MPEG files tends to be slow, with Matroska it takes only milliseconds :) Please give your toughest tests. It only supports MPEG Video ES format right now so you have to demux the video stream usually. I will add PS and TS support as soon as I find the time. MPEG-1 decoding doesn't work with DirectShow based players ATM, however you can play them in VLC. If you have the latest Matroska Splitter for DShow you can play the MPEG-2 files as long as you have an MPEG2 decoder. So, have fun.

To use it, go to a command prompt and change to the directory where it is then execute "mpeg2mkv input.m2v output.mkv"

I plan to make a nice GUI for it once I have system streams supported and there's actually something to have in the GUI besides input and output file :).

PS: If you find the audio is not synced after you mux it as you normally would, this is probably due to your mpeg stream having an open first GOP. I close the first GOP which means I discard a couple of frames, usually 2 or 4. so try adjusting the delay of the audio accordingly. If you experience this problem let me know and I will help you or even add delay calculation into the app.

E-Male
23rd August 2004, 00:40
i tried alpha 0.2

i transmuxed a short svcd sample in 3 steps
-tmpgenc mpeg tools
-mpeg2mkv
-mmg

audio was in sync and it played in all my players that play matroska files

so far the good news, but i also got one problem:

changing the AR via the mkv-file doesn't work (it does with transmuxed avis)

i hope both the succes- and the bug-report help

spyder
23rd August 2004, 03:35
Yeah...I think the problem there is that the mpeg decoders respect the aspect ratio given in the mpeg stream first and you can't get it resized at the end of the graph. Perhaps it would work with ffdshow decoding the video but I think that's broken. I recommend setting the aspect ratio in both places for now.

E-Male
23rd August 2004, 06:38
ok i tested with an old svcd
demuxed, changed ar to anamorphic with restream, used your tool and then muxed with audio

works great in mpc and wmp

in winamp the ar is wrong, like it just uses the 480x576 resolution

it seems these files are sensitive to which mpeg2 decoder(s) are installed on the system (somehow that was to be expected i gues)

all in all: great job!!

spyder
23rd August 2004, 21:50
I will add support for aut setting the mkv aspect ratio info from the mpeg's settings. Also, it may be possible to modify the stream as it's muxed to change the aspect ratio so you have less to do during creation.

PS: My next plan is to work on better MKV output code so that I can create complete mkv files with cues and everything. Then I will add PS and TS support.

E-Male
23rd August 2004, 22:14
>>I will add support for aut setting the mkv aspect ratio info from the mpeg's settings.
-i thought more of the other way round

>>Also, it may be possible to modify the stream as it's muxed to change the aspect ratio so you have less to do during creation.
-ok, ignore last comment :cool:

>>PS: My next plan is to work on better MKV output code so that I can create complete mkv files with cues and everything. Then I will add PS and TS support.
-sounds great
do you think this can be integrated into mkvmerge/mmg when it's advanced and tested?

Mosu
23rd August 2004, 22:15
Originally posted by E-Male
do you think this can be integrated into mkvmerge/mmg when it's advanced and tested?

Yes.

E-Male
24th August 2004, 07:22
:)

spyder
25th August 2004, 01:14
OK, I made a couple of fixes to the app. Nothing worth incrementing the version with yet. This fixes a bug in the buffer that crashed me while debugging but not in real use. The most important change though is that this build should correctly set the default duration for frames in the MKV. This value is used to calculate framerate by some tools. The files made with an incorrect default duration are OK but they will show up strangely in informational tools(25fps will show as 25000000fps). Anyway, it still shows up wrong for 29.97fps content because I set the default duration to be 33ms which is correct for most of the frames in the MKV. From here I will try to focus on separating the code from my mini framework and adding PS support so Mosu or I can properly integrate it into mkvmerge(and with as little hassle as possible :)).

PS: Please DO NOT use MPEG-PS files(.mpg .vob) directly as input to this tool. It will not tell you it doesn't support them and copy all of the mpeg packs into the mkv. This is not a nince thing :) Also, remember for a couple of weeks this is kind of experimental. The files it makes should be fine. It will be more stable once it's part of mkvmerge which has much more refined code for writing mkv's.

E-Male
25th August 2004, 14:38
i wrote a little batch file that converts mpg files "directly" to mkv
http://e-rels.dyndns.org/downloads/mpg2mkv.bat

requirements:
mpgtx in c:\mpgtx (http://mpgtx.sourceforge.net)
mpeg2mkv in c:\mpeg2mkv (this thread)
mkvmerge in c:\mkvtoolnix (http://www.bunkus.org/videotools/mkvtoolnix/index.html#dlinst_win32)
twice the size of the input-file free on c:
(paths can be changed ofcourse)

installation:
just put the batch-file somewhere

how to:
run with mpg file as parameter or simply drop the mpg file on the batch file

notes:
uses c:\m2m_tmp for temp files
resulting file will have the same name as the input file plus the .mkv extension
atm only the first audio stream is kept

enjoy

GIR
26th August 2004, 05:20
Well things for MPEG2 in MKV sure are looking good :) I have successfully managed to mux an MPEG2 stream with mpeg2mkv and then remux the file using mkvtoolnix with one audio stream and one subtitle stream, plays great in MPC, my tests using MPEG1 were not so good though :( it is b0rked, resulting file crashes MPC completely, it would be good if this was working as well as MPEG2 as I have a few old MPEG1 videos with subtitles that I need in the one package.