Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # usage: cd into your working directory, put all sub directories containing mkv's with dts track to encode to ac3 over there and run it
- use warnings;
- use strict;
- use File::Basename;
- my $DCADEC="/usr/bin/dcadec";
- # apt-get install libdca0 libdca-utils
- my $AFTEN="/usr/bin/aften";
- # apt-get install cmake
- # cd /usr/src; wget wget http://downloads.sourceforge.net/project/aften/aften/0.0.8/aften-0.0.8.tar.bz2; tar xvjf aften-0.0.8.tar.bz2
- # cd aften-0.0.8; mkdir default; cd default
- # cmake .. -DCMAKE_INSTALL_PREFIX:STRING="/usr"; make && make install
- my $MKVMERGE="/usr/bin/mkvmerge";
- my $MKVEXTRACT="/usr/bin/mkvextract";
- # apt-get install mkvtoolnix mkvtoolnix-gui
- my $TMP_DTS="tmp.dts";
- my $TMP_AC3="tmp.ac3";
- my $PATTERN_DTS="A_DTS";
- my $PATTERN_AC3="A_AC3";
- sub dts2ac3 {
- my ($dts, $ac3) = @_;
- `$DCADEC -o wavall $dts | $AFTEN - $ac3`;
- }
- sub info {
- my ($mkv) = @_;
- return `$MKVMERGE -i $mkv`;
- }
- sub demux {
- my ($mkv, $id) = @_;
- `$MKVEXTRACT tracks $mkv $id:$TMP_DTS`;
- }
- sub mux {
- my ($mkv, $new, $ac3) = @_;
- #remove all tracks with -A, only add new
- `$MKVMERGE -A -o $new $mkv $ac3`;
- }
- sub clean {
- # delete 1.dts, 1.ac3, old mkv
- my ($dts, $ac3, $old) = @_;
- system("rm -f $dts");
- system("rm -f $ac3");
- system("rm -f $old");
- }
- my $pwd=`pwd`;
- print "Processing all matches in $pwd...\n\n";
- my @dirs=<*>;
- my $dir;
- my @files;
- my $file;
- my @buf;
- my $line;
- my $id;
- my $name;
- my $ext=".mkv";;
- my $output;
- foreach $dir (@dirs) {
- chdir $dir;
- @files=<*>;
- foreach $file (@files) {
- if($file=~m/mkv/i) {
- $id=-1;
- # 1. get dts track id from info
- @buf=info($file);
- foreach $line (@buf) {
- if($line=~m/$PATTERN_DTS/i) {
- $line=~m/(\d+)/;
- $id = $1;
- }
- if($line=~m/$PATTERN_AC3/i) {
- print "AC3 track found.\n";
- }
- }
- next if($id<0);
- # 2. demux dts track
- print "Demuxing DTS track from $file...\n";
- demux($file,$id);
- # 3. encode dts to ac3
- print "Encoding DTS to AC3...\n";
- dts2ac3($TMP_DTS,$TMP_AC3);
- # 4. parse old name, create new
- if($file=~m/dts/i){
- $output=$file;
- $output=~s/DTS/AC3/g;
- $output=~s/dts/AC3/g;
- } else {
- ($name, undef, $ext) = fileparse($file,qr"\.mkv");
- $output="$name.AC3$ext";
- }
- # 5. mux
- print "Creating new output with AC3 in $output...\n";
- mux($file, $output, $TMP_AC3);
- # 6. clean
- print "Deleting temp files and old mkv...\n";
- clean($TMP_DTS, $TMP_AC3, $file);
- # 7. info
- print info($output);
- }
- }
- chdir "../";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement