2013-07-08

I decided to write this guide after sending someone these instructions via email, I figured I might as well post it somewhere to help other people new to this as well, hopefully this guide will help people who have not used MP4Box before.

The software you need for this is:

MKVToolNix: http://www.bunkus.org/videotools/mkvtoolnix/downloads.html

MKVExtractGUI-2: http://sourceforge.net/projects/mkvextractgui-2/

MP4Box: http://gpac.wp.mines-telecom.fr/mp4box/

for current & older versions: http://www.videohelp.com/tools/mp4box

Oxelon Media Converter: http://www.oxelon.com/media_converter.html

K-lite Standard Codec Pack (Playback Testing with Media Player Classic, and MediaInfo Lite): http://codecguide.com/download_kl.htm

MetaX (Optional): http://www.danhinsley.com/

YAMB (Optional MP4Box GUI): http://yamb.unite-video.com/

Step One Unpack / Extract the MKV Container:

Install MKVToolNix, and then extract the MKVExtractGUI-2 files to the same folder as MKVToolNix.

Run the MKVExtractGUI-2 executable file and browse for and open your MKV file.

Select the elements you wish to use for your new MP4 / M4V file from the list by checking the corresponding tick boxes.

Then click the Extract command button.

You should have separate files now for the video and audio, also if selected the subtitles and chapters as well.

Convert DTS to AAC (or AC3):

I use the program "Oxelon Media Converter" to convert DTS to 2 Channel AAC it's quick and easy. I do this as Apple do not support the DTS format, and I only need stereo sound for my iPad, but this program also supports converting to AC3 5.1.

Extracted MKV repacked to MP4 Container with GPAC 0.5.0-rev4065:

1. Rebuild Chapters to Apple friendly format GPAC TTXT:

Typical chapters extracted from Matroska (MKV) files are normally in OGG (*.OGM), Extensible Markup Language (*.XML), or SubRip Text (*.SRT) format.

Apple does not natively support these formats, supporting instead the Timed Text Format (*.TTXT) .

To change other types of chapter files to TTXT open any of these files in Notepad, and then copy the time codes into a new text file saved in UTF-8 named “chapters.ttxt”.

In the following example you can see the areas in red where you can cut and paste the time codes into a previously created template, optionally you can replace the chapter numbers with names as well.

<?xml version="1.0" encoding="UTF-8" ?>

<!-- GPAC 3GPP Text Stream -->

<TextStream version="1.1">

<TextStreamHeader width="480" height="368" layer="0" translation_x="0" translation_y="0">

<TextSampleDescription horizontalJustification="center" verticalJustification="bottom" backColor="0 0 0 0" verticalText="no" fillTextRegion="no" continuousKaraoke="no" scroll="None">

<FontTable>

<FontTableEntry fontName="Arial" fontID="1"/>

</FontTable>

<TextBox top="0" left="0" bottom="368" right="480"/>

<Style styles="Normal" fontID="1" fontSize="32" color="ff ff ff ff"/>

</TextSampleDescription>

</TextStreamHeader>

<TextSample sampleTime="00:00:00.000">1</TextSample>

<TextSample sampleTime="00:06:05.000">2</TextSample>

<TextSample sampleTime="00:12:14.000">3</TextSample>

<TextSample sampleTime="00:20:31.000">4</TextSample>

<TextSample sampleTime="00:25:21.000">5</TextSample>

<TextSample sampleTime="00:31:03.000">6</TextSample>

<TextSample sampleTime="00:35:39.000">7</TextSample>

<TextSample sampleTime="00:40:04.000">8</TextSample>

<TextSample sampleTime="00:45:41.000">9</TextSample>

<TextSample sampleTime="00:51:10.000">10</TextSample>

<TextSample sampleTime="00:55:28.000">11</TextSample>

<TextSample sampleTime="01:03:51.000">12</TextSample>

<TextSample sampleTime="01:13:53.000">13</TextSample>

<TextSample sampleTime="01:18:56.000">14</TextSample>

<TextSample sampleTime="01:27:57.000">15</TextSample>

<TextSample sampleTime="01:32:34.000">16</TextSample>

<TextSample sampleTime="01:37:55.000">17</TextSample>

<TextSample sampleTime="01:46:53.000">18</TextSample>

<TextSample sampleTime="01:52:24.000">19</TextSample>

<TextSample sampleTime="01:57:32.000">20</TextSample>

</TextStream>

Step Two Repack the Extracted files into a new Container:

MP4Box is a part of the GPAC Project on Advanced Content. GPAC is an implementation of the MPEG-4 Systems standard written in ANSI C.

GPAC provides tools for media playback, vector graphics and 3D rendering, MPEG-4 authoring and distribution. from Wikipedia.

MP4Box is a tool-set for handling the MP4 container format this is Command Line only by default, although various Graphical User Interface’s (GUI) for it do exist most are old and unsupported.

Optional GUI:

If you want to use a GUI I suggest YAMB (Yet.Another.MP4.Box - User Interface).

Its old but once installed you can replace the pre-installed MP4Box.exe with the latest version to ensure up to date compatibility.

To do this replace the MP4Box.exe file in the installation folder with the current one.

Default location for this (example): C:\Users\John\AppData\Roaming\Yamb\MP4Box.exe

MP4Box Installation options:

The latest version of MP4Box comes bundled as an installer as part of the GPAC framework, but you also have the option of not installing MP4Box and just browsing to the executable when you want to run it (if you unpack the .exe, or download a slightly older .zip package).

MP4Box Command Structure (typical usage):

MP4Box follows the typical rules for DOS commands, and Batch files can be written to make commonly used tasks available with the click of a mouse.

1. Typically the MP4Box instruction for each file is placed at the beginning of the file.

2. For each and every file used in the command line, it starts and ends with a speech mark "".

3. Every instruction within each speech mark for that file is separated by a colon :.

4. Each value is assigned by the equals sign =.

Command Line used by YAMB MP4 to MP4 (example):

"C:\Users\John\AppData\Roaming\Yamb\MP4Box.exe "

-add "C:\Users\John\Desktop\MOVIE EDIT DO NOT DEL\Paul (Unrated) [2011] (HD).m4v#1:fps=23.976"

-add "C:\Users\John\Desktop\MOVIE EDIT DO NOT DEL\Paul (Unrated) [2011] (HD).m4v#2:lang=en" -itags tool="Yamb 2.1.0.0 [http://yamb.unite-video.com]"

"C:\Users\John\Desktop\MOVIE EDIT DO NOT DEL\Paul (Unrated) [2011] (HD) New.mp4"

In Plain English:

Locate and use the MP4Box.exe file.

In MP4Box locate and add the following file, select only track one from that file, and set its frame-rate to 23.976 frames per second.

In MP4Box locate and add the following file, select only track two from that file, set it's listed language as English, add the following data to the file about it's creation.

Create a new file in the following location with the following name from all previous files and instructions.

Summary:

This takes a video and audio track from a file and creates a new one with those, setting the frame-rate and labeling the audio track as English, then adding data about it's creation (Yamb 2.1.0.0 [http://yamb.unite-video.com]).

Command Line example for adding typical HD content extracted from an MKV file (with installed GPAC Framework) in MP4Box:

MP4Box -add "C:\Users\John\Desktop\MyMovie.h264:fps=23.976:nam e=MyMovieMP4:lang=en" -add "C\Users\John\Desktop\MyMovie.aac:lang=en:name =2 Channel Audio" "C:\Users\John\Videos\My New Movie.mp4"

In English:

Add the H.264 video file to the AAC audio file and label both as English language, set the frame-rate to 23.976 frames per second, label the video file as "MyMovieMP4" and audio file as "2 Channel Audio". Then output these instructions as a new file with the name "My New Movie.mp4" in the Videos folder.

Putting the file back together:

Commands entered in Administrator Command Prompt (example):

