# mkv2tivomp4.bat



## orangeboy

Ok, I got a request to post some instructions on how to setup and use the mkv2tivomp4.bat file I posted in another thread. The following instructions are based on Windows XP, what I am running at home. Here it goes:


Create a folder on your computer named mkv2mp4.
Download and install/extract to the mkv2mp4 folder you created the programs that do the actual work:
eac3to.exe - Is required to demux (separate) the audio and video streams from the .mkv file.
and either:
mp4creator.exe - Can be used to mux (join) the audio and video streams into a .mp4 file.
or
mp4box.exe - An alternative to mp4creator that may reduce audio/video synchronization errors.

Download and save to the mkv2mp4 folder you created the mkv2tivomp4.v6.txt file attached in this post, and rename that file to mkv2tivomp4.bat.
Create a Shortcut to mkv2tivomp4.bat:
Open Windows Explorer and go to the SendTo folder: 
In Windows NT, 200x, XP: %UserProfile%\Sendto
In Vista and Windows 7: %AppData%\Microsoft\Windows\SendTo

Right-click on the whitespace in the folder, and select New > Shortcut
The dialog will ask for a location. Use Browse... to navigate to the \mkv2mp4 folder you created, and select mkv2tivomp4.bat
Give the shortcut a new name if you wish (I usually just leave off the ".bat" part of the name).
Click Finish.

Find an .mkv file.
Right-click on it, and SendTo > mkv2tivomp4 (or whatever name you gave it)
A Windows command window will open, with a short narrative concerning "First Run Setup". Read this, and then press any key.
Follow the dialog, answering the questions as you go. 
Some affirmative answers will lead to more questions, but all in all, it doesn't take too long to finish.
You may be prompted for program locations. Typically you will specify the \mkv2mp4 folder you created.
If you choose so, and you already have the following installed, there are options for: 
copying to Tivo Desktop Plus auto-transfer folders,
copying to pyTivo-auto-push folders, 
performing pyTivoMetaThis to create pyTivo metadata files.

You can specify an additional user defined post process to occur. Perhaps deleting or moving the original .mkv file? It's up to you...
You will be prompted to press any key when the dialog completes, indicating the batch file has been configured.

The .mkv file you initially selected will now be "converted" to a .mp4 file.
Any additional .mkv files you "SendTo" mkv2tivomp4.bat will not require you to perform the setup again.
Multiple files can be sent to the batch file using the SendTo method, and it will process them one at a time. An example would be using Search to find all .mkv files in a folder or on a drive, and then Sending them To the mkv2tivomp4.bat shortcut

Advanced setup: If you add the mkv2mp4 folder to your %path% environment variable, the batch will not prompt you at setup time for the programs that reside in that folder (or any program or command that can be found in %path%).

Any questions you may have, or any bugs you encounter, let me know!
I'm working (not too quickly) on version 7 that will support UNC paths for those files on remote drives, and will better detect filenames that don't play well with batch files...


----------



## superflysocal

Awesome thanks.

Any chance to create a mp4 with multichannel aac to mp4 with 2 channel aac script?


----------



## orangeboy

superflysocal said:


> Awesome thanks.
> 
> Any chance to create a mp4 with multichannel aac to mp4 with 2 channel aac script?


Hmm... It appears that eac3to does support aac:



Code:


Supported source formats:
(1) RAW, (L)PCM
(2) WAV (PCM, DTS and AC3), W64, RF64
(3) AC3, E-AC3
(4) DTS, DTS-ES, DTS-96/24, DTS-HD Hi-Res, DTS-HD Master Audio
(5) MP1, MP2, MP3 audio
(6) AAC audio
(7) MLP, TrueHD, TrueHD/AC3
(8) FLAC
(9) EVO/VOB/(M2)TS and MKV

Decoded audio data can be stored as / encoded to:
(1) RAW, (L)PCM
(2) WAV (PCM only), W64, RF64, AGM
(3) WAVs (multiple mono WAV files, PCM only)
(4) AC3
(5) DTS
(6) AAC
(7) FLAC

I'll see what I can do to work in an aac section. There's certainly the option to go stereo with "-down2", but would 5.1 aac > 5.1 ac3 be better?
Whoops! Spoke too soon. eac3to doesn't support aac natively. I got this error just now:


Code:


MKV, 1 video track, 3 audio tracks, 0:01:40, 24p /1.001
1: h264/AVC, Japanese, 720p23.975
   "AVC (720p)"
2: AAC, Japanese, 2.0 channels, 48khz
   "AAC (Original/Instrumental)"
3: AAC, Japanese, 2.0 channels, 48khz
   "AAC (Miku Hatsune voice)"
4: AAC, Japanese, 2.0 channels, 48khz
   "AAC (Instrumental)"
v01 The video bitstream is encoded in a non-standard framerate.
v01 The video bitstream framerate field doesn't match the container framerate.
a02 Extracting audio track number 2...
a02 Decoding with DirectShow (Nero Audio Decoder 2)...
a02 Getting "Nero Audio Decoder 2" instance failed.
Aborted at file position 1310720.

If there's a CLI program that does aac processing, I'll gladly add it in! :up:


----------



## superflysocal

there is a utility in the Popcorn Hour forum called MKV AudioConverter that converts MKV with AAC to MKV with AC3. I think it uses Aften.exe or Faad.exe for that but not sure. Have a look:

http://www.networkedmediatank.com/showthread.php?tid=20887&highlight=audioconverter


----------



## txporter

orangeboy said:


> Hmm... It appears that eac3to does support aac:
> 
> 
> 
> Code:
> 
> 
> Supported source formats:
> (1) RAW, (L)PCM
> (2) WAV (PCM, DTS and AC3), W64, RF64
> (3) AC3, E-AC3
> (4) DTS, DTS-ES, DTS-96/24, DTS-HD Hi-Res, DTS-HD Master Audio
> (5) MP1, MP2, MP3 audio
> (6) AAC audio
> (7) MLP, TrueHD, TrueHD/AC3
> (8) FLAC
> (9) EVO/VOB/(M2)TS and MKV
> 
> Decoded audio data can be stored as / encoded to:
> (1) RAW, (L)PCM
> (2) WAV (PCM only), W64, RF64, AGM
> (3) WAVs (multiple mono WAV files, PCM only)
> (4) AC3
> (5) DTS
> (6) AAC
> (7) FLAC
> 
> I'll see what I can do to work in an aac section. There's certainly the option to go stereo with "-down2", but would 5.1 aac > 5.1 ac3 be better?
> Whoops! Spoke too soon. eac3to doesn't support aac natively. I got this error just now:
> 
> 
> Code:
> 
> 
> MKV, 1 video track, 3 audio tracks, 0:01:40, 24p /1.001
> 1: h264/AVC, Japanese, 720p23.975
> "AVC (720p)"
> 2: AAC, Japanese, 2.0 channels, 48khz
> "AAC (Original/Instrumental)"
> 3: AAC, Japanese, 2.0 channels, 48khz
> "AAC (Miku Hatsune voice)"
> 4: AAC, Japanese, 2.0 channels, 48khz
> "AAC (Instrumental)"
> v01 The video bitstream is encoded in a non-standard framerate.
> v01 The video bitstream framerate field doesn't match the container framerate.
> a02 Extracting audio track number 2...
> a02 Decoding with DirectShow (Nero Audio Decoder 2)...
> a02 Getting "Nero Audio Decoder 2" instance failed.
> Aborted at file position 1310720.
> 
> If there's a CLI program that does aac processing, I'll gladly add it in! :up:


If you read down at the end of the instruction screen for eac3to, it says you need Nero AAC Encoder for eac3to to encode to AAC. I think you can get it here. I really haven't messed around with it much, but have done 1 or 2 encodes with it just to experiment.


----------



## KevinSartori

If you're running Windows Vista or 7 the SendTo folder is in a different place. So, for Step 4, Open Windows Explorer and go to this folder instead:

%UserProfile%\AppData\Roaming\Microsoft\Windows\SendTo

BTW, nice work on this *orangeboy*! Thanks!


