[Home]Mp42dvd

Difference (from prior major revision) (no other diffs)

Changed: 18,22c18,19
# For live-action, the hqdn3d lines should be deleted entirely
# and the arguments to eq2 should be changed to 0.9:1:0.02:1.03
#
# For live-action only, I recommend adding 'nr = 20' to the
# ffmpeg.cfg, or 'nr = 10' if the source is SUPER clean.
# For live-action, the hqdn3d filter should be removed from the
# -J filter list.

Added: 52a50
nr = 40

Changed: 131,133c129,130
-J hqdn3d=luma=8:chroma=8:luma_strength=7:chroma_strength=8:pre=0 \
-J modfps=clonetype=4 \
-x mplayer="-vf eq2=0.8:1:0.04:1.1",null \
-J hqdn3d,msharpen=threshold=8:strength=16,modfps=clonetype=4 \
-x mplayer="-vf eq2=0.9:1:0:1.02",null \

Changed: 155,157c152,153
-J hqdn3d=luma=8:chroma=8:luma_strength=7:chroma_strength=8:pre=0 \
-J modfps=clonetype=4 \
-x mplayer="-vf eq2=0.8:1:0.04:1.1",raw \
-J hqdn3d,msharpen=threshold=8:strength=16,modfps=clonetype=4 \
-x mplayer="-vf eq2=0.9:1:0:1.02",raw \

#!/bin/sh
#
# This script is a variation of my avitovob.sh script.
# It will (if you read the comments and act accordingly)
# produce EXTREMELY hgh quality results, and therefore
# encode very slowly!
#
# Though this script is called mp42dvd, it will work with no
# modification on mp4, avi, mkv, ogm, mpg, and mov files.
#
# The ffmpeg.cfg settings are for HQ and will therefore slow
# down encoding greatly.
#
# Note that cmp and subcmp in ffmpeg.cfg should be set to
#'2' for animation,  and '3' for live action.
#
# For live-action, the hqdn3d filter should be removed from the
# -J filter list.
#
# Note that the -J modfps=clonetype=4 is almost certainly
# NOT what you really want if you are dealing with hard
# telecine... You really want to use this for that:
#
#  -J ivtc,32detect=force_mode=3,decimate
#
# Note that this script requires sox version 12.18.1 - With sox
# version 13.0.0 or greater, the '-b' and '-w' switches have been
# renamed: -b -> -1 and -w -> -2. You should NOT use sox versions
# 13.0, 13.1, or 14.0 in any case, they are all broken.
#
# Other useful options to mplayer might include: 
#
#     Subtitle options: -sid 0 -slang en -ass -embeddedfonts
#     Audio stream options: -aid 1
#
# Phil Ehrens <phil@slug.org>
#

## NOMINAL BITRATE ##
vbitrate=2400

## WRITE LAVC CONFIG ##
cat > ffmpeg.cfg <<_EOF
[mpeg2video]
mbd = 2
trell = 1
cmp = 2
subcmp = 2
nr = 40
vqcomp = 0.7
vqblur = 0.3
_EOF

## PROCESS COMMAND LINE ARGS AND ITERATE ##
[ ! -z "$1" ] && files="$@";

for arg in $files ;

do

# strip the .avi, .mkv, .mov, .mp4 or .ogm file extension
file=`echo $arg | sed -e 's/\.[amo][vkpgo][iv4m]$//'`
ext=`echo $arg | sed -e 's/^.*\.//'`

 ## AUDIO PRE-PROCESSING STAGE ##
 # dump the audio as pcm
 mplayer -ao pcm:fast \
         -vo null \
         -vc dummy \
          $arg > /dev/null 2>&1 &

 echo "mplayer: dumping pcm audio from $arg to audiodump.wav"
 while ps -p $! > /dev/null; do printf . ; sleep 1; done ; echo

 # if the sound turns out to be 8 bit, then sox needs
 # extra options to handle it correctly.
 # thanks to Kenneth Stailey for this patch!
 file audiodump.wav | grep -qs 'PCM, 8 bit'
 if [ $? = 0 ]; then
    B=-b
    W=-w
 else
    B=
    W=
 fi

 echo "sox: resampling to 48 kHz if samplerate is not 48 kHz" 
 echo "sox: this will take a moment... be patient."

 # HIGH quality resampling to get samplerate to 48k
 if sox $B audiodump.wav -r 48000 $W output.wav resample -ql ; then
    mv -f output.wav audiodump.wav
 else
    rm -f output.wav
 fi

 # adjust the volume downward slightly
 sox -v 0.7 audiodump.wav output.wav &
 echo "sox: reducing audio gain to 0.7"
 while ps -p $! > /dev/null; do printf . ; sleep 1; done ; echo
 mv -f output.wav audiodump.wav

 # boost the bass!!
 sox audiodump.wav output.wav mcompand \
 "0.005,0.1 -60,-30 0 0 0" 1600 "0.005,0.1 -60,-60 0 0 0" &
 echo "sox: boosting low level bass frequencies"
 while ps -p $! > /dev/null; do printf . ; sleep 1; done ; echo
 mv -f output.wav audiodump.wav

## MPLAYER PROBING ##
foo=`mplayer -identify -frames 0 -ao null -vo null $arg 2>/dev/null | grep ID_VIDEO_`
eval "$foo";
geometry=${ID_VIDEO_WIDTH}x$ID_VIDEO_HEIGHT;

framerate=$ID_VIDEO_FPS;
index=0;
[ $framerate = 23.976 ] && index=1;
[ $framerate = 24     ] && index=2;
[ $framerate = 25     ] && index=3;
[ $framerate = 29.970 ] && index=4;

rm -f stream.yuv ffmpeg.log
 
transcode --nice 20 \
           --print_status 500 \
           -g $geometry \
           -H 0 \
           -J hqdn3d,msharpen=threshold=8:strength=16,modfps=clonetype=4 \
           -x mplayer="-vf eq2=0.9:1:0:1.02",null \
           -Z 720x480 \
           --zoom_filter Mitchell \
           -j -16,-32,-16,-32 \
           -f $framerate,$index \
           --export_fps 23.976,1 \
           -y ffmpeg,null \
           --export_prof dvd-ntsc \
           --import_asr 3 \
           --export_asr 3 \
           -o $file \
           -w $vbitrate \
           -R 1,ffmpeg.log \
           -i $arg 

rm -f stream.yuv

transcode --nice 20 \
           --print_status 500 \
           -p audiodump.wav \
           -g $geometry \
           -H 0 \
           -J hqdn3d,msharpen=threshold=8:strength=16,modfps=clonetype=4 \
           -x mplayer="-vf eq2=0.9:1:0:1.02",raw \
           -Z 720x480 \
           --zoom_filter Mitchell \
           -j -16,-32,-16,-32 \
           -f $framerate,$index \
           --export_fps 23.976,1 \
           -y ffmpeg \
           --export_prof dvd-ntsc \
           --import_asr 3 \
           --export_asr 3 \
           -o $file \
           -w $vbitrate \
           -b 192 \
           -R 2,ffmpeg.log \
           -m $file.ac3 \
           -i $arg

rm -f stream.yuv

mplex -f 8 -o "$file.mpg" "$file.m2v" "$file.ac3"

rm -f *.m2v *.ac3 *.wav ffmpeg.log

done;
rm -f ffmpeg.cfg

Transcode Wiki | Recent Changes | Preferences
Password required to edit | View other revisions
Last edited August 6, 2008 10:49 pm by tarazed.ligo.caltech.edu (diff)
Search: