OSX: Pal-Speedup-Script from 23.976 -> 25.000. Completely automatic.

Come up with a useful post-processing script? Share it here!
Post Reply
ProfDrLuigi
Newbie
Newbie
Posts: 5
Joined: December 20th, 2008, 5:24 am

OSX: Pal-Speedup-Script from 23.976 -> 25.000. Completely automatic.

Post by ProfDrLuigi »

Hi folx.

The Situation:
You have a MKV-File with 23.976 FPS, 24.000 FPS or 29.970 FPS and want to convert it to PAL 25 FPS (30 FPS at a FPS of 29.970) to see the movie totaly smooth on your tv which is not supporting 24p correct. If you Speedup the Movie to 25FPS (or 30 FPS) you have the problem that the Audio-Track must be edited. There are 2 Ways:

1. Timestretch (that keeps the original Pitch but has the big disadvantage of creating Audio-Artefacts which doesn´t sounds well)
2. Speedup (The Audio-Track plays with approx. 4% more Speed. This method is used by Pal-DVDs because orig. Film-Material is ever in 23.976 FPS)

I want to go the 2nd way. Unfortunately for OSX doesnt exists a tool which can Speedup AC3 and DTS on thy fly. We will use eac3to from Windows-World.

Now i build a post-process-script the extracts the whole MKV-File (if it´s not already in 25 FPS) in his elementary streams. After that the script runs eac3to via Wine.

The script looks if the movie is in 23.976, 24.000 or 29.970 FPS and start to convert it to 25 FPS (30 FPS at a FPS of 29.970). If the File has 25 FPS the script do nothing.

For my script you need additional programs which i have bundled:
http://x7.to/f1ab97


And here is my Script:

Code: Select all

#!/bin/bash

################## Change to Unpack-Path ##################
base=`basename "$1"`
cd "$1"
###########################################################


######## Pathes to the needed Binaries (change this)#######
eac3to="/Users/luigi/.wine/drive_c/Programme/eac3to/eac3to.exe"
winebin="/Applications/Wine.app/Contents/Resources/bin/wine"
mediainfo="/usr/local/bin/mediainfo"
###########################################################


################ Ignore upper and lowercase ###############
shopt -s nocaseglob
###########################################################


################## Scan every Sub-Folder ##################
find . -type d | while read VERZEICHNIS
    do
    cd "$VERZEICHNIS"
###########################################################


##### Decide if 25 FPS. If not … extract the MKV-File #####
for i in *.mkv; do
fps=`/usr/local/bin/mediainfo --Inform=Video\;%FrameRate% "$i"`
base=`basename "$i"`

if  [ "$fps" = "25.000" ]; then
    echo -e "\033[1;30mAlready 25 FPS\033[0m"
    else
"$mediainfo" "$i" > "$base-info.txt"
"$winebin" "$eac3to" "$i" -demux -keepDialnorm
fi
###########################################################


### Looking for the FPS and initiate the right speedup ####
if  [ "$fps" = "23.976" ]; then
    for a in *.{ac3,dts}; do
    "$winebin" "$eac3to" "$a" "$a-speedup.ac3" -speedup -keepDialnorm
    done
    rm *Log.txt*
   
elif  [ "$fps" = "24.000" ]; then
    for a in *.{ac3,dts}; do
    "$winebin" "$eac3to" "$a" "$a-speedup.ac3" -24.000 -speedup -keepDialnorm
    done
    rm *Log.txt*
    
elif  [ "$fps" = "29.970" ]; then
    for a in *.{ac3,dts}; do
    "$winebin" "$eac3to" "$a" "$a-speedup.ac3" -29.970 -changeTo30.000 -keepDialnorm
    done
    rm *Log.txt*
    
fi
###########################################################

done

rm "*.mkv-info.txt" "*.mkv-chapters.xml" >/dev/null 2>&1
cd -
done
If you have questions ... ask ....  ;D
Last edited by ProfDrLuigi on May 15th, 2010, 11:10 am, edited 1 time in total.
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Re: OSX: Pal-Speedup-Script from 23.976 -> 25.000. Completely automatic.

Post by randyharris »

--
Last edited by randyharris on April 23rd, 2010, 11:49 am, edited 1 time in total.
randyharris
Full Member
Full Member
Posts: 146
Joined: January 21st, 2010, 5:36 pm

Re: OSX: Pal-Speedup-Script from 23.976 -> 25.000. Completely automatic.

Post by randyharris »

Sorry -  just deleted my last post - didn't intend to threadjack.

Nice work.
b1scu1t
Release Testers
Release Testers
Posts: 83
Joined: January 29th, 2008, 6:19 pm

Re: OSX: Pal-Speedup-Script from 23.976 -> 25.000. Completely automatic.

Post by b1scu1t »

Hello,

Thanks for the scripts, I have the reverse question.  I get some content from the UK and they are encoded in 25 fps mkv, how do I switch it to 30 fps mkv to play in my tv here in the US.

I will play with the settings in the script and see whether I can sort it, but if you know it right off the hand, please share it.

Greatly appreciate your work.

Thanks,
b1scu1t
ProfDrLuigi2
Newbie
Newbie
Posts: 1
Joined: January 2nd, 2012, 5:01 pm

Re: OSX: Pal-Speedup-Script from 23.976 -> 25.000. Completel

Post by ProfDrLuigi2 »

Hi Folx.

Hm my old account don´t work. Created a new one.

I have a bigger update. I enhanced the Script.

The biggest news: Now you can encode with the Surcode DTS Encoder completely automatic. The script searches if the audio is dts and initiate the needed steps. Macros for the Mouse are managing the push of the needed buttons in Surcode DTS Encoder (which is completely GUI-Only .. suxx :( )

You need this stuff:

- Wine (use Darwin Ports or search for a precompiled Package)
- eac3to ( http://forum.doom9.org/showthread.php?t=125966 )
- mediainfo CLI Version ( http://x7.to/hjb4w7 )
- mkvextract ( http://x7.to/tr77g2 )
- Surcode DTS Encoder DVD (look for it in the world wiiiiiiiide web (-; )
- For DTS-Encoding you need this too ( http://www.bluem.net/de/mac/cliclick/ ) .. copy this file at /opt/local/bin or if u want another path for this you must change the path in the surcode.sh too.


This 2 files you need to record again with Recorder (because you probably will have other coordinates of the buttons from Surcode Encoder (depends on the Display-Resolutionand place it inside the sabnzbd script folder too.

Ok now let´s show the updated script. U will need a 2nd script which depends on the first "big" script. Here is the big first.

Filename: As you want

Code: Select all

#!/bin/bash

################## Change to Unpack-Path ##################
base=`basename "$1"`
cd "$1"
###########################################################

######## Pathes to the needed Binaries (change this)#######
eac3to="/Users/luigi/.wine/drive_c/Programme/eac3to/eac3to.exe"
winebin="/opt/local/bin/wine"
mediainfo="/usr/local/bin/mediainfo"
mkvextract="/usr/local/bin/mkvextract"
surcode="/Volumes/TempI/Usenet/sabnzbd/scripts/"
###########################################################

################ Ignore upper and lowercase ###############
shopt -s nocaseglob
###########################################################

################## Scan every Sub-Folder ##################
find . -type d | while read VERZEICHNIS
    do
    cd "$VERZEICHNIS"
###########################################################

##### Decide if 25 FPS. If not … extract the MKV-File #####
for i in *.mkv; do
fps=`"$mediainfo" --Inform=Video\;%FrameRate% "$i"`
base=`basename "$i"`

if  [ "$fps" = "25.000" ]; then
    echo -e "\033[1;30mAlready 25 FPS\033[0m"
    else
"$mediainfo" "$i" > "$base-info.txt"
"$mkvextract" tracks "$i" 1:video.264 2:1.ac3 3:2.ac3 4:3.ac3 5:4.ac3 6:5.ac3 7:8.ac3 8:9.ac3 9:10.ac3 10:11.ac3 11:12.ac3 12:13.ac3
fi
###########################################################

######### Recognize File-Type and rename suffix ###########
for t in *.ac3; do
type=$(head -n 1 "$t" | od -t x1 -An | tr -d '\n ' | cut -c 1-4)

if [ "$type" = "0b77" ]; then
     echo ""

elif [ "$type" = "efbb" ]; then
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1srt/'`

elif [ "$type" = "fdd0" ]; then
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1mp_codec/'`

elif [ "$type" = "7ffe" ]; then
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1dts/'`

elif [ "$type" = "fe7f" ]; then
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1dts/'`

elif [ "$type" = "1fff" ]; then
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1dts/'`

elif [ "$type" = "ff1f" ]; then
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1dts/'`
else
     mv $t `echo $t | sed 's/\(.*\.\)ac3/\1unknown/'`
fi
done
###########################################################

### Looking for the FPS and initiate the right speedup ####
if  [ "$fps" = "23.976" ]; then
    for a in *.ac3; do
    if  [ "$a" = "*.ac3" ]; then
    echo "No AC3-File! Cancel AC3-Encoding."
    else  
    echo "Found AC3-File. Start AC3-Encoding of" "$a"
    "$winebin" "$eac3to" "$a" "$a-speedup.ac3" -speedup -keepDialnorm &
    fi
    done
	      
    for b in *.dts; do
    if  [ "$b" = "*.dts" ]; then
    echo "No DTS-File. Cancel DTS-Encoding."
    else   
    echo "Found DTS-File. Start DTS-Encoding of" "$b" 	
    bit=`"$mediainfo" --Inform=Audio\;%BitRate% "$b"`
  	   "$surcode"./surcode.sh &
 	   if  [ "$bit" -gt "900000" ]; then
 	   "$winebin" "$eac3to" "$b" "$b-speedup.dts" -1536 -speedup -keepDialnorm
  	    echo "Using 1536 to encode."
 	    else
  	   "$winebin" "$eac3to" "$b" "$b-speedup.dts" -768 -speedup -keepDialnorm
  	    echo "Using 768 to encode."
  	    fi
    fi
    done

elif  [ "$fps" = "24.000" ]; then
      for a in *.ac3; do
      if  [ "$a" = "*.ac3" ]; then
      echo "No AC3-File! Cancel AC3-Encoding."
      else  
      echo "Found AC3-File. Start AC3-Encoding of" "$a"
      "$winebin" "$eac3to" "$a" "$a-speedup.ac3" -24.000 -speedup -keepDialnorm &
      fi
      done
	      
      for b in *.dts; do
      if  [ "$b" = "*.dts" ]; then
      echo "No DTS-File. Cancel DTS-Encoding."
      else   
      echo "Found DTS-File. Start DTS-Encoding of" "$b" 	
      bit=`"$mediainfo" --Inform=Audio\;%BitRate% "$b"`
    	   "$surcode"./surcode.sh &
 	   if  [ "$bit" -gt "900000" ]; then
 	   "$winebin" "$eac3to" "$b" "$b-speedup.dts" -1536 -24.000 -speedup -keepDialnorm
  	    echo "Using 1536 to encode."
 	    else
  	   "$winebin" "$eac3to" "$b" "$b-speedup.dts" -768 -24.000 -speedup -keepDialnorm
  	    echo "Using 768 to encode."
  	    fi
    fi
    done

elif  [ "$fps" = "29.970" ]; then
      for a in *.ac3; do
      if  [ "$a" = "*.ac3" ]; then
      echo "No AC3-File! Cancel AC3-Encoding."
      else  
      echo "Found AC3-File. Start AC3-Encoding of" "$a"
      "$winebin" "$eac3to" "$a" "$a-speedup.ac3" -29.970 -changeTo30.000 -keepDialnorm &
      fi
      done
	      
      for b in *.dts; do
      if  [ "$b" = "*.dts" ]; then
      echo "No DTS-File. Cancel DTS-Encoding."
      else   
      echo "Found DTS-File. Start DTS-Encoding of" "$b" 	
      bit=`"$mediainfo" --Inform=Audio\;%BitRate% "$b"`
    	   "$surcode"./surcode.sh &
 	   if  [ "$bit" -gt "900000" ]; then
 	   "$winebin" "$eac3to" "$b" "$b-speedup.dts" -1536 -29.970 -changeTo30.000 -keepDialnorm
  	    echo "Using 1536 to encode."
 	    else
  	   "$winebin" "$eac3to" "$b" "$b-speedup.dts" -768 -29.970 -changeTo30.000 -keepDialnorm
  	    echo "Using 768 to encode."
  	    fi
    fi
    done
fi
rm *Log.txt*
###########################################################
done
cd -
done

Now the 2nd (new script for DTS-Encoding)
Filename MUST be "surcode.sh" and must be present in the sabnzbd script folder

Code: Select all

while [ true ] 
do
run=`ps ax | grep "surcodedvd.exe" | grep -v grep`
if [ "$run" = "" ]; then
sleep 1
else
sleep 20
/opt/local/bin/cliclick 770 696
/opt/local/bin/cliclick 770 696
#open /Volumes/TempI/Usenet/sabnzbd/scripts/Start-Encoder.kamrd
sleep 5
	while [ true ]  
	do
	sleep 20
	latest=`ls -1t *.dts|head -n1`
	touch zeit
	filetime=`perl -e '@d=localtime ((stat(shift))[9]); printf "%02d-%02d-%04d %02d:%02d:%02d\n", $d[3],$d[4]+1,$d[5]+190,$d[2],$d[1],$d[0]' "$latest" | cut -c 15-16`
	systime=`perl -e '@d=localtime ((stat(shift))[9]); printf "%02d-%02d-%04d %02d:%02d:%02d\n", $d[3],$d[4]+1,$d[5]+190,$d[2],$d[1],$d[0]' zeit | cut -c 15-16`
	if  [ "$filetime" = "$systime" ]; then
	sleep 1
	else
	rm zeit
	pid=`ps -ef | grep -v grep | grep "libexec/wine/wine " | grep "surcodedvd.exe" | cut -c 7-12`
	kill -TERM "$pid"
	exit
	fi
	done
exit
fi
done
OK guys. I hope i could help a little bit. The Development of this thing needs a lot of hours. Have fun with that. :) Test at what Coordinates your "Encode-Button" is. Press shift+cmd+4 and move the mouse in the middel of the Encode-Button of Surcode DTS and replace ist with my 770 696 in this script. 770x696 is at a Screen-Resolution of 1920x1080.
Post Reply