Giter Club home page Giter Club logo

mkvdts2ac3's Introduction

mkvdts2ac3 is a bash script which can be used for converting the DTS in Matroska (MKV) files to AC3. It provides you with a healthy set of options for controlling the resulting file.

Installation

Prerequisites

Make sure the executables for the following libraries are accessible.

  1. mkvtoolnix - Matroska tools
  2. ffmpeg - Audio conversion tool
  3. rsync - File transfer and synchronization

Note: If you are a Mac OS X user you may need to compile these libraries.

Installation

If you have git installed, you can just run git clone git://github.com/JakeWharton/mkvdts2ac3.git.

You can download the script directly with wget or curl: wget https://raw.github.com/JakeWharton/mkvdts2ac3/master/mkvdts2ac3.sh -or- curl -O https://raw.github.com/JakeWharton/mkvdts2ac3/master/mkvdts2ac3.sh

Otherwise you can click the "Download" link on the GitHub project page and download an archive and extract its contents.

Optional: If you want easy access to the script from any directory you can copy or symlink the mkvdts2ac3.sh file to a directory in your PATH variable or else append the script's directory to the PATH variable.

Usage

This script was designed to be very simple and will automatically convert the first DTS track it finds in a Matroska file to AC3 and append it when run without any arguments. Since this was the most common scenario for the developer it is the default action. mkvdts2ac3.sh Some.Random.Movie.mkv

For users who wish to change the behavior there are a variety of options which control various aspects of the script. Here is the output of the --help argument.

mkvdts2ac3-1.5.3 - by Jake Wharton <[email protected]> and
                      Chris Hoekstra <[email protected]>

