Sign up here and you can log into the forum!

mkvfix script

General WDLXTV-Live forum

mkvfix script   

Postby dzebrys » Sun Dec 04, 2011 11:36 am

hi,

i'd like to share script for mkv header compression removal.
it was written for synology nas but shall also works with any *nix system
[but millage vary]. the only requirement are bash and mkvtoolnix
from optware. it scans directories and search for files with compressed
headers. i'm running it periodically from cron. when copying it to box
take care not to break any long lines.

h2h/dzebrys


Code: Select all
#!/opt/bin/bash
#############################################################################
## mkvfix.sh
## A batch script to scan directories and fix header compression
## in mkv files when required.
##
## Written by: dzebrys
## Mail: dzebrys@gmail.com
## Date: 2011-12-02
#
# Save script as /opt/sbin/mkvfix.sh
#
# Script was prepared for Synology NAS but shall be easily portable
# to other *nix systems
#
# Some busybox systems have limited support for their linux-utils
# You could install those in optware.
#
# Required optware packages
#
# bash
# mkvtoolnix
#


# fill with more extensions or have it as a cmd line arg
TYPES=( mkv MKV mka MKA mks MKS mk3d MK3D )
LOGPATH=/var/log/messages
DIR=$1 # directory to start recursive search for files
DBG=1 # un/comment it for more debug logs

_logger ()
{
  echo "`date +"%b %d %X"` mkvfix info: ${1}" | tee -a ${LOGPATH}
}

# Create a regex of the extensions for the find command
TYPES_RE="\\("${TYPES[0]}
for t in "${TYPES[@]:1:${#TYPES[*]}}"; do
    TYPES_RE="${TYPES_RE}\\|${t}"
done
TYPES_RE="${TYPES_RE}\\)"

# Set the field seperator to newline instead of space
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# scan for file and fix it when needed
for f in `find ${DIR} -type f -regex ".*\.${TYPES_RE}"`; do
  [ $DBG ] && _logger "found file to analyse: ${f}"
  RESULT="0"
  RESULT=$(mkvinfo ${f} | grep "Content compression" | tail -1 | sed 's/.*|/1/')
  [ $DBG ] && _logger "mkvinfo result: ${RESULT:0:1}"
  if [ "${RESULT:0:1}" = "1" ]; then
    _logger "found file to fix: ${f}"
    #`mkWDclean "${f}" "${f}.fixed" &>/dev/null`
    `mkvmerge -o "${f}.fixed" -A -S --compression -1:none "${f}" -D -S --compression -1:none "${f}" -D -A --compression -1:none "${f}" &>/dev/null`
    if [ -e "${f}.fixed" ]; then
      rm -f "${f}"
      mv "${f}.fixed" "${f}"
      [ $DBG ] && _logger "successfully fixed file: ${f}"
    fi
  fi
done

# Reset IFS
IFS=$SAVEIFS

[ $DBG ] && _logger "finished"
Last edited by dzebrys on Wed Feb 15, 2012 6:50 am, edited 1 time in total.
User avatar
dzebrys
DLX'er
 
Posts: 131
Joined: Mon Feb 14, 2011 1:49 am
Location: poland

Re: mkvfix script   

Postby player_sct » Thu Jan 12, 2012 10:33 am

man - this script is great :) thanx

dzieki za skrypcik, rewelacja, szczegolniejak sie go w krona wepnie :)
User avatar
player_sct
Beta Tester
 
Posts: 90
Joined: Sun Apr 11, 2010 6:29 am
Location: Poland

Re: mkvfix script   

Postby sjaddy » Sun Jan 22, 2012 12:15 am

looks great but obviously i am doing something completely stupid.

have a synology 210j and have installed bash and mkvtoolnix and copied the above into the right file.


when i try and manually run the file i get

: not foundkvfix.sh: line 24:
: not foundkvfix.sh: line 25:
/opt/sbin/mkvfix.sh: line 27: syntax error: unexpected "("


Any ideas please?
sjaddy
n00b
 
Posts: 2
Joined: Wed Apr 14, 2010 12:41 am

Re: mkvfix script   

Postby player_sct » Mon Jan 23, 2012 12:08 pm

change in the first line path to bash. in my wdtv first line looks that:

Code: Select all
#!/usr/bin/bash
User avatar
player_sct
Beta Tester
 
Posts: 90
Joined: Sun Apr 11, 2010 6:29 am
Location: Poland

Re: mkvfix script   

Postby DJArty » Wed Feb 15, 2012 2:04 am

Where is the mkvmerge (app.bin) for 1.02.21 (compressed header fix need) can be finded? or making myself?
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413
User avatar
DJArty
Developer
 
Posts: 547
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

Re: mkvfix script   

Postby recliq » Wed Feb 15, 2012 2:40 am

­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: mkvfix script   

Postby DJArty » Wed Feb 15, 2012 3:18 am

thank you recliq.
But i don't understand why its two variants (comp/nocomp).. Оne mkvmerge with right keys (like --compression -1:none) must remove compression .. Why two versions? (description in Readme is similar).
WD TV Live (1.02.21-WDLXTV-0.4.7.3);
Please Donate PayPal to email: djartyua ( a t ) gmail (d o t) com
WebMoney: WMZ114867333413
User avatar
DJArty
Developer
 
Posts: 547
Joined: Wed Jul 21, 2010 2:30 am
Location: Ukraine

Re: mkvfix script   

Postby fidee » Wed Feb 15, 2012 4:55 am

Hello All,


this is indeed a greath script. I use it for 1 month now but yesterday found a little problem with compressed subtitles. I get garbage characters on screen.
I think that you need to adapt the mkvmerge line by adding as well --compression -1:none after the -D and -A options:

`mkvmerge -o "${f}.fixed" -A -S --compression -1:none "${f}" -D -S --compression -1:none "${f}" -D -A --compression -1:none "${f}" &>/dev/null`


Bye.
fidee
n00b
 
Posts: 1
Joined: Fri Sep 23, 2011 11:27 am

Re: mkvfix script   

Postby recliq » Wed Feb 15, 2012 5:54 am

DJArty wrote:thank you recliq.
But i don't understand why its two variants (comp/nocomp).. Оne mkvmerge with right keys (like --compression -1:none) must remove compression .. Why two versions? (description in Readme is similar).

The binaries have different default settings (with and without header compression).
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5513
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: mkvfix script   

Postby dzebrys » Wed Feb 15, 2012 6:49 am

DJArty wrote:thank you recliq.
But i don't understand why its two variants (comp/nocomp).. Оne mkvmerge with right keys (like --compression -1:none) must remove compression .. Why two versions? (description in Readme is similar).


if you use nocomp version then just remux contaier. no need for options/keys as it by default remove header compression (if exist).
much simpler and [probably] works for all tracks [if many].


fidee wrote:this is indeed a greath script. I use it for 1 month now but yesterday found a little problem with compressed subtitles. I get garbage characters on screen.
I think that you need to adapt the mkvmerge line by adding as well --compression -1:none after the -D and -A options:

`mkvmerge -o "${f}.fixed" -A -S --compression -1:none "${f}" -D -S --compression -1:none "${f}" -D -A --compression -1:none "${f}" &>/dev/null`


thanks, first post updated.


br/piotr
User avatar
dzebrys
DLX'er
 
Posts: 131
Joined: Mon Feb 14, 2011 1:49 am
Location: poland

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron