mplayer2 for demuxing the audio, anything else that can demux video/audio streams also works
x264 for video
oggenc2 for audio
mkvtoolnix for muxing to Matroska container
assuming the source video has wav audio (if it has mp3 or some other lossy audio just skip to video encoding)
mplayer2 video.mpg -dumpaudio -dumpfile audio.wav
sometimes dumpaudio doesn't work as expected but decoding to wav works always
mplayer2 video.mpg -vc null -vo null -ao pcm:fast:file=audio.wav
encode audio to Vorbis at q5
oggenc2 -q5 audio.wav
encode video with x264 using crf mode
x264 video.mpg --preset slow --tune film --crf 20 -o video.264
use higher crf value if you want smaller filesize at lower quality
mux video and audio
mkvmerge video.264 audio.ogg -o video.mkv
if the source had mp3 or some other lossy audio then use the source audio for muxing
mkvmerge video.264 -D -S -B -T -M video.mpg -o video.mkv
-D = no video
-S = no subtitles
-B = no buttons
-T = no tags
-M = no attachments
MeGUI if you need GUI for the tools
also MeGUI guide at
and [url=http://mewiki.project357.com/wiki/]MeWiki