----------



## orangeboy

KevinSartori said:


> If you're running Windows Vista or 7 the SendTo folder is in a different place. So, for Step 4, Open Windows Explorer and go to this folder instead:
> 
> %UserProfile%\AppData\Roaming\Microsoft\Windows\SendTo
> 
> BTW, nice work on this *orangeboy*! Thanks!


Thanks Kevin - Instructions updated!


----------



## nickels

I tried this yesterday and something went wrong. My video framerate is too fast and the audio doesn't sync due to this video issue. I am using Windows 7 and I tried both options (mp4creator and mp4box). HELP PLEASE!


----------



## orangeboy

nickels said:


> I tried this yesterday and something went wrong. My video framerate is too fast and the audio doesn't sync due to this video issue. I am using Windows 7 and I tried both options (mp4creator and mp4box). HELP PLEASE!


Does it happen consistently, or just one file? Does the .mkv playback ok before being "converted" to .mp4?

If it's consistent, about halfway down the script (line 395), you'll see a section that looks like this:


Code:


:Done
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This section ends the processing of this batch file.                      ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
EXIT /B

If you would, make a small modification:


Code:


:Done
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This section ends the processing of this batch file.                      ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET
PAUSE
EXIT /B

That will show all the variables (unfortunately, even System variables, but I can weed through those), and PAUSE. Copy what's on the screen (right click on the script's Title bar > Edit > Select All > Press <ENTER>) and PM me that information. A copy of the script's .ini file may be handy for me, too...


----------



## ajayabb

The Nero aac encoder link is here. http://www.nero.com/eng/downloads-nerodigital-nero-aac-codec.php

I am not sure how to incorporate it into mkv2mp4. I extracted it to the mkv2mp4 folder but not sure if that will work


----------



## Spenner

Your batch is awesome. Can I put in a little request for it to include a Preferred Language setting? That way if your preferred language is Eng, and a video has two audio tracks Eng and something else, it will use the highest-scoring English track even if another track has a higher score.


----------



## orangeboy

ajayabb said:


> The Nero aac encoder link is here. http://www.nero.com/eng/downloads-nerodigital-nero-aac-codec.php
> 
> I am not sure how to incorporate it into mkv2mp4. I extracted it to the mkv2mp4 folder but not sure if that will work


Cool! :up:
I downloaded the zip (after entering [email protected] ), and will take a look at the exes inside. I imagine this will add additional processing time if invoked, but the benefits could outweigh that...


----------



## orangeboy

Spenner said:


> Your batch is awesome. Can I put in a little request for it to include a Preferred Language setting? That way if your preferred language is Eng, and a video has two audio tracks Eng and something else, it will use the highest-scoring English track even if another track has a higher score.


Uh-oh. Is the following falling through?


Code:


FOR /F "tokens=1,2 delims=,/ " %%A IN ('FINDSTR "%aLang% %sLang%" %SourceInfoName%') DO (
	SET track_ID=%%A
	SET track_type=%%B
	IF DEFINED track_type CALL :!track_type! !track_ID! !track_type! %aLang% %sLang%
)

The above _should_ select the audio/subtitle language set during the "First Run Setup" dialog:


Code:


:Audio_Language
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This section prompts the user for the preferred audio language.           ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
CLS
ECHO.
ECHO * Audio language 
SET /P aLang=Enter your preferred audio track language: 
SET aLang= %aLang%
CALL :TitleCase aLang
SET aLang=%aLang: =%
IF NOT DEFINED aLang GOTO Audio_Language

Unless the the language reported is literally "Eng", and not "English"? I may be able to substring the language variable to the first the characters, but I'm not sure that would work for all language abbreviations...


----------



## nickels

I just installed a newer version of pyTivo and the MKV files are now transferring normally without the need for conversion. So, I am done troubleshooting and thanks!


----------



## jcthorne

pyTivo cannot push an mkv to tivo without conversion to mpeg2. Only an mp4 can be pushed to tivo containing an h.264 video stream.....So far.


----------



## KevinG

I've just started using this wonderful tool...thank you for providing it!

Now, a question.

I've currently got sabnzbd listening to RSS feeds, grabbing files, and calling a batch file which pushes said files automatically to one of my tivos.

What I'd like to do is insert this process before the push.

Has anyone successfully automated that entire process? Interesting tidbits that I'm thinking about...how to only run the process on MKVs. How to delete the MKVs only upon successful conversion to MP4?

Thanks again.
-Kevin


----------



## orangeboy

KevinG said:


> I've just started using this wonderful tool...thank you for providing it!
> 
> Now, a question.
> 
> I've currently got sabnzbd listening to RSS feeds, grabbing files, and calling a batch file which pushes said files automatically to one of my tivos.
> 
> What I'd like to do is insert this process before the push.
> 
> Has anyone successfully automated that entire process? Interesting tidbits that I'm thinking about...how to only run the process on MKVs.


I had a reply drafted, but ended up dropping it all and starting over. I think the toughest thing to overcome with the RSS feeds is determining the filename of the extracted _result_ of the feed. According to the SABnzbd User-Script Wiki, the only filename that is passed is the original .nzb. However, in your "push" bat, you may still be able to use the passed SABnzbd arguments, similar to this:



Code:


FOR /F "delims=" %%a IN ('DIR /B /S /A-D "%~1\*.mkv"') DO mkv2tivomp4.bat "%%a"

That should search all the directories and sub-directories for mkv files, rooted in the "The final directory of the job (full path)", or %1.



KevinG said:


> How to delete the MKVs only upon successful conversion to MP4?
> 
> Thanks again.
> -Kevin


Yep, that's a logic fail on my part. 
I "post-process" regardless of whether a valid .mp4 file is created or not, instead of just jumping to the next mkv file (if there is one). That should be an easy thing to fix though, and I'm VERY glad you brought it up! I don't like code that executes when it shouldn't.

In the meantime, around line 294 begins a "cleanup" section. You could add a line in the group of "IF EXIST"s that would delete the original .mkv file:



Code:


IF EXIST "%SourceFullPath%" DEL "%SourceFullPath%"

Although I thought about adding that as the default action, I've found some mkv source files that didn't play on my TiVos after being remuxed into the mp4 container. Having the original mkv file around to run mediainfo on made it helpful to figure out "why".


----------



## KevinG

orangeboy said:


> I think the toughest thing to overcome with the RSS feeds is determining the filename of the extracted _result_ of the feed. According to the SABnzbd User-Script Wiki, the only filename that is passed is the original .nzb.


Yes, this is tough, but I've already solve that part. I run a batch program which calls a perl program which does a "glob" on the directory and finds the "newest" mkv file. Then I use curl to push it to the tivo. This only fails when I grab an "older" nzb and the resulting mkv isn't the "newest" one in the folder. I've tried getting perl to recognize the "write" datestamp, instead of the "creation" datestamp, but it doesn't seem to work on Windows (but works fine on linux).

Anyway, I'll have to look into your other suggestions...maybe I'll just call mkv2tivo inside my perl script...

Thanks again!


----------



## zabolots

Great batch file. I've used it on a few MKV's and it worked great, but I've got a couple of others that are giving me issues. Here's the output:


Code:


The format of the source file could not be detected.FINDSTR: Cannot open Boardwa
lk.Empire.S01E01.mkv.info.txt
FINDSTR: Cannot open Boardwalk.Empire.S01E01.mkv.info.txt
FINDSTR: Cannot open Boardwalk.Empire.S01E01.mkv.info.txt
FINDSTR: Cannot open Boardwalk.Empire.S01E01.mkv.info.txt
Valid video stream not found. Please review the information in "Boardwalk.Empire
.S01E01.mkv.info.txt".

Unfortunately there is no .txt file to get add'l info. There is briefly a .tmp file but it is deleted when the batch file ends so I have no idea what it contains.

Here's the mediainfo output for the file:



Code:


General #0
Complete name        : \temp\DVD\Boardwalk.Empire.S01E01.mkv
Format               : Matroska
File size            : 2.19 GiB
PlayTime             : 1h 12mn
Bit rate             : 4330 Kbps
Writing application  : x264.exe
Writing library      : mkv2rls x264-tv version built on 2010 jul 11

