ps3m2ts

I’ve used mkv2vob sometimes to convert my .mkv files to either a .vob or .m2ts file that my Playstation 3 console can play. Why? I’ve hooked it up to our big screen (well actually a projector) and surround system in my loft and so I thought it would be easier if I could watch all my media on the PS3 instead of switching between that and a PC. That may sound lazy but I really do enjoy the XMB interface and using the controller to navigate through folders etc. It just feels right.

The only problem with mkv2vob is that I have to manually add the files/folders I want to convert and I’m a guy that enjoys when things can run automatically. Mkv2vob does not have a command-line interface which makes running it from within a script or another application really difficult. So I began searching through the forums only to discover that it’s a feature request and intended for later; also the source code for the application isn’t available at this time.

I’m a software developer, self-taught in C# and other programming/scripting languages so I thought I might give it a try to write a command-line application that can do what mkv2vob can — so I can implement it in future projects for automating the process of converting media files. I attempted to write something similar maybe a year before but I never got anywhere because I didn’t know how I would fix the .h264 streams to work with the PS3. Back then you could and you still can use a tool called h264info that you could input the .h264 file and specify fps etc and it would add the necessary parts to the h264 file so the PS3 can read it. It would allow you to change the H.264 profile (PS3 won’t handle H.264 level 5.1 properly). I encountered the same problem, there was no command-line interface for h264info and I was unaware of any other methods at the time so I gave up after trying to rewrite h264info in C#.

This time around things are different. Thanks to a great tool made by SmartLabs called tsmuxer I can now do all of the necessary things to make a .mkv work on PS3. tsmuxer can demux .mkv and provide the same functionality as h264info in regards of fixing the .h264 parts and mux it back together as a .m2ts file which can be read and played back by the PS3. This made my work much easier.

I made a tool I call ps3m2ts (orginally ps3video but it might have been confusing with PS3 Video 9 etc). The tools used are actually the same tools found in mk2vob except that I don’t use mencoder or the dts applications provided with mkv2vob (yet). That’s the only minor setback with my tool as of now. If the media file contains a DTS stream it converts it to AC3 so you’ll know it will work. I haven’t figured out the DTS thing that mkv2vob does yet, but then again I started developing this tool three days or go.

Tools:

  • Mediainfo
    I use this tool to extract information from the .mkv file, what video streams and audio streams are available and what codecs they use, FPS and etc. This is most useful.
  • Tsmuxer
    As mentioned, this is the holy grail, the main tool used. If your .mkv contains a .h264 and AC3 audio this is the only tool used in the process of converting because it demuxes, fixes and mux the files back together all by itself.
  • eac3to
    This tool is used for converting the .dts audio stream to .ac3 so it can easily be played back on the PS3.
  • mkvextract
    A part of a set of tools, mkvtoolnix; this tool is used to extract the different tracks (files) contained in your .mkv file. This is only used when there’s a .dts audio stream because we need it to convert it to .ac3

If you want to create your own little tool for doing the same thing I did tsmuxer needs a META file to be created containing the information required so it can do it magic. The .meta file tells tsmuxer what options and what input files to be used. Here’s an example .meta for the movie Eurotrip:

MUXOPT –no-pcr-on-video-pid –new-audio-pes –vbr –split-size=4GB –vbv-len=500
V_MPEG4/ISO/AVC, “EuroTrip.2004.AC3D.720p.HDTV.x264.mkv”, fps=23.976, level=4.1, insertSEI, contSPS, ar=As source, track=1
A_AC3, “EuroTrip.2004.AC3D.720p.HDTV.x264.mkv”, track=2

The first line contains muxing options (I got these from the tsmuxer-GUI) except for the –split-size=4GB where you can specify if you want tsmuxer to split the file if you plan on copying it to a FAT32 drive where the max filesize is 4GB. So very useful. I don’t use the split options as I use a media server to stream it from my computer.

The next two lines specify the input files and the options. The format is as following:

<code name>, <file name>, <parameters>

The code name is the Codec ID we get from Mediainfo, in this case it’s AVC (H264), the file name and the parameters. A full listing of the different parameters and mux options you can go to this site and read up. The important ones to use when creating a .m2ts for playback on the PS3 is

insertSEI, contSPS
level=4.1Β  — If the level is higher than 4.1 use this so tsmuxer can change the profile level to 4.1 which is playable on the PS3

The other parameters you see like fps should be straight forward. We get this from Mediainfo and pass it a long so we hopefully won’t get wrong framerate and mess up the result. You also see track=ID parameter which is used if you don’t use external file but just want to use a track in the original .mkv. Save your file as something.meta and launch the tsmuxer

tsmuxer.exe something.meta output.m2ts

tsmuxer can output to m2ts, ts, Blu-Ray Disc or AVCHD folder.

This is a very long post, and I’m sorry you had to read until the end to get your hands on my tool but hopefully you have learned something (or not). Either way I give you the Binary and source versions. It’s written in C#, .NET version 3.0

Binary files: ps3m2ts-binary-v0.1.zip
Source code: ps3m2ts-source-v0.1.zip

To use the application

ps3m2ts.exe “file” [split]

Hopefully this application works for you, if it doesn’t give me a comment or send me an e-mail to me at henningms at gmail.com. If you’re a software developer hopefully you can improve upon the code and give me tips and ideas, it’s still a work in progress but all help is welcome. Join me!
Thanks for your time


  • Michael

    This is also a great tool for mkv conversion: ausmuxer. See more at http://forums.sabnzbd.org/index.php?topic=4500.0

  • Thanks man! πŸ™‚

  • James M

    wow spent the whole day trying to work with dvrmstoolbox to auto convert my mkv downloads.your tool does it in a fraction of the time. thanks bra. very nicely done

  • Glad it helped you! πŸ™‚ And that it still works!

  • ttfitz

    Like your tool – just like you, I was hoping to run mkv2vob in an automated method.

    One thing I can’t see – does your program take any options besides the name of the input file? I’d love to be able to send the output to a different drive/directory, for example.

    • Thanks! Been a while since I’ve used ps3m2ts or developed on it.

      There’s currently no option to do that, but if you’re interested I could take time to add that feature! πŸ™‚

  • ttfitz

    Oh, yes, an option to direct the output to a different location would be very useful to me. If you had the time, I would very much appreciate it.

  • whickwire

    ttfitz, you could always just run a script like I do πŸ™‚
    Just add a move command once the process is complete.

    @echo on
    SETLOCAL ENABLEDELAYEDEXPANSION

    set SOURCEPATH=C:UsersHOMEDesktopTV
    set TVERSITYPATH=C:ProgramDataTVersityMedia Server
    set PS3M2TSPATH=C:UsersHOMEDesktopTomps3m2ts

    cd %SOURCEPATH%
    IF EXIST *.mkv (
    GOTO MKVAVAIL
    ) ELSE (
    GOTO MKVNOTAVAIL
    )
    :MKVAVAIL
    cd %PS3M2TSPATH%
    FOR %%A in (“%SOURCEPATH%*.mkv”) DO (
    ps3m2ts.exe “%%A”
    )
    cd %SOURCEPATH%
    IF EXIST *.m2ts del *.mkv
    rename “*.m2ts” “*.m2t”
    :MKVNOTAVAIL
    cd %TVERSITYPATH%
    MShare.exe -R
    exit

  • ttfitz

    whickwire – this is true; however, much of the time I’m dealing with a drive that is rather full, so it can be difficult to use a script in this manner.

  • Nick

    Thanks for the good work!
    Did you ever sort out the DTS part of this app? Would be very handy! Also, is there an option to delete the source file one conversion completes without error?
    (either via switches or changing a default via XML)

  • Hi Nick and ttfitz,

    I’m sorry. I have’t been developing on this since this blog post but I will look into that soon! So check back sometime later for an update!

  • Stu

    Thanks a lot for this, it works a treat for me and this post was a really useful tutorial on what steps are involved!

    I’ve made a few tweaks to the source for my own benefit:
    1. Added support for converting a folder of files – mainly to make it compatible with the “Command Runner” plugin of Vuze so that I can convert files automatically as torrents finish.
    2. Logging to file – again so it can be run unattended and logs looked at later if there are problems.

    I’m happy to make further modifications for options like changing the destination, deleting the source file, unraring, etc. if you’ve not got the time to do so. Let me know. I could probably also fix the “DTS part” if someone explained to me what the issue is.

  • Hi Stu!

    Awesome work, would you be interested in sharing the code with us? I can then probably set up a Github repository and we can collaborate there so everybody can download the latest versions πŸ™‚

    I can’t exactly remember what the DTS issue was at this time, it’s been a long time since I developed this. I think it was a hack that tricked the PS3 to play the DTS track as DTS at that time only was available through specific formats (might have been AVCHD and discs playback). Or it might not.

    It’s been ages since I’ve last tried, so maybe the PS3 has become nicer and will allow pure dts tracks? We can try. I also made some modifications to ps3m2ts a while ago to include all audio tracks. So another feature request would be to set default language to use. In case there are several audio tracks (several languages) the user can specify what language to use so it only extracts the one track to minimize the size.

  • Stu

    Cool, I’m just emailing you πŸ™‚

  • Mike

    Nice tool, thanks alot! I’d also be interested if anybody has an automated script, the one above doesn’t work so well for me…

  • Hi Mike! Nice to hear that you enjoy the tool too.

    There will be an official release soon of version 0.2 with contributions by Stu that implements a lot of needed features. If you don’t want to wait I’ve already set up a repository where all changes we make will be available right away.

    So if you want to download the latest release just head over to https://github.com/henningms/ps3m2ts and download the zip. It’s the source-code but inside ps3m2ts directory there’s a binDebug folder that contains the latest compiled version with the tools.

    The version on github right now allows for converting a whole directory, deleting the source files after completed conversion, logging and specifying the output format.

    The other things I’ve planned for the official release of 0.2 is specifying the default language in case you have a file with many audio languages so that it only extracts the language you need to reduce file size.

  • Mike

    perfect additions, works like a charm! thanks again to you and Stu, exactly the features I needed

    it would cool if v0.3 came with subtitle support πŸ™‚

  • Mickey

    I’ve just stumbled upon this project (using the files within the debug folder of the github download) and I thought it was a fantastic solution for my automated media server setup until I went to stream the remuxed files to my Sony Home Theater system using PS3 Media Server, only to discover that they played back pixelated with a very poor quality.

    I think the compatibility issues my system has with that project is that the container of the output file is BDAV instead of mkv2vob’s MPEG-TS (The mkv2vob remuxed files I’ve manually converted play perfectly).

    It actually looks like someone implemented something similar into mkv2vob itself using that projects source code: http://www.mkv2vob.com/showthread.php?tid=15&pid=12455#pid12455
    but unfortunately all of the download links have expired and I’m at yet another dead end.

    Unfortunately I have no experience in any of the coding languages used in either project. If anyone knows of any other solutions for command line style remuxing of MKV’s I would be forever grateful.

  • Hi Mickey, sorry to hear that it didn’t quite work as intended for you.

    I can assure you though that the output format is supposed to be .m2ts (MPEG2 TS) if nothing else is specified.

    I am interested in finding out why it works poorly for you. The image quality shouldn’t be reduced or altered in any way as the tool uses the same video stream as in the .MKV file. The only alteration done is if the H264 stream has a higher profile than supported and so is changed to the highest supported profile for the PS3. It’s mostly done in the header of the file.

    Would you be interested in sending me an e-mail at henningms at gmail and figure this out?

  • Mickey

    When running some videos through the tool again in order to help with the diagnostic process, I decided to re-test the output file types with my system and though the m2ts files were in fact the default, my system (and MediaInfo GUI) claimed the streams were contained in a BDAV container, not the MPEG2-TS container that mkv2vob outputs.

    Inserting the format="ts" switch in the command, however, produced a .ts video file that MediaInfo GUI registered as having an MPEG2-TS container, and the files played back perfectly on my Sony BDV-370 home theater setup. (You may want to make this .ts format the default?)

    For consistency with the previous mkv2vob converted files, I included in my batch script a rename *.ts *.mpg function to change the file extensions. (I’m pretty sure mkv2vob uses a similar process, if you watch the files during the remuxing process) The final step was using theRenamer’s -fetch function to rename the TV and Movie files and sort them to into their final location (a very useful program).

    My home theater system is actually bad about playing DTS audio tracks so this tool’s current functionality is actually pretty perfect for my needs right now. I suppose subtitle support would be useful but I’ve only had one occasion where relevant subtitles weren’t actually hard-coded into the video.

    I guess all I have left to say is thank you for making my life easier.