Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.


Go Back   Doom9's Forum > (HD) DVD, Blu-ray & (S)VCD > (HD) DVD & Blu-ray authoring

Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 4th May 2009, 09:42   #1  |  Link
Registered User
clark15b's Avatar
Join Date: Apr 2009
Location: Moscow, Russia
Posts: 61
Another AVCHD/Blu-Ray demuxer

I'm proud to present my own M2TS files demuxer taken from AVCHD camera and Blu-ray disks. Utility have a number of advantages and features when you working with AVCHD materials.

There is a major issue: joining multiple scenes located in different M2TS (MTS)/TS files into one file with audio/vidio sync (optional).

After brief topic examination it came to me that such thing can be done by eac3to, tsMuxer or simple 'copy /b' command in Windows and 'cat' in *nix-es, just addition one file in the end of another.

But in practice this is not good idea. The question is each M2TS file audio and video may be varied by length. This is urgent for the NTSC with fractional FPS, for example 29.97. Audio length (AC3 fps) and video frames (H264 JVT NAL) could not be variable, consequently there is no way to combine they at the end of the TS stream. Easiest way is to adjust video to audio, in this case variable fps is needed. In result we have audio stream 1 msec longer then video. It is not hard to calculate that for the 100 scenes we will get tremendous audio delay for 100 msec at the end.

When playing M2TS files one after one player begins from start and there are no visible synchronization issues. But when we join files, extracting elementary streams and muxing to MKV we are dropping information for synchronization completely. Muxer (mkvmerge) have no idea about initial TS stream properties and therefore sets its own time marks, supposing video and audio synchronized (I would remind you h.264 stream doesn't contain any metadata about FPS and so on).

Here the program features:

* runs either by Windows, Linux and FreeBSD;
* completely opensource , GPLv2;
* understands M2TS and TS file formats (type detetection by magic sequence);
* batch processing;
* joining multiple scenes;
* demux to ES or PES streams;
* extensions for the output files would be set depending of elementary stream;
* takes files list and/or directories list as command line argument (it is possible to specify a path to files for example private/avchd/bdmv/stream, program will take all appropriate files by itself);
* extracts shooting date and time of the each clip from mpls files in camera (private/avchd/bdmv/playlist/*.mpl);
* extracts elementary streams all programs in TS container or selected by number;
* makes files with time codes for appropriate elementary streams synchronizationl (mkvmerge timecode format v2);
* determining h.264 and AC3 elementary stream FPS;
* determining audio delay after video in each file and brings appropriate corrections into time codes (urgent for Blu-ray, you not needed to calculate and specify delay by yourself when muxing into MKV);
* trying to align elementary streams endings inside each scene;
* produces file with scenes for saving information about initial material dividing into multiple M2TS files. Scene names gives after file names or shooting time/date from the playlist (mkvmerge xml format);
* produces SRT file with subtitles for saving information about shooting time/date from the playlist;
* shows invoking mkvmerge command for muxing produced material into MKV;
* support MPEG2 Video, MPEG2 Audio, H.264, VC-1, AC3, L-PCM elementary stream types;
* parses and shows information about TS stream without elementary streams extraction (shows streams types. length, offset, and fps);
* dump TS structure (M2TS timecodes, PTS/DTS ...).

Unfortunately there is only console version available yet. It was tested against AVCHD cameras by Sony, Canon, Panasonic, some Blu-ray disks and broadcast TS.

Competitors disadvantages:
* xport - Unable to join files and can't take TS from the standard input. Output file names not reflecting content type;
* eac3to - No source code available, only Windows;
* tsMuxer - Also no source code, not so useful console version, joining files in GUI version is not comfortable.

And no one of them able to form files for proper streams synchronization for mkvmerge, no ability to generate file with scenes list, and no shooting time/date extraction.

I suppose my program may be an alternative to xport.

GUI Windows setup (win32): http://tsdemuxer.googlecode.com/file...uxer_setup.exe
Windows binaries (win32): http://tsdemuxer.googlecode.com/files/tsdemux.zip
Linux binaries (gcc4, static): http://tsdemuxer.googlecode.com/files/tsdemux.tar.gz
Sources: http://code.google.com/p/tsdemuxer/source/browse
Project home page: http://code.google.com/p/tsdemuxer

Simple invocation form: 'tsdemux.exe -m -j -d x:\private\avchd\bdmv\stream' or 'tsdemux.exe -j 00001.mts 00002.mts'. Result will be in five files in current directory: video stream , audio stream, tmc-file for audio, tmc-file for video, xml-file with scenes. Then you should pass all of these to mkvmerge.

Command line options:
tsdemux.exe [-d src] [-l mpls] [-o dst] [-c channel] [-u] [-j] [-m] [-z] [-p] [-e mode] [-v] *.ts|*.m2ts ...

-d discard all TS/M2TS/MTS files from specified directory (use it multiple times for different directories, files will be sorted ascending). For the AVCHD/Blu-ray it should be 'private/avchd/bdmv/stream'.
-l path to AVCHD/Blu-ray playlist mpl/mpls file (usually it is 'private/avchd/bdmv/playlist/*.mpls'). If this option set then for the names of scenes shooting time/date will be used also.
-o redirect output to another directory
-c channel number in TS stream (if not specified then all streams from all programs will be extracted, but scene file for mkvmerge will not generated).
-u demux unknown streams
-j join elementary streams
-m shows mkvmerge invoking options for muxing results in MKV.
-z demux to PES streams (instead of elementary streams).
-p deny elementary streams extraction, only analyze with information output.
-e dump TS structure to STDOUT (mode=1: dump M2TS timecodes, mode=2: dump PTS/DTS, mode=3: human readable PTS/DTS dump)
-v turn on verbose output

Valid files extensions: m2ts, mts, ts.
Output files could be with extensions: sup, m2v, 264, vc1, ac3, m2a, pcm. Files with time codes for each elementary stream for mkvmerge (tmc) and mkvmerge scene file (chapter.xml) will be generated as well.

Send bugreports to comments, please

Last edited by clark15b; 28th August 2009 at 13:12. Reason: version 1.52
clark15b is offline   Reply With Quote

avchd, blu-ray, mux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 23:30.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.