Hello,
I searched several hours to do this conversation, thats why im sharing this here. MPEG transport stream, which is usullay a .ts files, is often used in TV broadcasting. So with this guide you can convert recorded TV-streams (HDTV and SDTV) into mkv files. Note: There is no reencoding/compression of video or sound streams! When it is MPEG-2 before, its MPEG-2 after too!
Motivation
Why would I want to convert a .ts file to .mkv? There are two main reasons for me: First, Matroska (mkv) is an open Video Container with broad support. Second, Matroska files are smaller then .ts files (around 3%, without additional compression, just less overhead!). Additional, you can define more Metainformation for the streams (e.x. audio language)
Demuxing .ts file
I did this with TsRemux from dmz01 over at doom9.org. There is no native Linux version! It's written in .NET, so we can use Mono to run it under Linux (tested with 0.21.2).
First we need to install additional Mono libraries.
Code:
$ sudo aptitude install libmono-winforms2.0-cil
Then you have to download TsRemux from this thread in the doom9.org Forum.
To start this TsRemux use this command:
At the main window you can open your .ts-file. Once opened, you should see a stream list in the left box. Right click an a stream and select "Demux ... to elementary stream". A filename you can use anything you want, its probably a good idea to name it after the content, for example out.mpeg or out.avc.
Once demuxed, you can get over and remux it to a mkv-file.
Muxing to a .mkv file
This is done using mkvmerge from the mkvtoolnix program suite. We also need mplayer do determine the fps of the .ts stream. There may be an easier method... It doesnt matter from where you now the fps of your .ts stream, the number is all that counts ! It is all contained in the repository, so we use a little aptitude magic again:
Code:
$ sudo aptitude install mkvtoolnix mkvtoolnix-gui mplayer
You can run the GUI using this command:
Now you can add the streams demuxed before with the add button.
You may get a warning that the number of frames per seconds could not be determined. We can do this using mplayer from the console on the original .ts file:
You get an output like this:
Code:
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: AMD Athlon(tm) 64 Processor 3200+ (Family: 15, Model: 31, Stepping: 0)
CPUflags: MMX: 1 MMX2: 1 3DNow: 1 3DNow2: 1 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing Desktop/arte.hd.ts.
TS file format detected.
VIDEO H264(pid=120) AUDIO MPA(pid=131) NO SUBS (yet)! PROGRAM N. 3585
FPS seems to be: 25.000000
xscreensaver_disable: Could not find XScreenSaver window.
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================
==========================================================================
Forced audio codec: mad
Opening audio decoder: [libmad] libmad mpeg audio decoder
AUDIO: 48000 Hz, 2 ch, s16le, 128.0 kbit/8.33% (ratio: 16000->192000)
Selected audio codec: [mad] afm: libmad (libMAD MPEG layer 1-2-3)
==========================================================================
AO: [pulse] Failed to connect to server: Connection refused
[AO_ALSA] alsa-lib: pcm_hw.c:1099:(snd_pcm_hw_open) open /dev/snd/pcmC0D0p failed: Device or resource busy
[AO_ALSA] alsa-lib: pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
[AO_ALSA] Playback open error: Device or resource busy
[AO OSS] audio_setup: Can't open audio device /dev/dsp: Device or resource busy
[AO_ALSA] alsa-lib: pcm_hw.c:1099:(snd_pcm_hw_open) open /dev/snd/pcmC0D0p failed: Device or resource busy
[AO_ALSA] alsa-lib: pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
[AO_ALSA] Playback open error: Device or resource busy
[AO ARTS] loading the aRts backend "/usr/lib/libartscbackend.la" failed
[AO ESD] latency: [server: 0.24s, net: 0.00s] (adjust 0.24s)
AO: [esd] 48000Hz 2ch s16le (2 bytes per sample)
Starting playback...
You have to set this frame rate in the "Format specific options" Tab of the Video stream under "FPS".
Once all streams are added, you can define an output filename and start muxing! You're done!
If audio is not sync with video, you may have taken a wrong FPS-rate....
Bookmarks