Usage: mkvdts2ac3.sh [options] <filename>
Options:
     -c TITLE,        Custom AC3 track title.
     --custom TITLE
     -d, --default    Mark AC3 track as default.
     -e, --external   Leave AC3 track out of file. Does not modify the
                      original matroska file. This overrides '-n' and
                      '-d' arguments.
     -f, --force      Force processing when AC3 track is detected
     -i, --initial    New AC3 track will be first in the file.
     -k, --keep-dts   Keep external DTS track (implies '-n').
     -m, --nocolor    Do not use colors (monotone).
     --md5            Perform MD5 comparison when copying across drives.
     -n, --no-dts     Do not retain the DTS track.
     --new            Do not copy over original. Create new adjacent file.
     -p PRIORITY      Modify niceness of executed commands.
     -s MODE,
     --compress MODE  Apply header compression to streams (See mkvmerge's --compression).
     -t TRACKID,
     --track TRACKID  Specify alternate DTS track.
     -w FOLDER,
     --wd FOLDER      Specify alternate temporary working directory.

     --test           Print commands only, execute nothing.
     --debug          Print commands and pause before executing each.

     -h, --help       Print command usage.
     -v, --verbose    Turn on verbose output
     -V, --version    Print script version information.

User Defaults

If you find yourself constantly using the same settings, you can create a configuration file to automatically set them. Copy the following to ~/.mkvdts2ac3.rc and uncomment whichever lines you wish.

#EXTERNAL=1
#NODTS=1
#KEEPDTS=1
#DEFAULT=1
#FORCE=1
#INITIAL=1
#NOCOLOR=1
#MD5=1
#NEW=1
#PRIORITY=0
#DTSTRACK=
#DTSNAME=
#COMP="none"

(Note: If EXTERNAL is set then NODTS and KEEPDTS should not be used. AUDIOMODE is the -o-flag value passed to aften. PRIORITY is the niceness value. DTSNAME is custom title for new AC3 track.)

Examples

Keep only the new AC3 track, discarding the original DTS

mkvdts2ac3.sh -n Some.Random.Movie.mkv

Specify an alternate directory to use for the temporary files. This can be useful when the partition your /tmp directory on is tiny.

mkvdts2ac3.sh -w /mnt/bigHDD Some.Random.Movie.mkv

Convert a different DTS track rather than the first one sequentially in the file. This will require you to check the output of a command like mkvmerge -i Some.Random.Movie.mkv which will give you the track ids of each file.

mkvdts2ac3.sh -t 4 Some.Random.Movie.mkv

If you want to retain the DTS track in an alternate location you can instruct the script not to delete it after the conversion.

mkvdts2ac3.sh -k Some.Random.Movie.mkv

If you want to keep the original file untouched (such as if you are still seeding it in a torrent) and your player supports external audio tracks you can choose to leave the converted AC3 track out of the file.

mkvdts2ac3.sh -e Some.Random.Movie.mkv

All of these examples only showcase the use of a single argument but they can be combined to achieve the desired result.

mkvdts2ac3.sh -d -t 3 -w /mnt/media/tmp/ Some.Random.Movie.mkv

If you're unsure of what any command will do run it with the --test argument to display a list of command execute. You can also use the --debug argument which will print out the commands and wait for the user to press the return key before running each.

$ ./mkvdts2ac3.sh --test -d -t 3 -w /mnt/media/tmp Some.Random.Movie.mkv

mkvdts2ac3-1.5.3 - by Jake Wharton <[email protected]> and
                      Chris Hoekstra <[email protected]>

MKV FILE: Some.Random.Move.mkv
DTS FILE: /mnt/media/tmp/Some.Random.Movie.dts
AC3 FILE: /mnt/media/tmp/Some.Random.Movie.ac3
TIMECODE: /mnt/media/tmp/Some.Random.Movie.tc
NEW FILE: /mnt/media/tmp/Some.Random.Movie.new.mkv
WORKING DIRECTORY: /mnt/media/tmp
Checking to see if DTS track specified via arguments is valid.
> mkvmerge -i "Some.Random.Movie.mkv" | grep "Track ID 3: audio (A_DTS)"

Extract track information for selected DTS track.
> mkvinfo "Some.Random.Movie.mkv" | grep -A 25 "Track number: 3"

Extract language from track info.
> echo "INFO" | grep -m 1 "Language" | cut -d " " -f 5

Extract name for selected DTS track. Change DTS to AC3 and update bitrate if present.
> echo "INFO" | grep -m 1 "Name" | cut -d " " -f 5- | sed "s/DTS/AC3/" | awk '{gsub(/[0-9]+(\.[0-9]+)?(M|K)bps/,"448Kbps")}1'

Extract timecode information for the audio track.
> mkvextract timecodes_v2 "Some.Random.Movie.mkv" 3:"/mnt/media/tmp/Some.Random.Movie.tc"
> sed -n "2p" "/mnt/media/tmp/Some.Random.Movie.tc"
> rm -f "/mnt/media/tmp/Some.Random.Movie.tc"

Extract DTS file from MKV.
> mkvextract tracks "Some.Random.Movie.mkv" 3:"/mnt/media/tmp/Some.Random.Movie.dts"
Converting DTS to AC3.
> ffmpeg -i "/mnt/media/tmp/Some.Random.Movie.dts" -acodec ac3 -ac 6 -ab 448k "/mnt/media/tmp/Some.Random.Movie.ac3"

Running main remux.
> nice -n 0 mkvmerge -q -o "/mnt/media/tmp/Some.Random.Movie.new.mkv" --compression 1:none "Some.Random.Movie.mkv" --default-track 0 --language     0:DTSLANG --track-name 0:"DTSNAME" --sync 0:DELAY --compression 0:none "/mnt/media/tmp/Some.Random.Movie.ac3"
Removing temporary AC3 file.
> rm -f "/mnt/media/tmp/Some.Random.Movie.ac3"

Copying new file over the old one.
> cp "/mnt/media/tmp/Some.Random.Movie.new.mkv" "Some.Random.Movie.mkv"

Remove working file.
> rm -f "/mnt/media/tmp/Some.Random.Movie.new.mkv"

Developed By

Git repository located at github.com/JakeWharton/mkvdts2ac3

Very Special Thanks

  • Philipp Winkler - Munich, Germany
  • Paul Tilley
  • Paulo Ferreira
  • Douglas Carter

Thanks

The following people contributed useful thoughts or code to mkvdts2ac3:

  • John Nilsson - Dependency, file, and space checking as well as general bash formatting.
  • crimsdings - General debugging and error resolution.
  • Vladimir Berezhnoy - Feature to copy track name from DTS.
  • Ricardo Capurro - Bug reporting on uncommon uses.
  • Tom Flanagan - Idea for downmixing support.
  • lgringo - Suggestion to copy audio track delay.
  • Huss - Suggestion of ability to set niceness.
  • Florian Beverborg - Suggestion of --new argument to leave original untouched.
  • Daniele Nicolucci - df portability fixes.
  • Florian Coulmier - Bug reports and patches.
  • NameLessJedi - Header compression disabling suggestion.
  • d4nyl0 - Transition to ffmpeg
  • n-i-x - Progress display on file copy

And to everyone who submitted bug reports through email and on networkedmediatank.com!

License

Copyright 2011 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

mkvdts2ac3's People

Contributors

adereis avatar choekstr avatar jakewharton avatar mihaic avatar non7top avatar tmchow avatar treppo avatar u2ix avatar wbotelhos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mkvdts2ac3's Issues

Won't convert main DTS track, due to commentary AC3.

Under the new script, it will quit if any AC3 tracks are detected, instead of converting any DTS tracks it finds.

For instance, I have a video here with a DTS track for the main audio, and then an AC3 track for commentary, and it gives the "There is already AC3" message and stops.

(I've reverted to version 1.0.2 which I know does not have this problem)

'back to du' issues

du is just a flawed tool altogether. I looked at the stat manpage but there isn't anything I can find that would be cross platform.
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/stat.1.html

Here is what I get using du and what is causing the script to fail with using du:
EXT3 filesystem:
du -k Cool_Hand_Luke.avi
1321452 Cool_Hand_Luke.avi
md5sum Cool_Hand_Luke.avi
a0e94fceaf9b0c69ca70fdc058d1aa85 Cool_Hand_Luke.avi
vs
ReiserFS filesystem:
du -k Cool_Hand_Luke.avi
1321445 Cool_Hand_Luke.avi
md5sum Cool_Hand_Luke.avi
a0e94fceaf9b0c69ca70fdc058d1aa85 Cool_Hand_Luke.avi

ls -s is no better.
EXT3 filesystem:
ls -s /tmp/Cool_Hand_Luke.avi
1321452 /tmp/Cool_Hand_Luke.avi
ReiserFS filesystem:
ls -s Cool_Hand_Luke.avi
1321445 Cool_Hand_Luke.avi

How about:
stat |grep Size|awk '{print $2}'

does that work on Mac OS/X? I don't have a mac system to try it on but hopefully that will return a filesize in there that we can use?

Normalize AC3 sound

consider to use the -dnorm switch for aften. Sometimes the output ac3 sound is too quiet/low.
(possible value is 27, so : "-dnorm 27" should be set as a parameter for aften.)

Locales other than en_US break mkvinfo language parsing

Hi Jake,

i have a small improvement for the mkvdts2ac3 script. If you have another locale then en on your machine (mine is de_DE) the script can not get the language information from mkvinfo.

The simplest way is to add the following lines to the script:
unset LANG
unset LC_ALL

./mkvdts2ac3.sh: line 505: [: -eq: unary operator expected

mkvdts2ac3-1.5.4 - by Jake Wharton [email protected] and
Chris Hoekstra [email protected]

Extracting Timecodes:
Progress: 100%
Timecode extraction took: 00:10:29 (629 seconds)

Extracting DTS Track:
Progress: 100%
DTS track extracting took: 00:08:29 (509 seconds)

Converting DTS to AC3:
libdca-0.0.5 - by Gildas Bazin [email protected]
based on the a52dec code from Michel Lespinasse [email protected] and Aaron Holtzman
Stream with high frequencies VQ coding
SIMD usage: MMX SSE SSE2 SSE3
Threads: 4

733204 frames in 1779.74 sec (411.97 fps), 219 last 0.50 sec (438.00 fps)
733245 frames decoded in 1779.83 seconds (411.97 fps)
./mkvdts2ac3.sh: line 505: [: -eq: unary operator expected
DTS track conversion took: 00:29:44 (1784 seconds)

1.5.2: free space check uses wrong column in Ubuntu

Got "There is not enough free space on /tmp to create the new file." on pretty full drive.

found in line 486
WDFREESPACE=$(\df -k "$WD" | tail -1 | awk '{print $4*1024}')
but
\df -k "$WD" | tail -1
gives
1939175428 1913048748 26126680 99% /
on my Ubuntu system
and awk uses the 4th column instead of the 3rd which is supposedly wrong

\df -k /tmp/ | tail -1 | awk '{print $4}' results in
99%
which is obviously wrong

\df -k /tmp/ | tail -1 | awk '{print $3}' results in
26126680
which is correct.
and btw it doesn't have to be multiplied by 1024 as done in your script since the result is already in kilobytes. But this is already addressed in issue #37.

It is not to my knowledge if this only applies to Ubuntu, but may be it's worth a check.

DTS file is not copied when keep-dts option is passed

Hello,

When the "-k" flag is set, the DTS file is left in the temporary directory. It should be copied to the directory containing the old MKV file and then deleted from the temp dir.

Here is a patch to add this :

--- mkvdts2ac3.sh.bak 2011-03-26 17:05:27.000000000 +0100
+++ mkvdts2ac3.sh 2011-03-26 17:08:59.000000000 +0100
@@ -623,12 +623,23 @@
error "ERROR: '$NEWFILE' and '$MKVFILE' files do not match. You might want to investigate!"
fi
fi
+

  •   # Copy DTS file if keep-dts is active
    
  •   if [ $KEEPDTS = 1 ]; then
    
  •       color YELLOW; echo "Moving DTS track to MKV directory."; color OFF
    
  •       rsync -av "$DTSFILE" "$(dirname $MKVFILE)"
    
  •       checkerror $? "ERROR: There was an error copying the DTS track to MKV directory. You can perform this manually by copying '$DTSFILE' in '$(dirname $MKVFILE)'." 1
    
  •   fi
    
    fi
    +
    +

    Remove new file in $WD

    doprint "\nRemove working file."
    doprint "> rm -f "$NEWFILE""
  • doprint "> rm -f "$DSTFILE""
    dopause
    cleanup $NEWFILE
  • cleanup $DTSFILE
    fi

timestamp "File copy took: "

Regards,

Florian

stat -c doesn't work on Darwin / Mac OSX

stat -c isn't an option under Darwin / Max OSX

Currently get:

"stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
./mkvdts2ac3.sh: line 570: - : syntax error: operand expected (error token is " ")"

I believe it should be stat -f (haven't tested though)

additional feature: Set track id for the new ac3 track

Can you pls add the feature, specify the track id of the new ac3 file.
I got a samsung tv, that only supports ac3 tracks and that track have to be the first audio track in the mkv container.
This issue is related to every Samsung tv, that supports media2.0 features.

Thanks for your work. I love your tool/script. :)
nick

make disk-pkg not working on armel architecture

here's follow a patch that make the makefile building deb for all architectures :

From f7f1eee32710fa1d3c151a2369dd4b694c85133d Mon Sep 17 00:00:00 2001
From: ka2er <[email protected]>
Date: Fri, 1 Jul 2011 23:12:33 +0200
Subject: [PATCH] - fix make issue for non i386 architecture i386 => all (debian)

---
 Makefile            |    2 +-
 mkvdts2ac3_dpkg.txt |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index b10396a..0278cd3 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ dist-dpkg: dist-dir
    $(CP) mkvdts2ac3.sh $(DIST_DPKG)/usr/bin/mkvdts2ac3
    $(CP) $(PACKAGE)_dpkg.txt $(DIST_DPKG)/DEBIAN/control
    $(CP) CHANGELOG.md LICENSE.txt $(DIST_DPKG)/DEBIAN
-   dpkg -b $(DIST_DPKG) dist/$(PACKAGE)_$(VERSION)-$(REVISION).i386.deb
+   dpkg -b $(DIST_DPKG) dist/$(PACKAGE)_$(VERSION)-$(REVISION).all.deb
    $(RM) -r $(DIST_DPKG)

 clean:
diff --git a/mkvdts2ac3_dpkg.txt b/mkvdts2ac3_dpkg.txt
index 98e4d29..285be37 100644
--- a/mkvdts2ac3_dpkg.txt
+++ b/mkvdts2ac3_dpkg.txt
@@ -3,7 +3,7 @@ Version: 1.5.3
 Provides: mkvdts2ac3
 Section: security
 Priority: optional
-Architecture: i386
+Architecture: all
 Essential: no
 Depends: rsync, mkvtoolnix, libdca-utils, aften
 Installed-Size: 20k
-- 
1.7.2.5

Custom name for AC3

Add a parameter to the script to specify the name for the AC3 track, since I don't know of any tool which would let you edit the track name without generating a new MKV file.

Ricardo Capurro

--compression bug

I think you need to specify the TID in the --compression statements:
something like this:

diff --git a/mkvdts2ac3.sh b/mkvdts2ac3.sh
index 3f33f12..547a087 100755
--- a/mkvdts2ac3.sh
+++ b/mkvdts2ac3.sh
@@ -544,12 +544,12 @@ else
                        # Get a list of all the other audio tracks
                        SAVETRACKS=$(mkvmerge -i "$MKVFILE" | grep "audio (A_" | cut -d ":" -f 1 | grep -vx "Track ID $DTSTRACK" | cut -d " " -f 3 | awk '{ if (T == "") T=$1; else T=T","$1 } END { print T }')
                        # And copy only those
-                       CMD="$CMD -a \"$SAVETRACKS\""
+                       CMD="$CMD -a \"$SAVETRACKS\" --compression \"$SAVETRACKS\":none"
                fi
        fi

        # Add original MKV file, perform no header compression
-       CMD="$CMD --compression TID:none \"$MKVFILE\""
+       CMD="$CMD --compression 0:none \"$MKVFILE\""


        # If user wants new AC3 as default then add appropriate arguments to command
@@ -573,7 +573,7 @@ else
        fi

        # Append new AC3, perform no header compression
-       CMD="$CMD --compression TID:none \"$AC3FILE\""
+       CMD="$CMD --compression 0:none \"$AC3FILE\""

        # ------ MUXING ------
        # Run it!

Hide aften output

Pipe the aften output to /dev/null since it offers no useful information due to the piping of its input. At least dcadec shows the frame count for some notion of progress.

Easily set default values

Somehow be able to set default values for the script (such as not including the DTS in the new file or setting the new AC3 track as default)

Error on line 518

Not sure if this is something already in your to-do list, but I got the following error while converting an AC3 track:
/usr/local/bin/mkvdts2ac3.sh: line 518: [: 49%: integer expression expected

by Ricardo Capurro

MD5 sum is not tested

Hello,

At lines 643 and 644, the script calculate MD5 sum of OLD and NEW MKV files, but on line 645, it checks if files size are equals.
I think this :

if [ $OLDFILESIZE -ne $NEWFILESIZE ]; then

should be replaced by this :

if [ $OLDFILEMD5 -ne $NEWFILEMD5 ]; then

Regards,

Florian

Add nice level argument

Add argument to pass a nice level to the programs that the script utilizes.

Suggested by Huss

df on the Mac does not have option -B

[My apologies, I did not take time to see and read the Unread issues where the below is already listed]

The df command on the Mac does not have option -B to establish a blocksize.

The Mac version of df doesn't appear to have an equivalent option to Unix/Linux's -B. The Mac version has -b, -g, -k, -m, and -P options to force blocksizes of 512 Byte, 1GB, 1,024KB, 1MB, and 512 Byte respectively. Here is a link to the Mac df manual page: http://developer.apple.com/Mac/library/documentation/Darwin/Reference/ManPages/man1/df.1.html

So, without alteration the script seems to complete but does not perform the space checks. It's output is also messy with errors and such. Changing the -B option to -b clears everything up, though, I'm not familiar enough with the df command or the workings of the script to know if everything is working properly.

take care.

Copying new file over old file

Hi,
I might not understand this correctly, but if you do this:
cp new.mkv old.mkv
rm new.mkv

you're copying multiple gigabytes of data. if you however do this:
rm old.mkv
mv new.mkv old.mkv

you basically just rename it and it takes a fraction of a second.

Kind regards

-n option doesn't delete dts track after finishing

After updating to 1.5.5 using the -n option no longer deletes the .dts file at the end of processing. It just leaves the .dts file in the original file's directory. I don't recall this happening in the past and was curious if this was intended or not. Thanks.

Test to see if AC3 track already exists

A very simple test to determine if any work needs to be done should be performed. I tested the current 1.0.5 version and it will just re-do the file despite having just been done.

I followed your coding conventions and added at line 249 the following test:
if [ "$(mkvmerge -i "$MKVFILE" | grep -i "A_AC3")" ]; then echo "AC3 track already exists in $MKVFILE. Exiting.";exit 1;fi

With that one line I can now run the script without any worry of duplication of effort. If you do add this test into your next version you might consider a -f (Force) option that overrides this test.

Great script BTW,
Chris

Error Line 367 mkvdts2ac3.sh (Current SVN version as of 12/3/09)

You forgot a closing ')' in version 1.0.6 on line 367

Line is: DTSNAME=$(echo "$INFO" | grep -m 1 "Name" | cut -d " " -f 5- | sed "s/DTS/AC3/" | awk '{gsub(/[0-9]+(.[0-9]+)?(M|K)bps/,"448Kbps")}1'

It should be (I think) DTSNAME=$(echo "$INFO" | grep -m 1 "Name" | cut -d " " -f 5- | sed "s/DTS/AC3/" | awk '{gsub(/[0-9]+(.[0-9]+)?(M|K)bps/,"448Kbps")}1')

Option to decode dts to external .wav file instead of piping to aften

Hi,
I'm having some problems with dcadec | aften (OSX, built latest versions from svn).

The encoding process freezes or stops saying "error allocating read buffer" (depending on aften version, 0.0.8 shows the error, svn freezes). I noticed that the errors occur when trying to process a 2.0 channels DTS.

Strangely enough, everything works flawlessly using an external wav file instead of piping, even if I don't understand why, so it would be great supporting such an option.

I could (try to) provide a patch, if you want.

Add --compression TID:none

Looks like for some versions of mkvmerge (at least 4.6.0 included in debian-multimedia.org) header compression is enabled by default. This causes some TV players (like Samsung B650 or LGs) either crash or refuse to play resulting file. Using option from title of this issue solves playback problems

faad for aac support?

Hey there-

Great script, made the dts->ac3 conversion a breeze on my Snow Leopard machine. I was just wondering if you would consider adding additional input types, other than DTS? (Obviously the name of the script would become a little wonky then ;)

Using faad2, you can accomplish pretty much the same exact work as you did w/ dcadec, but for aac encodings instead of DTS.

If I'm not mistaken:

dcadec -o wavall "/mnt/media/tmp/Some.Random.Movie.dts" == faad -w "/mnt/media/tmp/Some.Random.Movie.aac"

Add unit testing

It would be beneficial to include small (<1s) movie samples (read-only) which would be duplicated and then run the script on it. Multiple passes would be needed to test out each of the main features. The outputs of mkvinfo and mkvmerge -i could be used to ensure a proper output. This will greatly help development of future versions since we (the developers) don't even use the script anymore.

B vs KB

I didn't realize until I implemented stat in my copy of the script that stat returns a filesize in bytes whereas df returns sizes of disk in KB:
$ stat -c %s CHD-Transformers-1080p-Sample.mkv # 108Mb sample
108214561
$ df /tmp |tail -1|awk '{print $4}' # 173Gb free on drive
173922760

The script fails on copying over the file in many instances as the test for sufficient space on the Working Directory ($WD) fails.

The way I solved this was to just _1024 the df value right in awk:
WDFREESPACE=$(\df "$WD" | tail -1 | awk '{print $4_1024}')

Find portable grep -P solution

grep -P is not supported by FreeBSD and is also causing issues with discrepancies between grep versions on Unix-based platforms. Find an alternative that is portable.

Error on line 288

/usr/local/bin/mkvdts2ac3.sh: line 288: [: too many arguments

I used the script using the following command line:
mkvdts2ac3.sh -t 3 The_Bourne_Identity.mkv

I also ran the following:
mkvmerge -i The_Bourne_Identity.mkv | grep "Track ID 3: audio (A_DTS)" Track ID 3: audio (A_DTS)

so I guess the script didn't like the "-z" test in line 288 for some reason.

by Ricardo Capurro

Updating mkvtoolnix

This isn't a bug necessarily, but more curiosity on my part. Up until this point I have been using mkvtoolnix 2.3.0 (mkvextract, mkvinfo, and mkvmerge). These are from 2008 and are quite obsolete. I don't remember where I got the old versions from that were compiled for Mac but I decided to download mkvtoolnix 4.9.1 from the tool's website. This involved me downloading a precompiled GUI version of mkvtoolnix and going into the package's contents and finding mkvextract, mkvinfo, and mkvmerge. Using 2.3.0, when the script began to remux the AC3 track into the mkv there would be output stating what parts of the file were being muxed and what tool was being used. Now using 4.9.1, when remuxing there is no output from the script and it looks like this:

Muxing AC3 Track in:
MOVING new file over old file. DO NOT KILL THIS PROCESS OR YOU WILL EXPERIENCE DATA LOSS!

Using 2.3.0, there was information displayed between the two lines. Everything seems to convert correctly in the end. Does this change have something to do with the script or just due to changes made to mkvtoolnix from 2.3.0 to 4.9.1? Sorry if my question is confusing, didn't know how else to put it.

1.5.2: Space checks bytes against kilobytes

The script does use

line 43
DUCMD="$(which \du) -k" for the filesize calculation in kilobytes

whereas the actual calculation and comparison is made against bytes

...continue in line 484

filesize in kilobytes
MKVFILESIZE=$($DUCMD "$MKVFILE" | cut -f1)
filesize in kilobytes
AC3FILESIZE=$($DUCMD "$AC3FILE" | cut -f1)
freespace evaluated in kilobytes but converted to bytes by awk
WDFREESPACE=$(\df -k "$WD" | tail -1 | awk '{print $4*1024}')
if [ $(($MKVFILESIZE + $AC3FILESIZE)) -gt $WDFREESPACE ]; then
... rest of the code

Btw. awk is using the wrong column in Ubuntu but this is addressed in issue #38

Use --track-order for --initial

This eliminates the need to build the command two different ways and can allow for "normal" track ordering (i.e. video, ac3, dts, subs).

The merged ac3 doesn't have lang code and track name

Original file has following info http://rafb.net/p/zILpik90.html

And script produces following when run with --debug
Running main remux.

mkvmerge -o "./Star.Wars.The.Clone.Wars.2008.-.PGor.-.(BD-Rip.720p.x264.Russian.AC3.EX-5.1.English.DTS-HD-5.1.Sub).new.mkv" "Star.Wars.The.Clone.Wars.2008.-.PGor.-.(BD-Rip.720p.x264.Russian.AC3.EX-5.1.English.DTS-HD-5.1.Sub).mkv" "./Star.Wars.The.Clone.Wars.2008.-.PGor.-.(BD-Rip.720p.x264.Russian.AC3.EX-5.1.English.DTS-HD-5.1.Sub).ac3"

1.5.0 permission denied, 1.0.5 working normally

Hi,

well, when I'm trying to run the 1.5.0 -version script with command $"./mkvdts2ac3.sh -n some.movie.mkv" I get "Permission denied". fstab should be OK.

But, when I run the script with version 1.0.5 and exactly with same command, it works! Any ideas? Using Linux Mint 8 Helena 32 bit and ext4.

BR,

j-mi

Failed on specific MKV file.

Thanks for the usefull script!

It failed on one mkv here:

Version: JakeWharton-mkvdts2ac3-7a06e1406eff7e81fbeb8e6ea41cae2af925e674
System: Debian stable
mkvtoolnix 2.0.2-1.1+b1

froh@dionysos:/data/bittorrent$ mkvdts2ac3.sh --debug -w /data/tmp Valkyrie.720p.BluRay.x264-> REFiNED/refined-valkyrie-blu720p.mkv
........
Running main remux.

mkvmerge -o "/data/tmp/refined-valkyrie-blu720p.new.mkv" "Valkyrie.720p.BluRay.x264-REFiNED/refined-valkyrie-blu720p.mkv" --language 0:duration: "/data/tmp/refined-valkyrie-blu720p.ac3"

Attached mkvinfo output from the file

Happy hacking!

Frode Haugsgjerd
Norway

mkvinfo (snippet):
| + A track
| + Track number: 2
| + Track UID: 2864556435
| + Track type: audio
| + Enabled: 1
| + Default flag: 1
| + Forced flag: 0
| + Lacing flag: 1
| + MinCache: 0
| + Timecode scale: 1.000000
| + Max BlockAddition ID: 0
| + Codec ID: A_DTS
| + Codec decode all: 1
| + Default duration: 10.667ms (93.750 fps for a video track)
| + Language: eng
| + Name: English DTS 1509kbps
| + Audio track
| + Sampling frequency: 48000.000000
| + Channels: 6

Likely due to a different number of values under the audio track so the language grep is matching the wrong content. Should change to grep specifically the language line.

Replace 'du' usage with 'stat'

The use of 'du' for determining accurate file sizes is problematic on differing filesystems as du doesn't return the correct filesize for an identical file on differing filesystems or ones with differing block sizes.
More information: http://forums.thedailywtf.com/forums/p/8057/151626.aspx

This problem arose on a filesystem that had ext3 for /tmp and reiserfs for the final movie destination and despite the md5 checksum's being identical du reported different values for the two files when testing if the copy/move was successful.

a replacement for:
du "$NEWFILE" | awk '{print $1}'
would be
stat -c %s "$NEWFILE"

Hope this helps make this a more robust script,
Chris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.