Video #0
Codec                : MPEG-4 AVC
Codec/Info           : MPEG4 ISO advanced profile
PlayTime             : 1h 12mn
Width                : 1280 pixels
Height               : 720 pixels
Aspect ratio         : 16/9
Frame rate           : 23.976 fps

Audio #0
Codec                : AC3
Codec/Info           : Dolby AC3
Channel(s)           : 6 channels
Sampling rate        : 48 KHz
Title                : English
Language             : English

Text #0
Codec                : UTF-8
Codec/Info           : UTF-8 Plain Text
Title                : English
Language             : English


----------



## Spenner

zabolots said:


> Great batch file. I've used it on a few MKV's and it worked great, but I've got a couple of others that are giving me issues. Here's the output:
> 
> 
> Code:
> 
> 
> The format of the source file could not be detected.FINDSTR: Cannot open Boardwa
> lk.Empire.S01E01.mkv.info.txt
> FINDSTR: Cannot open Boardwalk.Empire.S01E01.mkv.info.txt
> FINDSTR: Cannot open Boardwalk.Empire.S01E01.mkv.info.txt
> FINDSTR: Cannot open Boardwalk.Empire.S01E01.mkv.info.txt
> Valid video stream not found. Please review the information in "Boardwalk.Empire
> .S01E01.mkv.info.txt".


I've gotten that sometimes too. It's some kind of file or folder permission issue on the source. Just copy the mkv file to another folder and try it again, and that usually works for me.


----------



## zabolots

Spenner said:


> I've gotten that sometimes too. It's some kind of file or folder permission issue on the source. Just copy the mkv file to another folder and try it again, and that usually works for me.


I don't think it's a permissions issue for me since every MKV I've tried to convert with this batch file (both successfully and unsuccessfully) were all in the same folder. Plus, it does briefly create the .tmp file I mentioned so I know that it is not being preventing from creating files in the folder where the MKV file is located.


----------



## zabolots

I tried to rewrite the MKV into an MP4 container with ffmpeg. It doesn't help me one bit, but perhaps somebody will see something here to figure out a way to fix these files so they'll work with the mkv2tivomp4 process:



Code:


c:\Temp\DVD>ffmpeg -i Boardwalk.Empire.S01E01.mkv -vcodec copy -acodec copy -ac
2 Boardwalk.Empire.S01E01.mp4
FFmpeg version SVN-r21085, Copyright (c) 2000-2010 Fabrice Bellard, et al.
  built on Jan  8 2010 06:05:02 with gcc 4.2.4
  configuration: --enable-memalign-hack --prefix=/mingw --cross-prefix=i686-ming
w32- --cc=ccache-i686-mingw32-gcc --target-os=mingw32 --arch=i686 --cpu=i686 --e
nable-avisynth --enable-gpl --enable-version3 --enable-zlib --enable-bzlib --ena
ble-libgsm --enable-libfaad --enable-pthreads --enable-libvorbis --enable-libthe
ora --enable-libspeex --enable-libmp3lame --enable-libopenjpeg --enable-libxvid
--enable-libschroedinger --enable-libx264 --enable-libopencore_amrwb --enable-li
bopencore_amrnb
  libavutil     50. 7. 0 / 50. 7. 0
  libavcodec    52.45. 0 / 52.45. 0
  libavformat   52.46. 0 / 52.46. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libswscale     0. 8. 0 /  0. 8. 0
[matroska @ 0x13abc40]MAX_READ_SIZE:5000000 reached
[matroska @ 0x13abc40]Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 47.95 (48000/
1001) -> 23.98 (24000/1001)
Input #0, matroska, from 'Boardwalk.Empire.S01E01.mkv':
  Duration: 01:12:19.00, start: 0.000000, bitrate: N/A
    Stream #0.0(eng): Video: h264, yuv420p, 1280x720, PAR 1:1 DAR 16:9, 47.62 fp
s, 23.98 tbr, 1k tbn, 47.95 tbc
    Stream #0.1(eng): Audio: ac3, 48000 Hz, 6 channels, s16
    Metadata:
      description     : English
    Stream #0.2(eng): Subtitle: 0x0000
    Metadata:
      description     : English
[mp4 @ 0x2d80050]track 1: codec frame size is not set
Output #0, mp4, to 'Boardwalk.Empire.S01E01.mp4':
    Stream #0.0(eng): Video: libx264, yuv420p, 1280x720 [PAR 1:1 DAR 16:9], q=2-
31, 48k tbn, 23.98 tbc
    Stream #0.1(eng): Audio: ac3, 48000 Hz, 6 channels
Stream mapping:
  Stream #0.0 -> #0.0
  Stream #0.1 -> #0.1
Could not write header for output file #0 (incorrect codec parameters ?)


----------



## orangeboy

I think the problem is this:



Code:


Video #0
Codec                : MPEG-4 AVC
Codec/Info           : MPEG4 ISO advanced profile
PlayTime             : 1h 12mn
Width                : 1280 pixels
Height               : 720 pixels
Aspect ratio         : 16/9
Frame rate           : 23.976 fps

This looks like an mpeg4 video codec, and the mkv2mp4 bat only looks for compatible h264 video codecs.


----------



## sirfergy

If you have an mkv with h264 and AC3 you can use the copy flags on ffmpeg.


----------



## zabolots

sirfergy said:


> If you have an mkv with h264 and AC3 you can use the copy flags on ffmpeg.


I tried that as noted in post #22 above, but as mentioned by orangeboy, the file is not h264 but rather some MPEG4 codec.

It's strange that even the ffmpeg encoding profile used by kmttg won't work with these files. I don't understand why the MPEG4 codec in this file is so unfriendly.


----------



## tjtv

Hi,