C:\Windows\system32>mp4box -add "C:\Users\John\Desktop\1.h264:fps=23.976:name= The Host:lang=en" -add "C:\Users\John\Desktop\1.aac:lang=en:name=2 Channel audio" -add "C:\Users\John\Desktop\chapters.ttxt:chap:name=Cha pters" "C:\Users\John\Desktop\The Host.mp4"

Command Prompt Output:

AVC-H264 import - frame size 1916 x 796 at 23.976 FPS

AVC Import results: 180641 samples - Slices: 22064 I 715584 P 707480 B - 183081 SEI - 19520 IDR

AAC import - sample rate 44100 - MPEG-4 audio - 2 channels

Timed Text (GPAC TTXT) Import

Saving to C:\Users\John\Desktop\The Host.mp4: 0.500 secs Interleaving

Media Information on completed file:

General

Complete name: C:\Users\John\Desktop\The Host.mp4

Format: MPEG-4

Format profile: Base Media

Codec ID: isom

File size: 4.27 GiB

Duration: 2h 5mn

Overall bit rate mode: Variable

Overall bit rate: 4 865 Kbps

Encoded date: UTC 2013-07-07 21:18:46

Tagged date: UTC 2013-07-07 21:18:46

Video

ID: 1

Format: AVC

Format/Info: Advanced Video Codec

Format profile: High@L4.0

Format settings, CABAC: Yes

Format settings, ReFrames: 5 frames

Codec ID: avc1

Codec ID/Info: Advanced Video Coding

Duration: 2h 5mn

Bit rate: 4 712 Kbps

Maximum bit rate: 12.5 Mbps

Width: 1 916 pixels

Height: 796 pixels

Display aspect ratio: 2.40:1

Frame rate mode: Constant

Frame rate: 23.976 fps

Color space: YUV

Chroma subsampling: 4:2:0

Bit depth: 8 bits

Scan type: Progressive

Bits/(Pixel*Frame): 0.129

Stream size: 4.13 GiB (97%)

Title: The Host

Language: English

Encoded date: UTC 2013-07-07 21:18:46

Tagged date: UTC 2013-07-07 21:22:41

Color primaries: BT.709

Transfer characteristics: BT.709

Matrix coefficients: BT.709

Audio

ID: 2

Format: AAC

Format/Info: Advanced Audio Codec

Format profile: LC

Codec ID: 40

Duration: 2h 5mn

Bit rate mode: Variable

Bit rate: 150 Kbps

Maximum bit rate: 207 Kbps

Channel(s): 2 channels

Channel positions: Front: L R

Sampling rate: 44.1 KHz

Compression mode: Lossy

Stream size: 134 MiB (3%)

Title: 2 Channel audio

Language: English

Encoded date: UTC 2013-07-07 21:22:30

Tagged date: UTC 2013-07-07 21:22:41

Text

ID: 3

Format: Timed text

Codec ID: tx3g

Duration: 2h 2mn

Bit rate mode: Variable

Bit rate: 0 bps

Stream size: 71.0 Bytes (0%)

Title: Chapters

Encoded date: UTC 2013-07-07 21:22:41

Tagged date: UTC 2013-07-07 21:22:41

(The red text above is the data put into the file by the instructions in MP4Box.)

Rename the file from *MP4 to *M4V for compatibility with iTunes.

Simple Batch file examples in MP4Box:

1.

for /r %%v in (*.mp4) do mp4box "%%v" -info >"%%v.txt"

In English:

for recursive variables ending with .mp4 run MP4Box.exe using the variables name, with the command -info, and output the results to a text file of the same name.

This runs the information tool in MP4Box, listing the file properties of the selected files, which in this case would be all MP4 files in this folder and all sub-folders.

2.

for %%a in (*.srt) do mp4box -add "%%~Na.m4v" -add "%%a:chap:name=Chapters" "(Ch)%%~Na.m4v"

In English:

for all files ending in .srt do MP4Box.exe then add the M4V file with the corresponding name, next set the .srt files use to Chapters instead of the default Subtitles, label it as Chapters, and output these instructions to a new file labeled for the original but with the prefix CH.

(note this one doesn’t work with subs as the last one stays on the screen).

Show more