Burning MPEG2-TS to DVD – E03 – adding the subtitles
DVD subtitles aren't text, hardware players don't support rendering text into fonts, so you have to insert images that will be displayed by the player at the right time.
When demuxing our TS in the first article, we have extracted the subtitles in subrip format. We now need a tool that will create another MPEG2 track that contains images of the subtitles, rendered with the right font.
spumux, part of the dvdauthor suite does this job fairly well. Again, use your package manager to install dvdauthor and you should be able to use it.
XML subtitles descriptor
spumux uses an XML descriptor file that helps it render the subtitles. You specify the location of the subrip file, its charset, the font that will be used for rendering the text, and various other parameters for the location of the subtitles.
Here is the content of the file named stream-subs.xml we are going to use for this project.
<subpictures> <stream> <textsub filename="stream[889].srt" characterset="ISO8859-1" fontsize="28.0" font="arial.ttf" horizontal-alignment="center" vertical-alignment="bottom" left-margin="60" right-margin="60" top-margin="20" bottom-margin="30" subtitle-fps="25" movie-fps="25" movie-width="720" movie-height="574" force="yes" /> </stream> </subpictures>
$ spumux -P stream-subs.xml < stream.ps > stream-with-subs.ps DVDAuthor::spumux, version 0.6.14. Build options: gnugetopt magick iconv freetype Send bugs to INFO: Locale=fr_FR.UTF-8 INFO: Converting filenames to UTF-8 INFO: Detected subtitle file format: subviewer INFO: Opened iconv descriptor. *UTF-8* *ISO8859-1* INFO: Read 1267 subtitles INFO: Unicode font: 242 glyphs. INFO: Found EOF in .sub file.a written INFO: 1267 subtitles added, 0 subtitles skipped, stream: 32, offset: 0.12 Statistics: - Processed 1267 subtitles. - The longest display line had 37 characters. - The maximum number of displayed lines was 2. - The normal display height of the font arial.ttf was 32. - The bottom display height of the font arial.ttf was 38. - The biggest subtitle box had 3118 bytes.
When spumux finishes processing, you should have a stream-with-subs.ps file in your current working directory, and you should be able to test that it displays properly using VLC or your media player (VLC won't recognize the subtitles stream in the resulting PS, but don't worry, spumux has inserted it properly.
Fonts
Not liking Arial too much, I am still looking for the best font for the job, spumux comes with a set of fonts coming from the mplayer project, if you want to try out other fonts, they just have to be in ~/.spumux just copy/link the .ttf files there.
Timing issues
Sometimes the subtitles are offset a bit and do not display at the right time. I have found a very handy tool named Sears that will allow you to edit the subtitles, change the text or timing, and more importantly offset the whole batch by one or 2 seconds if necessary.
Now it's time to move on the final step of our DVD authoring. Creating the DVD structure from the resulting MPEG2-PS.
Back to the summary article
Episode 1: Edit cutpoints and de-mux with ProjectX
Episode 2: Multiplex the resulting streams into a DVD-compatible PS using mplex
Episode 4: authoring the DVD
Burning MPEG2-TS to DVD – E02 – Multiplex audio and video streams into a DVD-compliant PS
So you've just finished extracting the video, audio and subtitles tracks from your TS, as described in the previous article of the serie.
In the working directory, you should have the following files:
total 8583424 -rw-r--r-- 1 erwan staff 1699268204 7 mai 09:43 stream.m2v -rw-r--r-- 1 erwan staff 207926016 7 mai 09:43 stream.mp2 -r-xr-xr-x 1 erwan staff 2487420480 6 mai 21:22 stream.ts -rw-r--r-- 1 erwan staff 82010 7 mai 09:43 stream[889].srt -rw-r--r-- 1 erwan staff 3232 7 mai 09:43 stream_log.txt
stream.m2v is the video track, stream.mp2 is the audio track, the subtitles have been extracted into stream[889].srt.
You're going to build a DVD-compliant PS file using mplex. mplex is part of the mjpegtools program suite, you can install them with your package manager, on my my Mac, I used macports to install it (port install mjpegtools).
[19:10:02]-erwan@ip-192-168-224-58:~/tmp/article > mplex -f8 -o stream.ps stream.m2v stream.mp2 INFO: [mplex] mplex version 1.9.0 (2.2.7 $Date: 2006/02/01 22:23:01 $) INFO: [mplex] File stream.m2v looks like an MPEG Video stream. INFO: [mplex] File stream.mp2 looks like an MPEG Audio stream. INFO: [mplex] Video stream 0: profile 8 selected - ignoring non-standard options! INFO: [mplex] Found 1 audio streams and 1 video streams INFO: [mplex] Selecting dvdauthor DVD output profile INFO: [mplex] Multiplexing video program stream! INFO: [mplex] Scanning for header info: Video stream e0 (stream.m2v) INFO: [mplex] VIDEO STREAM: e0 INFO: [mplex] Frame width : 720 INFO: [mplex] Frame height : 576 INFO: [mplex] Aspect ratio : 4:3 display INFO: [mplex] Picture rate : 25.000 frames/sec INFO: [mplex] Bit rate : 5430400 bits/sec INFO: [mplex] Vbv buffer size : 229376 bytes INFO: [mplex] CSPF : 0 INFO: [mplex] Scanning for header info: Audio stream c0 (stream.mp2) INFO: [mplex] MPEG AUDIO STREAM: c0 INFO: [mplex] Audio version : 1.0 INFO: [mplex] Layer : 2 INFO: [mplex] CRC checksums : yes INFO: [mplex] Bit rate : 32768 bytes/sec (256 kbit/sec) INFO: [mplex] Frequency : 48000 Hz INFO: [mplex] Mode : 0 stereo INFO: [mplex] Mode extension : 0 INFO: [mplex] Copyright bit : 0 no copyright INFO: [mplex] Original/Copy : 0 copy INFO: [mplex] Emphasis : 0 none INFO: [mplex] SYSTEMS/PROGRAM stream: INFO: [mplex] rough-guess multiplexed stream data rate : 5810448 INFO: [mplex] target data-rate specified : 10080000 INFO: [mplex] Setting specified specified data rate: 10080000 INFO: [mplex] Run-in delay = 7200 Video delay = 7200 Audio delay = 10800 INFO: [mplex] New sequence commences... INFO: [mplex] Video e0: buf= 0 frame=000000 sector=00000000 INFO: [mplex] Audio c0: buf= 0 frame=000000 sector=00000000 INFO: [mplex] Scanned to end AU 162441 INFO: [mplex] STREAM e0 completed INFO: [mplex] STREAM c0 completed INFO: [mplex] Multiplex completion at SCR=584792210. INFO: [mplex] Video e0: completed INFO: [mplex] Audio c0: completed INFO: [mplex] VIDEO_STATISTICS: e0 INFO: [mplex] Video Stream length: 1699268204 bytes INFO: [mplex] Sequence headers: 4820 INFO: [mplex] Sequence ends : 1 INFO: [mplex] No. Pictures : 162442 INFO: [mplex] No. Groups : 4820 INFO: [mplex] No. I Frames : 4820 avg. size 32405 bytes INFO: [mplex] No. P Frames : 49328 avg. size 12305 bytes INFO: [mplex] No. B Frames : 108294 avg. size 8643 bytes INFO: [mplex] Average bit-rate : 2092000 bits/sec INFO: [mplex] Peak bit-rate : 5431600 bits/sec INFO: [mplex] BUFFERING min 15 Buf max 153570 INFO: [mplex] AUDIO_STATISTICS: c0 INFO: [mplex] Audio stream length 207926016 bytes. INFO: [mplex] Syncwords : 270737 INFO: [mplex] Frames : 270737 padded INFO: [mplex] Frames : 0 unpadded INFO: [mplex] BUFFERING min 15 Buf max 779 INFO: [mplex] MUX STATUS: no under-runs detected.
Ok, now stream.ps contains a DVD-compliant stream that you'll be able to use for authoring the DVD. Before going further make sure that you can play it with your media player (VLC comes handy), and that the audio and video tracks are in sync ...
Now, it's time to insert the subtitles track.
Back to the summary article
Episode 1 : Edit cutpoints and de-mux with ProjectX
Episode 3: adding the subtitles
Episode 4: authoring the DVD
Burning MPEG2-TS to DVD – E01 – cutpoints and demux with ProjectX
This is the first episode of the "Burning MPEG2-TS to DVD" serie of articles. In this one, we'll see how to cut MPEG2 and extract the streams from our MPEG2-TS file.
Say you got a file name "stream.ts" from your decoder.
Start ProjectX. The UI is not very intuitive, but i'll try to walk you through it so you know your way around
open stream.ts, the preview window in the middle should display the list of streams in the container that ProjectX detected.
Take note of the PID of every streams you are interested in (here it's 0xA2 -> video, 0x59 -> original soudtrack, and 0x26 for the subtitles). The stream list usually doesn't stay long before returning back to the preview mode. If it disappears, just click on the file name in the list at the bottom of the window.
In the right part of the window, you can specify the list of the PIDs that you want to extract ("PES(&Sub)-ID/PID list").
Add each interesting streams to this list, including the subtitle one (0x26 here)
Now you are ready to extract the streams from the TS. Click the "prepare >>" button on the left of the main window.
Before starting the process you'll need to adjust some options, mainly related to subtitles. Open the "pre-settings" windows in "PreSettings -> Presettings".
go to the subtitle tab on the left, and enter the teletext page number for the subtitles. On my satellite feed, it is page 889, but this number depends on the broadcaster, you have to fiddle around a bit to find it.
Choosing "basic latin" as language will encode the resulting file in ISO-8859-1.
use "subtitle export formats": SRT (subrip)
You are ready :
press on the "play" button, and projectX will start working
After the end of the process, voilà !
The following files are produced:
- stream.m2v - the video track
- stream.mp2 - the audio track
- stream[889].srt - subtitles
The next article will discuss re-multiplexing the video and audio tracks into a DVD-compliant MPEG2-PS file
Back to the summary article
Episode 2: Multiplex the resulting streams into a DVD-compatible PS using mplex
Episode 3: adding the subtitles
Episode 4: authoring the DVD
Burning MPEG2-TS to a DVD
For years, i have been using my dreambox to record TV shows and enjoy them when I fancy. I especially like the fact that i can skip commercials. Anyway, a while ago a good friend asked if I could make a DVD out of a documentary I had recorded on the box's HDD.
"no problem, I'll burn it rightaway", I answered ...
could I be more foolish ?
It took me more than a month to figure out what were the steps requested to achieve this. At the beginning, I was thinking that simply building a DVD structure (dvdauthor) out of the MPEG2 Transport Stream picked up from the receiver would work. After all, a DVD player can read MPEG2, and everything needed is inside the file, including the video track, the audio in 2 languages and the subtitles !
DVD players can only read MPEG2 Program Streams and what you get from a DVB tuner are Program Streams, totally different beasts !
Some background about MPEG2
The MPEG2 standard defines two kind of containers for a variety of streams that are multiplexed (or muxed) together. Transport streams (MPEG2-TS) are used by most broadcasted programs such as DVB (-S for satellite, -T for terrestial, ...) and Program Streams (MPEG2-PS) for anything that could be contained in file-based storage (with a beginning and an end). As stated in this Wikipedia article, the two formats are "different, but related", and for this reason, you can't just dump a program you've recorded on a DVD and hope that your player will be happy with it.
Additionally, TS are inherently resistant to broadcasting errors (reception problems, rain on the satellite dish, etc ...), and have support to allow players to resynchronize the video and audio tracks when it jumps. PS don't provide that, and just converting the TS to a PS would progressively make the video and audio out of sync when playing it back.
Making a proper PS for inclusion in a DVD from a TS requires a lot of steps that I'm going to describe in this article. Hold your breath
My requirements for this DVD-burning project are:
- being able to watch movies with their original soundtrack. I just can't bear the french soundtrack they make us endure in France (and it's actually a law here. You can't broadcast movies with the original soundtrack before very late at night if you're not a premium channel)
- subtitles. I can enjoy most movies in english, but i like to have subtitles. Movies recorded from DVB streams in France, contain, in a very old-fashioned way, another MPEG stream, containing teletext encoded text on a special page (889 for french). Mind it, your DVD player will not be happy with those either !
I have found many user-friendly tools with nice GUI such as MPEGStreamClip for OSX, that would have allowed me to perform most of the step outlined below, but they always fall short on some of my requirements. For instance I could not make MPEGStreamClip include subtitles from the teletext stream into the file it produces. Other solution will not allow you to keep the original soundtrack. So my solution involves a lot of command-line tools and needs you to be pretty familiar with UNIX, and not afraid by a terminal window.
Something worth noting: With the recent advent of high-definition, decoders such as Free's FreeBOX-HD still produces MPEG2-TS files, but with the video track encoded using the H-264 codec. I couldn't make ProjectX cut/edit those files but it can still demux them. I've not tried that, but converting the video to MPEG-video and follow the same process should be possible. I guess you would have to re-encode them with a lower resolution, as MPEG2 in HD would use a HUGE amount of space and would certainly not fit in a 4.7GB DVD
The tools we'll need
- ProjectX: the swiss-army knife of MPEG-2. The interface is not very intuitive, but after a while, you can figure it out pretty easily and get it to do what you want. We're going to use this tool to extract the video, audio and subtitle tracks from the TS.
- mplex: part of the mjpeg-tools, this command-line tool allows to build a DVD-compliant Program Stream using the different tracks extracted using ProjectX
- spumux: part of the dvdauthor suite, allows you to add a dvd-compliant stream of subtitles from many different format (including subrip files !) to a MPEG2-PS
- dvdauthor: will build the standard DVD structure (AUDIO_TS and VIDEO_TS folders) from a MPEG2-PS
Say we downloaded a file named "stream.ts" from our decoder. Our goal is to use it to produce a valid DVD structure from it. In my serie of articles, I am going to walk you through converting that TS to a valid DVD structure that you can use to burn a DVD for your hardware DVD player.
Episode 1: Edit cutpoints and de-mux with ProjectX
Episode 2: Multiplex the resulting streams into a DVD-compatible PS using mplex
Episode 3: adding the subtitles
Episode 4: authoring the DVD






