PDA

View Full Version : Muxing and Demuxing (tsmuxer or mkvtoolnix) - a lossless process?


fifteen
6th March 2009, 19:42
X264 1114 Skystrife’s patched build

Mkvtoolnix 2.5.2

Tsmuxer 1.8.20

I’m creating and authoring my own AVC content.

I’m using x264 to encode the video to a raw 264 stream and using ffmpeg to encode the audio to Micosoft PCM WAV file.
In both cases I’m using the GUIs for tsmuxer and mkvtoolnix at default settings.

I want to mux these streams so that I have a single playable a/v file but I also want to ensure that I can demux these streams and essentially retain the original streams losslessly.

Stream info:

.264 file: 207 MB (217,526,031 bytes)
Wav file: 39.9 MB (41,880,044 bytes)
Wav length: 00:03:38.125

What I’ve found so far:

1. Muxing with tsmuxer to TS or M2TS then demux with tsmuxer:

Resulting files:
.264 file: 207 MB (217,526,082 bytes)
Wav file: 39.9 MB (41,880,072 bytes)
Wav length: 00:03:38.125

2. Muxing with tsmuxer the demuxed streams to TS or M2TS then demux with tsmuxer:

Resulting files:
.264 file: 207 MB (217,526,082 bytes)
Wav file: 39.9 MB (41,881,028 bytes)
Wav length: 3mn 38s 130ms

Notice that tsmuxer muxing and demuxing twice caused the wav file to lengthen, but the video file stayed the same size.
What is going on?

3. Muxing with mkvtoolnix to MKV then demux with mkvtoolnix:

Resulting files:
.h264 file: 207 MB (217,494,112 bytes)
Wav file: 39.9 MB (41,880,044 bytes)
Wav length: 3mn 38s 130ms

4. Muxing with mkvtoolnix the demuxed streams to MKV then demux with mkvtoolnix:

Resulting files:
.h264 file: 207 MB (217,494,162 bytes)
Wav file: 39.9 MB (41,880,044 bytes)
Wav length: 3mn 38s 130ms

Notice that with mkvtoolnix, the WAV file stayed the same size, but the video file size increased and on subsequent muxing/demuxing it continues to increase (at least as far as I tried it).
What is going on?


What I want to know is,
Is there a muxing -> demuxing solution that can ensure that no matter how many times I mux/demux I won’t be destroying the streams?


:stupid:

Mosu
7th March 2009, 19:18
I want to mux these streams so that I have a single playable a/v file but I also want to ensure that I can demux these streams and essentially retain the original streams losslessly.

mkvtoolnix is not about lossless transformation of containers. I don't guarantee nor aim for the streams to be bit identical if you mux and demux with mkvtoolnix.

Stream info:

.264 file: 207 MB (217,526,031 bytes)

...

4. Muxing with mkvtoolnix the demuxed streams to MKV then demux with mkvtoolnix:

Resulting files:
.h264 file: 207 MB (217,494,162 bytes)
Wav file: 39.9 MB (41,880,044 bytes)
Wav length: 3mn 38s 130ms

Notice that with mkvtoolnix, the WAV file stayed the same size, but the video file size increased

I would say that it DEcreased, but maybe that's just me and my weird math. Anyway, I consider the stream growing a bit not really a problem as long as the extracted stream can be read again (e.g. with mkvmerge or mp4box or whatever).

fifteen
7th March 2009, 20:10
I would say that it DEcreased, but maybe that's just me and my weird math. Anyway, I consider the stream growing a bit not really a problem as long as the extracted stream can be read again (e.g. with mkvmerge or mp4box or whatever).

Yes, the size decreased from the original stream, upon initial demuxing.

What I was pointing out was once i've muxed/demuxed and repeated the process that the video files began increasing in size. In the example above, it was by 40 bytes each time. My thought was that at some point, does this adding become destructive in some way? tsmuxer definitely harms the audio file if you demux and remux in that way with ts/m2ts files.

I've tried the process again with mkvtoolnix with another set of files and the video stream consistently grew by 50 bytes each time. I diffed the files and I'm guessing the header (first line of the file) is growing each time by the same amount and in the same location: right before the encoder settings?? I uploaded 3 files to your ftp site if you want to take a look. My guess is that the same information is being added to the file each time. Is this normal behavior or is it adding stuff that doesn't need to be added?

Mosu
7th March 2009, 20:54
Ah yes. mkvextract always adds the headers during extraction even if the same headers are present in the first frame. That's probably nothing I'll change.

fifteen
7th March 2009, 21:27
Ah yes. mkvextract always adds the headers during extraction even if the same headers are present in the first frame. That's probably nothing I'll change.

Is it possible that this process can become destructive if the headers are continually added? I know this is an unrealistic situation - muxing/demuxing continually, i'm just curious at this stage.

Mosu
7th March 2009, 21:36
No, I strongly doubt it.

fifteen
7th March 2009, 23:12
One more question. Is it possible that another program might have trouble reading the mkv if it has multiple copies of this info?

Mosu
7th March 2009, 23:33
No, they're part of the bitstream. Also they're identical and therefore no problem.

neuron2
8th March 2009, 00:34
Correct. SPS's and PPS's are usually repeated throughout the bitstream anyway to allow for random access, so having a few extra copies at the start is inconsequential.

tebasuna51
8th March 2009, 02:47
I can confirm than Tsmuxer add garbage at end of wav files when demux.
Use eac3to to demux.