I've been using this script successfully for a few weeks, but I've run into this problem on several files lately. It seems to crash, regardless of whether I use mp4box or mp4creator. Thanks for your help!
*
Script Output*:
eac3to v3.24
command line: "C:\Users\Tom\Downloads\mkv2mp4tivo\eac3to.exe" "Inception.2010.1080p.BluRay.DTS.x264.mkv" 1: "Inception.2010.1080p.BluRay.DTS.x264.h264" 2: "Inception.2010.1080p.BluRay.DTS.x264.ac3" -448 
------------------------------------------------------------------------------
MKV, 1 video track, 1 audio track, 2:28:08, 24p /1.001
1: h264/AVC, 1920x800 24p /1.001
2: DTS, 5.1 channels, 24 bits, 1509kbps, 48kHz
[a02] The ArcSoft and Sonic decoders don't seem to work, will use libav instead.
[v01] Extracting video track number 1...
[a02] Extracting audio track number 2...
[a02] Decoding with libav/ffmpeg...
[a02] Encoding AC3 <448kbps> with libAften...
[v01] Creating file "Inception.2010.1080p.BluRay.DTS.x264.h264"...
[a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
[a02] Clipping detected, a 2nd pass will be necessary. <WARNING>
[a02] Starting 2nd pass...
[a02] Extracting audio track number 2...
[a02] Decoding with libav/ffmpeg...
[a02] Encoding AC3 <448kbps> with libAften...
[a02] Applying -2.59dB gain...
[a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
Video track 1 contains 213097 frames.
eac3to processing took exactly 16 minutes.
Done.

Extracted audio and video tracks found.
Combining to create MP4 file...

AC3 import - sample rate 48000 - 5.1 channels
Assertion failed: nal_start, file media_tools/media_import.c, line 4244

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

*Here is the mediainfo for this file:*
General
UniqueID : 204683534229430445538714122649473598499 (0x99FC9D61897AE224A2A3F1F55A374423)
Complete name : K:\Movies\Inception (2010)\Inception.2010.1080p.BluRay.DTS.x264.mkv
Format : Matroska
File size : 14.2 GiB
Duration : 2h 28mn
Overall bit rate : 13.7 Mbps
Encoded date : UTC 2010-11-22 20:33:05
Writing application : mkvmerge v4.4.0 ('Die Wiederkehr') built on Oct 31 2010 21:52:48
Writing library : libebml v1.0.0 + libmatroska v1.0.0

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Format profile : [email protected]
Format settings, CABAC : Yes
Format settings, ReFrames : 5 frames
Muxing mode : Header stripping
Codec ID : V_MPEG4/ISO/AVC
Duration : 2h 28mn
Bit rate : 13.4 Mbps
Width : 1 920 pixels
Height : 800 pixels
Display aspect ratio : 2.40:1
Frame rate : 23.976 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Bits/(Pixel*Frame) : 0.364
Stream size : 13.9 GiB (98%)
Language : English

Audio
ID : 2
Format : DTS
Format/Info : Digital Theater Systems
Muxing mode : Header stripping
Codec ID : A_DTS
Bit rate mode : Constant
Bit rate : 32.0 Kbps
Channel(s) : 1 channel
Channel positions : Mono
Sampling rate : 0
Bit depth : 16 bits
Compression mode : Lossy
Language : English


----------



## orangeboy

tjtv said:


> Hi,
> 
> I've been using this script successfully for a few weeks, but I've run into this problem on several files lately. It seems to crash, regardless of whether I use mp4box or mp4creator. Thanks for your help!
> 
> 
> Code:
> 
> 
> [B][U]
> Script Output[/U][/B]:
> eac3to v3.24
> command line: "C:\Users\Tom\Downloads\mkv2mp4tivo\eac3to.exe"  "Inception.2010.1080p.BluRay.DTS.x264.mkv" 1: "Inception.2010.1080p.BluRay.DTS.x264.h264"   2: "Inception.2010.1080p.BluRay.DTS.x264.ac3"  -448
> ------------------------------------------------------------------------------
> MKV, 1 video track, 1 audio track, 2:28:08, 24p /1.001
> 1: h264/AVC, 1920x800 24p /1.001
> 2: DTS, 5.1 channels, 24 bits, 1509kbps, 48kHz
> [a02] The ArcSoft and Sonic decoders don't seem to work, will use libav instead.
> [v01] Extracting video track number 1...
> [a02] Extracting audio track number 2...
> [a02] Decoding with libav/ffmpeg...
> [a02] Encoding AC3 <448kbps> with libAften...
> [v01] Creating file "Inception.2010.1080p.BluRay.DTS.x264.h264"...
> [a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
> [a02] Clipping detected, a 2nd pass will be necessary.  <WARNING>
> [a02] Starting 2nd pass...
> [a02] Extracting audio track number 2...
> [a02] Decoding with libav/ffmpeg...
> [a02] Encoding AC3 <448kbps> with libAften...
> [a02] Applying -2.59dB gain...
> [a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
> Video track 1 contains 213097 frames.
> eac3to processing took exactly 16 minutes.
> Done.
> 
> Extracted audio and video tracks found.
> Combining to create MP4 file...
> 
> AC3 import - sample rate 48000 - 5.1 channels
> Assertion failed: nal_start, file media_tools/media_import.c, line 4244
> 
> This application has requested the Runtime to terminate it in an unusual way.
> Please contact the application's support team for more information.
> 
> 
> [B][U]Here is the mediainfo for this file:[/U][/B]
> General
> UniqueID                         : 204683534229430445538714122649473598499 (0x99FC9D61897AE224A2A3F1F55A374423)
> Complete name                    : K:\Movies\Inception (2010)\Inception.2010.1080p.BluRay.DTS.x264.mkv
> Format                           : Matroska
> File size                        : 14.2 GiB
> Duration                         : 2h 28mn
> Overall bit rate                 : 13.7 Mbps
> Encoded date                     : UTC 2010-11-22 20:33:05
> Writing application              : mkvmerge v4.4.0 ('Die Wiederkehr') built on Oct 31 2010 21:52:48
> Writing library                  : libebml v1.0.0 + libmatroska v1.0.0
> 
> Video
> ID                               : 1
> Format                           : AVC
> Format/Info                      : Advanced Video Codec
> Format profile                   : [email protected]
> Format settings, CABAC           : Yes
> Format settings, ReFrames        : 5 frames
> Muxing mode                      : Header stripping
> Codec ID                         : V_MPEG4/ISO/AVC
> Duration                         : 2h 28mn
> Bit rate                         : 13.4 Mbps
> Width                            : 1 920 pixels
> Height                           : 800 pixels
> Display aspect ratio             : 2.40:1
> Frame rate                       : 23.976 fps
> Color space                      : YUV
> Chroma subsampling               : 4:2:0
> Bit depth                        : 8 bits
> Scan type                        : Progressive
> Bits/(Pixel*Frame)               : 0.364
> Stream size                      : 13.9 GiB (98&#37;)
> Language                         : English
> 
> Audio
> ID                               : 2
> Format                           : DTS
> Format/Info                      : Digital Theater Systems
> Muxing mode                      : Header stripping
> Codec ID                         : A_DTS
> Bit rate mode                    : Constant
> Bit rate                         : 32.0 Kbps
> Channel(s)                       : 1 channel
> Channel positions                : Mono
> Sampling rate                    : 0
> Bit depth                        : 16 bits
> Compression mode                 : Lossy
> Language                         : English


You may want to try upgrading mp4box. I found this post where other users encountered the same (or similar) error, and this post with an apparent change to resolve the problem:



> MP4Box build has been changed today. with this build I cannot reproduce anymore the problems mentioned above. But with all the GPAC problems in the last weeks I assume we will find new (or old) problems soon.


Just curious: What happens when mp4creator is used?


----------



## tjtv

orangeboy said:


> Just curious: What happens when mp4creator is used?


*This is the error log when mp4creator is used:*
eac3to v3.24
command line: "C:\Users\Tom\Downloads\mkv2mp4tivo\eac3to.exe" "Inception.2010.1080p.BluRay.DTS.x264.mkv" 1:

"Inception.2010.1080p.BluRay.DTS.x264.h264" 2: "Inception.2010.1080p.BluRay.DTS.x264.ac3" -448 
------------------------------------------------------------------------------
MKV, 1 video track, 1 audio track, 2:28:08, 24p /1.001
1: h264/AVC, 1920x800 24p /1.001
2: DTS, 5.1 channels, 24 bits, 1509kbps, 48kHz
[a02] The ArcSoft and Sonic decoders don't seem to work, will use libav instead.
[v01] Extracting video track number 1...
[a02] Extracting audio track number 2...
[a02] Decoding with libav/ffmpeg...
[a02] Encoding AC3 <448kbps> with libAften...
[v01] Creating file "Inception.2010.1080p.BluRay.DTS.x264.h264"...
[a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
[a02] Clipping detected, a 2nd pass will be necessary. <WARNING>
[a02] Starting 2nd pass...
[a02] Extracting audio track number 2...
[a02] Decoding with libav/ffmpeg...
[a02] Encoding AC3 <448kbps> with libAften...
[a02] Applying -2.59dB gain...
[a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
Video track 1 contains 213097 frames.
eac3to processing took exactly 16 minutes.
Done.

Extracted audio and video tracks found.
Combining to create MP4 file...

AC3 import - sample rate 48000 - 5.1 channels
AVC-H264 import - frame size 1920 x 800 at 23.976 FPS
Import results: 213097 samples - Slices: 1836 I 45216 P 166045 B - 1 SEI - 1734 IDR
Stream uses B-slice references - max frame delay 2
Converting to ISMA Audio-Video MP4 file...
Saving to Inception.2010.1080p.BluRay.DTS.x264.mp4: 0.500 secs Interleaving
Error: I/O Error

Comparing source filesize: 15215333482 with output filesize: 8997294080

Generated mp4 file is within acceptable file size.
Deleting any workfil


----------



## orangeboy

tjtv said:


> *This is the error log when mp4creator is used:*
> 
> 
> Code:
> 
> 
> eac3to v3.24
> command line: "C:\Users\Tom\Downloads\mkv2mp4tivo\eac3to.exe"  "Inception.2010.1080p.BluRay.DTS.x264.mkv" 1:
> 
> "Inception.2010.1080p.BluRay.DTS.x264.h264"   2: "Inception.2010.1080p.BluRay.DTS.x264.ac3"  -448
> ------------------------------------------------------------------------------
> MKV, 1 video track, 1 audio track, 2:28:08, 24p /1.001
> 1: h264/AVC, 1920x800 24p /1.001
> 2: DTS, 5.1 channels, 24 bits, 1509kbps, 48kHz
> [a02] The ArcSoft and Sonic decoders don't seem to work, will use libav instead.
> [v01] Extracting video track number 1...
> [a02] Extracting audio track number 2...
> [a02] Decoding with libav/ffmpeg...
> [a02] Encoding AC3 <448kbps> with libAften...
> [v01] Creating file "Inception.2010.1080p.BluRay.DTS.x264.h264"...
> [a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
> [a02] Clipping detected, a 2nd pass will be necessary.  <WARNING>
> [a02] Starting 2nd pass...
> [a02] Extracting audio track number 2...
> [a02] Decoding with libav/ffmpeg...
> [a02] Encoding AC3 <448kbps> with libAften...
> [a02] Applying -2.59dB gain...
> [a02] Creating file "Inception.2010.1080p.BluRay.DTS.x264.ac3"...
> Video track 1 contains 213097 frames.
> eac3to processing took exactly 16 minutes.
> Done.
> 
> Extracted audio and video tracks found.
> Combining to create MP4 file...
> 
> AC3 import - sample rate 48000 - 5.1 channels
> AVC-H264 import - frame size 1920 x 800 at 23.976 FPS
> Import results: 213097 samples - Slices: 1836 I 45216 P 166045 B - 1 SEI - 1734 IDR
> Stream uses B-slice references - max frame delay 2
> Converting to ISMA Audio-Video MP4 file...
> Saving to Inception.2010.1080p.BluRay.DTS.x264.mp4: 0.500 secs Interleaving
> Error: I/O Error
> 
> Comparing source filesize: 15215333482 with output filesize: 8997294080
> 
> Generated mp4 file is within acceptable file size.
> Deleting any workfil


Do you have ~42.6 GiB available on your harddrive?

14.2 GiB for original .mkv file, 
14.2 GiB for extracted .h264 and .ac3 files, and
14.2 GiB for new .mp4 file
42.6 GiB free space needed.


----------



## tjtv

Thanks for your help. I cleared up some disk space, and updated to a newer version of mp4box and the script now works again!


----------



## orangeboy

tjtv said:


> Thanks for your help. I cleared up some disk space, and updated to a newer version of mp4box and the script now works again!


Good deal!

I considered having the script delete the original .mkv file after audio and video track extraction in an effort to conserve disk space, but thought better of it. I've used up all the free disk space in the past, when doing a batch of 5-10 files at once. I now only do 2-3 at a time if I'm running relatively low on space.


----------



## thekayman

Great script orangeboy... I had a few problems with mp4box crashing but went to a older ver (MP4Box-0.4.5) and it seems to be working now.. altho its stuck on Saving to blahblah.mp4: 0.500 secs Interleaving for the past 1.5 hours with a cursur flashing I'm going to wait it out to see if it moves on does this process normally take long on a 14gb mkv file?

just fyi when mp4box was crashing I tried mp4creator but it converted the 5.1 dts into 2 chan stereo, dont know if that is what its meant to do or not.

Thanks again.


----------



## orangeboy

thekayman said:


> Great script orangeboy... I had a few problems with mp4box crashing but went to a older ver (MP4Box-0.4.5) and it seems to be working now.. altho its stuck on Saving to blahblah.mp4: 0.500 secs Interleaving for the past 1.5 hours with a cursur flashing I'm going to wait it out to see if it moves on does this process normally take long on a 14gb mkv file?


Thank you!

I've never had _any_ luck with mp4box, and have used mp4creator. I just did an 8GB file that took about 45 minutes, start to finish, using mp4creator. eac3to extraction took about 13 minutes, so muxing took about 32 minutes. This was on a machine with two Pentium 4 processors running at 3GHz, and 2GB of RAM. 1.5 hours for 14GB would be a tad bit longer than expected, but not out of the question in my environment.



thekayman said:


> just fyi when mp4box was crashing I tried mp4creator but it converted the 5.1 dts into 2 chan stereo, dont know if that is what its meant to do or not.
> 
> Thanks again.


Does the file have multiple audio tracks? If so, it's possible that a 2 channel AC3 track is "scored" higher than the DTS track, if the DTS track had a lot of extra conversion to perform. 5.1 channels is scored pretty high, but bitrates or frequencies that are too high can offset that high score. That's the only possible reason I can going from 5.1 to 2.0 channels.

Also, the scoring only effects which audio track eac3to extracts. I would think that choice of muxer would make no difference in the audio channels. At least I didn't specify anything special to reduce the number of channels with either muxer's command line options. I do have eac3to reduce the number of channels to 5.1 _if_ they are 6.1 or greater.


----------



## thekayman

mp4box was still going this morning so I killed it and am trying again.

The extracted audio is showing 6 channels (5.1) but the output file after mp4creator only shows 2 channels.. any ideas or what I could try?

I'll also see how mp4box goes a second time round... I have a C2D E6600 (2.4Ghz) so it should in theory be quicker then on your setup you would think.


----------



## orangeboy

thekayman said:


> mp4box was still going this morning so I killed it and am trying again.
> 
> The extracted audio is showing 6 channels (5.1) but the output file after mp4creator only shows 2 channels.. any ideas or what I could try?
> 
> I'll also see how mp4box goes a second time round... I have a C2D E6600 (2.4Ghz) so it should in theory be quicker then on your setup you would think.


I haven't touched the script in months, but I do have a version that I could implement some rudimentary logging to provide a synopsis of what's going on. The problem with Windows batch is that commands cannot be piped to two destinations at the same time; it's either to the console (command window) or a file. I could capture everything to a file initially and then "type" the file to the console, but then you'd be looking at nothing until the command actually finished. So in your case, you wouldn't even be able to see if mp4box was actually executing! I had contemplated porting the script to python, but that would not be done quickly.

In the meantime, can you execute eac3to on just the .mkv file by issuing the command:

"\your\path\to\eac3to.exe" "\your\path\to\the.mkv.file"

in a command prompt, where both "\your\path\to\" and "the.mkv.file" are filled in appropriately, and post the results?


----------



## tjtv

I have one other question, now that I've been using this script successfully. 

The created mp4 file plays perfectly on the tivo, but when I play it on the computer(using windows media player), I don't get any sound. Any idea why this is happening?

Thanks again for all your help, and for providing this incredibly useful script!


----------



## orangeboy

tjtv said:


> I have one other question, now that I've been using this script successfully.
> 
> The created mp4 file plays perfectly on the tivo, but when I play it on the computer(using windows media player), I don't get any sound. Any idea why this is happening?
> 
> Thanks again for all your help, and for providing this incredibly useful script!


I would guess that WMP doesn't know about the AC3 codec. Downloading a codec pack would probably fix the issue, but I'm personally concerned with security with some of the installers, having received a virus or two in the past.

That being said, I highly recommend using VideoLan's VLC media player. It comes with it's own codecs, and plays nearly everything thrown at it.


----------



## thekayman

Hi Orangeboy,
I ran eac3to.exe on the mkv file and here are the results
MKV, 1 video track, 1 audio track, 2:08:45, 24p /1.001
1: h264/AVC, English, 1920x800 24p /1.001
2: DTS, English, 5.1 channels, 24 bits, 1509kbps, 48kHz
"DTS 5.1 @ 1.5 Mbps"

During the process of your script as it separates the files i can see the ac3 Audio file and it does contain the 5.1 audio but once mp4creator finishes the resulting mp4 file only has 2 channel which is strange.
mp4box just keeps crashing on me so I cannot use that even to test unfortunately.

I suppose if we can output results to screen and put a pause at the end so I can copy paste results that might work?


----------



## orangeboy

thekayman said:


> Hi Orangeboy,
> I ran eac3to.exe on the mkv file and here are the results
> MKV, 1 video track, 1 audio track, 2:08:45, 24p /1.001
> 1: h264/AVC, English, 1920x800 24p /1.001
> 2: DTS, English, 5.1 channels, 24 bits, 1509kbps, 48kHz
> "DTS 5.1 @ 1.5 Mbps"
> 
> During the process of your script as it separates the files i can see the ac3 Audio file and it does contain the 5.1 audio but once mp4creator finishes the resulting mp4 file only has 2 channel which is strange.
> mp4box just keeps crashing on me so I cannot use that even to test unfortunately.
> 
> I suppose if we can output results to screen and put a pause at the end so I can copy paste results that might work?


At line 287 (about 1/3 of the way down) is a statement:



Code:


:Cleanup
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: In this section, file existence logic is used to determine if an output   ::
:: file has been successfully created. If it has, the output file's size is  ::
...

Adding a pause after that will stop the script immediately after muxing the files, and before deleting any of the "work" files:



Code:


:Cleanup
PAUSE
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: In this section, file existence logic is used to determine if an output   ::
:: file has been successfully created. If it has, the output file's size is  ::
...


----------



## thekayman

Hi Orangeboy, thanks for the assistance... below is the info that was in the screen before the pause

Opening the files in KMplayer and selecting media info...
the .MKV shows DTS 6 Channels with the right channel positions
the extracted .AC3 shows AC-3 6 channels with the right channel positions
the .mp4 shows AC-3 Channel0 (and is only stereo) and doesnt show any channel positions



Code:


Gathering file information. Please wait...

Input file information:
-----------------------
1: h264/AVC, English, 1920x800 24p /1.001

2: DTS, English, 5.1 channels, 24 bits, 1509kbps, 48kHz



Video and audio codecs are compatible.
Starting extraction process...

MKV, 1 video track, 1 audio track, 2:08:45, 24p /1.001
1: h264/AVC, English, 1920x800 24p /1.001
2: DTS, English, 5.1 channels, 24 bits, 1509kbps, 48kHz
   "DTS 5.1 @ 1.5 Mbps"
a02 The ArcSoft and Sonic decoders don't seem to work, will use libav instead.
v01 Extracting video track number 1...
a02 Extracting audio track number 2...
a02 Decoding with libav/ffmpeg...
a02 Encoding AC3 <448kbps> with libAften...
v01 Creating file "videoname.h264"...
a02 Creating file "videoname.ac3"...
a02 Clipping detected, a 2nd pass will be necessary.
a02 Starting 2nd pass...
a02 Extracting audio track number 2...
a02 Decoding with libav/ffmpeg...
a02 Encoding AC3 <448kbps> with libAften...
a02 Applying -1.32dB gain...
a02 Creating file "videoname.ac3"...
Video track 1 contains 185206 frames.
eac3to processing took 14 minutes, 11 seconds.
Done.

Extracted audio and video tracks found.
Combining to create MP4 file...

Error decoding sei message
Press any key to continue . . .


----------



## orangeboy

thekayman said:


> Hi Orangeboy, thanks for the assistance... below is the info that was in the screen before the pause
> 
> Opening the files in KMplayer and selecting media info...
> the .MKV shows DTS 6 Channels with the right channel positions
> the extracted .AC3 shows AC-3 6 channels with the right channel positions
> the .mp4 shows AC-3 Channel0 (and is only stereo) and doesnt show any channel positions
> 
> 
> 
> Code:
> 
> 
> Gathering file information. Please wait...
> 
> Input file information:
> -----------------------
> 1: h264/AVC, English, 1920x800 24p /1.001
> 
> 2: DTS, English, 5.1 channels, 24 bits, 1509kbps, 48kHz
> 
> 
> 
> Video and audio codecs are compatible.
> Starting extraction process...
> 
> MKV, 1 video track, 1 audio track, 2:08:45, 24p /1.001
> 1: h264/AVC, English, 1920x800 24p /1.001
> 2: DTS, English, 5.1 channels, 24 bits, 1509kbps, 48kHz
> "DTS 5.1 @ 1.5 Mbps"
> a02 The ArcSoft and Sonic decoders don't seem to work, will use libav instead.
> v01 Extracting video track number 1...
> a02 Extracting audio track number 2...
> a02 Decoding with libav/ffmpeg...
> a02 Encoding AC3 <448kbps> with libAften...
> v01 Creating file "videoname.h264"...
> a02 Creating file "videoname.ac3"...
> a02 Clipping detected, a 2nd pass will be necessary.
> a02 Starting 2nd pass...
> a02 Extracting audio track number 2...
> a02 Decoding with libav/ffmpeg...
> a02 Encoding AC3 <448kbps> with libAften...
> a02 Applying -1.32dB gain...
> a02 Creating file "videoname.ac3"...
> Video track 1 contains 185206 frames.
> eac3to processing took 14 minutes, 11 seconds.
> Done.
> 
> Extracted audio and video tracks found.
> Combining to create MP4 file...
> 
> Error decoding sei message
> Press any key to continue . . .


Unfortunately, there's still nothing that jumps out at me as to why mp4creator would be down-mixing to stereo. It looks like mp4creator can create debug messages by using a '-verbose=" switch. Changing line 279 to include that switch may shed some light:

Old:


Code:


	IF EXIST %VideoTrackName% (
		IF EXIST %AudioTrackName% (
			ECHO.
			ECHO Extracted audio and video tracks found.
			ECHO Combining to create MP4 file...
			ECHO.
			GOTO %Muxer%
			:mp4creator
			%mp4creatorPath% -create=%VideoTrackName% -rate=%vfps% -timescale=%vtimescale% -optimize -use64bits -mpeg4-video-profile=4.1 %OutputFullName% >>CON 2>&1
			%mp4creatorPath% -create=%AudioTrackName% -optimize %OutputFullName% >>CON 2>&1
			GOTO Cleanup

New:


Code:


	IF EXIST %VideoTrackName% (
		IF EXIST %AudioTrackName% (
			ECHO.
			ECHO Extracted audio and video tracks found.
			ECHO Combining to create MP4 file...
			ECHO.
			GOTO %Muxer%
			:mp4creator
			%mp4creatorPath% -create=%VideoTrackName% -rate=%vfps% -timescale=%vtimescale% -optimize -use64bits -mpeg4-video-profile=4.1 %OutputFullName% >>CON 2>&1
			%mp4creatorPath% -create=%AudioTrackName% -optimize %OutputFullName% -verbose=1 >>CON 2>&1
			GOTO Cleanup

The above sets the debugging level to 1, which I assume produces the least amount of debugging messages. It may be a tedious task, but running the batch several times increasing the verbosity may be needed to get the messages needed.

The only thought/theory I have is that the channels are seen as being out of order. I found this table that shows a slight difference between AC3 and DTS mappings:



Code:


Format		Chan 0	Chan 1	Chan 2	Chan 3	Chan 4	Chan 5
5.1 WAV		FL	FR	FC	LFE	SL	SR
5.1 AC3		FL	FC	FR	SL	SR	LFE
5.1 DTS		FC	FL	FR	SL	SR	LFE
5.1 AAC		FC	FL	FR	SL	SR	LFE
5.1 AIFF	FL	SL	FC	FR	SR	LFE

FL : Front Left
FC : Front Center
FR : Front Right
SL : Surround Left
SR : Surround Right
LFE : Low Frequency Effects (Sub)

I'm not putting too much faith in that theory, since I believe that labels like "FL" or "FC" are for the benefit of human understanding, and having incorrect mappings would only result in all channels still being present, but the sound being incorrect for the listener...


----------



## thekayman

I set verbose to 1 and got a whole heap of stuff (attached as text file)

dont know if that helps in anyway I couldnt see any info about text although there was prob more info above but i didnt have a big enough buffer i think.


----------



## rfryar

Just a quick change for those using MP4Box. For some reason it will default to using ISOM as the Major Brand. This is never supposed to be used as the Major Brand according to the specs.

While I had this running fine for a number of months, once I started to use a program called MetaX to add image metadata to my movies the TiVo refused to recognize the files. I believe this was due to the invalid Major Brand tag. I have since updated this script to change MP4box to add:



Code:


-brand mp42

This has resolved the tagged files from playing correctly on my TiVos. I am also going to look into MP4creator to see if it has similar issues.

Rick


----------



## orangeboy

rfryar said:


> Just a quick change for those using MP4Box. For some reason it will default to using ISOM as the Major Brand. This is never supposed to be used as the Major Brand according to the specs.
> 
> While I had this running fine for a number of months, once I started to use a program called MetaX to add image metadata to my movies the TiVo refused to recognize the files. I believe this was due to the invalid Major Brand tag. I have since updated this script to change MP4box to add:
> 
> 
> 
> Code:
> 
> 
> -brand mp42
> 
> This has resolved the tagged files from playing correctly on my TiVos. I am also going to look into MP4creator to see if it has similar issues.
> 
> Rick


Thanks Rick! Since I've never had any luck using mp4box, I've not explored all the options available. Input from folks like you is greatly appreciated!

Edit: Have you tried


Code:


-brand avc1

 as well? I only ask because mediainfo tends to report "avc1" quite often with mkv files...


----------



## boredsox38

I have been looking for a tool like this for sometime now. I am happy to find. I ran my first MKV file this morning using mp4box. It resulted in two diff files, an ac3 file and an .h264 file. How do I get both of these combined to mp4? Did I miss a step here? Thanks for you help and thanks for working on the program.


----------



## ajayabb

boredsox38 said:


> I have been looking for a tool like this for sometime now. I am happy to find. I ran my first MKV file this morning using mp4box. It resulted in two diff files, an ac3 file and an .h264 file. How do I get both of these combined to mp4? Did I miss a step here? Thanks for you help and thanks for working on the program.


Interested to hear the answer as well. I have gotten this hiccup on a few of my MKV files while others have been fine.


----------



## orangeboy

Tried replying earlier and wasn't successful (web page not available?!). Anyway, I can only suggest trying mp4creator. I've _never_ had luck with mp4box, so I can't make recommendations for making it work.


----------



## xyth

boredsox38 said:


> I have been looking for a tool like this for sometime now. I am happy to find. I ran my first MKV file this morning using mp4box. It resulted in two diff files, an ac3 file and an .h264 file. How do I get both of these combined to mp4? Did I miss a step here? Thanks for you help and thanks for working on the program.


Sounds like eac2to.exe is extracting the video and sound from the .mkv, but mp4box isn't running so they are put back into the mp4 container. My first guess is you didn't get the path to the mp4box.exe file correct, so it is aborting the batch file. Open your mkv2tivomp4.ini file and confirm you have the path correct. It should look like this at the very end of the file:

SET Muxer=mp4box
SET mp4creatorPath="."
SET mp4boxPath="C:\yourdirectory\mkv2mp4\MP4Box.exe"
GOTO :EOF

yourdirectory path is whatever leads you to the mkv2mp4 folder you created per the installation instructions.

mp4box works fine for me, and I have used it for years in another batch file with a different extraction program. Good luck.


----------



## orangeboy

xyth said:


> Sounds like eac2to.exe is extracting the video and sound from the .mkv, but mp4box isn't running so they are put back into the mp4 container. My first guess is you didn't get the path to the mp4box.exe file correct, so it is aborting the batch file. Open your mkv2tivomp4.ini file and confirm you have the path correct. It should look like this at the very end of the file:
> 
> SET Muxer=mp4box
> SET mp4creatorPath="."
> SET mp4boxPath="C:\yourdirectory\mkv2mp4\MP4Box.exe"
> GOTO :EOF
> 
> yourdirectory path is whatever leads you to the mkv2mp4 folder you created per the installation instructions.
> 
> mp4box works fine for me, and I have used it for years in another batch file with a different extraction program. Good luck.


Very good advice! :up:
Also look at the end of the batch file besides the .ini file. The .ini file is only used to aid in the setup when a new version is released (it's been pretty dormant of late though).


----------



## xyth

I too started having a few crashes with MP4Box, so after a few hours of debugging I offer a few suggestions that seemed to solve what might be more than one problem causing these crashes or non-writes. First, add the switch -new to the line where the mkv2tivomp4 batch file writes out the final file. Its the line above the cleanup section, and mine now looks like this:



Code:


&#37;mp4boxPath% -add %VideoTrackName%:fps=%vfps% -add %AudioTrackName% -new %OutputFullName% -isma >>CON 2>&1

That forces the creation of a new file, which seemed to the batch from blowing up at the beginning of the file output.

Another issue is that I have found a lot of different builds of mp4box out there, even for a given version. Some versions compile in the needed dependencies into the .exe file, others require you add a few other dependence files (.dll and .patch) into the same directory as the mp4box.exe file. If you mix up the different versions of these dependencies, it will give you other errors.

You can get the source code yourself and build a stable version, or if your lazy like me grab a version used in a current project on Sourceforge. I am using the files contained in the latest version of the Srtiphone project which can be found on Sourceforge. If your lost, search for Mp4box on Sourceforge and it will show you where the Srtiphone project is.

Anyway, good luck, and thank to Orangeboy for this fine batch file.


----------



## orangeboy

xyth said:


> I too started having a few crashes with MP4Box, so after a few hours of debugging I offer a few suggestions that seemed to solve what might be more than one problem causing these crashes or non-writes. First, add the switch -new to the line where the mkv2tivomp4 batch file writes out the final file. Its the line above the cleanup section, and mine now looks like this:
> 
> 
> 
> Code:
> 
> 
> %mp4boxPath% -add %VideoTrackName%:fps=%vfps% -add %AudioTrackName% -new %OutputFullName% -isma >>CON 2>&1
> 
> That forces the creation of a new file, which seemed to the batch from blowing up at the beginning of the file output.


Thanks for sharing your findings! Any mp4box tweaks definitely helps.



xyth said:


> Another issue is that I have found a lot of different builds of mp4box out there, even for a given version. Some versions compile in the needed dependencies into the .exe file, others require you add a few other dependence files (.dll and .patch) into the same directory as the mp4box.exe file. If you mix up the different versions of these dependencies, it will give you other errors.
> 
> You can get the source code yourself and build a stable version, or if your lazy like me grab a version used in a current project on Sourceforge. I am using the files contained in the latest version of the Srtiphone project which can be found on Sourceforge. If your lost, search for Mp4box on Sourceforge and it will show you where the Srtiphone project is.


Yeah, I link to a specific site for mp4box to keep the experience a simple as possible. For those adventurous enough to build there own can do so; but *I* personally would rather not get involved with trying to troubleshoot mp4box of many different builds. If there's a definitive, stable build found to work better than whatever source I'm linking to (kurtnoise build I think?), I'll happily adjust the links, and suggest using that instead. I've set my local copy of mkv2mp4 to always use mp4creator after several unsuccessful attempts at using mp4box, so I am a bit out of my element with the latter.



xyth said:


> Anyway, good luck, and thank to Orangeboy for this fine batch file.


I'm happy to share what I can!


----------



## xyth

I have been playing with the mp4creator option, and I agree it seems more stable. I do get an error when mp4creator combines to create the mp4 file. The error is: "Error decoding sei message". The resulting file seems to work well though, and I think the error happens because the output files were over 4 gigs.


----------



## orangeboy

xyth said:


> I have been playing with the mp4creator option, and I agree it seems more stable. I do get an error when mp4creator combines to create the mp4 file. The error is: "Error decoding sei message". The resulting file seems to work well though, and I think the error happens because the output files were over 4 gigs.


I've never found a good explanation for the "Error decoding sei message". I've ignored it. There appears to have been a patch created, but the link is 404.


----------



## philhu

orangeboy said:


> I've never found a good explanation for the "Error decoding sei message". I've ignored it. There appears to have been a patch created, but the link is 404.


The location is no longer 404.

It is a pointer in another forum. Go look!


----------



## orangeboy

philhu said:


> The location is no longer 404.
> 
> It is a pointer in another forum. Go look!


Sorry - I should have said the _resulting (patch)_ link is 404.


----------



## sirfracas

. . Orangeboy. My wife finally became so frustrated with all the .mkv files having corrupt audio she waved her hand imperiously at me the other day and said, "Do some of that IT voodoo you do and fix the issue."

Happy wife, happy life.

P.S. I used MP4Box-0.4.6-rev2735 for those scoring at home and so far no issues.


----------



## vincejose

Just wanted to say thanks for the tool, I've used it on a couple files and it's worked beautifully.


----------



## orangeboy

vincejose said:


> Just wanted to say thanks for the tool, I've used it on a couple files and it's worked beautifully.


I happy to hear it!


----------



## orangeboy

I just discovered that mkv2TiVomp4 also works on (compatible) m2ts files as well. eac3to has no problems extracting the proper audio and video tracks found in the ts container. This may have been common knowledge, but I hadn't opportunity to try until just recently.


----------



## MrJedi

Been using this with mp4creator the last two days with no issues. Thanks for the .bat and the Send To instructions


----------



## orangeboy

Glad to hear it!


----------



## Mikey_C

Just got mk2Tivomp4 and I'm using it with Streambaby. The only issue I'm having is that any 720p video that is less than exactly 1280x720 (1280x538, for example) gets downrezzed to 480i by the Tivo. I found an explanation on the Streambaby wiki that says its a bug in the way Tivo processes h264 video. My question is, is there any way to add some code to this batch file so if the file is less than 1280x720 it can "pad" it out to 1280x720?


----------



## orangeboy

Mikey_C said:


> Just got mk2Tivomp4 and I'm using it with Streambaby. The only issue I'm having is that any 720p video that is less than exactly 1280x720 (1280x538, for example) gets downrezzed to 480i by the Tivo. I found an explanation on the Streambaby wiki that says its a bug in the way Tivo processes h264 video. My question is, is there any way to add some code to this batch file so if the file is less than 1280x720 it can "pad" it out to 1280x720?


It's unlikely that a feature like that will get directly added. eac3to, mp4creator nor mp4box have options (that I can find) to manipulate the video size, so an additional tool (or tools) would need to be incorporated. Adding in another tool like ffmpeg to do the padding could introduce additional support issues as well; some ffmpeg builds use options like -padtop and -padbottom, while others use -vf pad= option. I like hearing people say "it works!", and not saying "it's broke!" 

But... Are you doing any user post-processing commands/programs automatically with the batch? It was one of the last steps in the setup dialog. I could *maybe* come up with an add-on that would do what you're looking for. I think I've got a handle on invoking MediaInfo to get video attibutes, so coupling that information with something like ffmpeg or mencoder may produce the desired results.


----------



## Mikey_C

I just did a little experiment using ffmpeg. The only way to resize it to 1280 x 720 is to re-encode it.. vcopy won't do it. <bummer>


----------



## orangeboy

Mikey_C said:


> I just did a little experiment using ffmpeg. The only way to resize it to 1280 x 720 is to re-encode it.. vcopy won't do it. <bummer>


Hmm... found this command line:



Code:


ffmpeg -i input.avi  -padtop 120  -padbottom 120  -padcolor 000000  output.avi

It's curiously absent of *any* codec information. But it is a Linux distribution ffmpeg command line. I'm not sure if the Win32 versions would work. Could you try this on one of your 1280x538 videos?



Code:


ffmpeg -i some.file.in.mp4  -padtop 90  -padbottom 92  -padcolor 000000  some.file.out.mp4


----------



## txporter

I am pretty sure that you will need a full re-encode since you are trying to add data to each frame. See this post on a ubuntu forum about ffmpeg with pad options.


----------



## jcthorne

Did you ever find a solution to mkv's with AAC audio? I tried placing neroaacdec.exe in the same folder with the bat and eac32 and the bat closes before I can read the error message but it does not extract the tracks.

Been a while since I used this. I had gotten away from it because of the 720p video bug in TivoHD but no longer have that issue with the Premiere. Also have a large number of files I'd like to convert so doing them one at a time in meGUI is tedious at best. Thanks!


----------



## orangeboy

jcthorne said:


> Did you ever find a solution to mkv's with AAC audio? I tried placing neroaacdec.exe in the same folder with the bat and eac32 and the bat closes before I can read the error message but it does not extract the tracks.
> 
> Been a while since I used this. I had gotten away from it because of the 720p video bug in TivoHD but no longer have that issue with the Premiere. Also have a large number of files I'd like to convert so doing them one at a time in meGUI is tedious at best. Thanks!


Unfortunately, no. I've got a script that invokes mediainfo, ffmpeg and x264 that handles everything but mkv and mp4 to make a TiVo compatible h264/AC3/mp4 file. I've been meaning to do a bit more mediainfo processing to get detailed h264 information such as ref-frames, but time hasn't allowed me to expand that script further, otherwise I'd share it with the Community.


----------



## enclave000

thanks


----------



## jcthorne

Any way we (I) could persuade you to update the routine to handle mkvs that contain aac audio? eac3to.exe now does the extraction/conversion to ac3. At least it can from within meGUI. Would sure be great to be able to run these web downloads through your batch file for tivo.


----------



## tgrim1

2 comments/questions...

1. Im having trouble with several mkv's that have 2 channel AAC, here is one of them...



Code:


Video
ID                               : 1
Format                           : AVC
Format/Info                      : Advanced Video Codec
Format profile                   : [email protected]
Format settings, CABAC           : Yes
Format settings, ReFrames        : 4 frames
Codec ID                         : V_MPEG4/ISO/AVC
Duration                         : 1h 15mn
Nominal bit rate                 : 633 Kbps
Width                            : 1 280 pixels
Height                           : 496 pixels
Display aspect ratio             : 2.581
Frame rate                       : 23.976 fps
Color space                      : YUV
Chroma subsampling               : 4:2:0
Bit depth                        : 8 bits
Scan type                        : Progressive
Bits/(Pixel*Frame)               : 0.042
Writing library                  : x264 core 80 r1376M 3feaec2
Encoding settings                : cabac=1 / ref=4 / deblock=1:-1:-1 / analyse=0x3:0x113 / me=umh / subme=5 / psy=1 / psy_rd=0.0:0.0 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=2 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=6 / sliced_threads=0 / nr=0 / decimate=1 / mbaff=0 / constrained_intra=0 / bframes=3 / b_pyramid=0 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=1 / wpredp=2 / keyint=250 / keyint_min=25 / scenecut=40 / rc_lookahead=40 / rc=2pass / mbtree=1 / bitrate=633 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / vbv_maxrate=50000 / vbv_bufsize=50000 / ip_ratio=1.40 / aq=1:1.00

Audio
ID                               : 2
Format                           : AAC
Format/Info                      : Advanced Audio Codec
Format profile                   : HE-AAC / LC
Codec ID                         : A_AAC
Duration                         : 1h 15mn
Channel(s)                       : 2 channels
Channel positions                : Front: L R
Sampling rate                    : 48.0 KHz / 24.0 KHz
Compression mode                 : Lossy

2. Is there a way to have a watched folder that the batch file will autoprocess when an mkv is there? (I use streambaby to watch my DL'd shows and want to use a type of SABnzbd/Sickbeard type setup to automate it)


----------



## Soapm

Do a search for a free program called Handbrake. Trust me, you won't look back...

http://handbrake.fr/downloads.php


----------



## ajayabb

Soapm said:


> Do a search for a free program called Handbrake. Trust me, you won't look back...
> 
> http://handbrake.fr/downloads.php


Handbrake is a great program but I think rather than demux the h.264 video in the .mkv container, Handbrake will reencode the entire file to .mp4


----------



## jcthorne

for files that mkv2tivomp4.bat will not handle, I use meGUI. It can demux the mkv, recode incompatible audio only and remux into an IMSA standard Mp4. Handles many codecs that the bat file does not but not nearly as easy to use. It can also recode the video when necessary.


----------

