Recoding of videos to H.264 using mencoder


# a few possible video filters
VF="-vf crop=712:568:4:4,pp=fd"
VF="-vf crop=688:568:18:4,pp=fd"
VF="-vf spp,scale"
VF="-sws 9 -vf scale=720:-11,expand=:-48::0"
VF="-vf expand=0:-32::0"

# audio filters
AF="-af stats,volume=6 -oac lavc -lavcopts acodec=ac3 -aid 128"
AF="-af stats,volume -oac pcm -aid 129"
AF="-aid 128 -af volume=20:0"

# H.264 settings
PASS1="-ovc x264 -x264encopts pass=1:$ENCOPTS"
PASS2="-ovc x264 -x264encopts pass=3:$ENCOPTS"
mencoder "$INPUT" \
         -o "$OUTPUT" \
         -nosub \
         $VF $PASS1 \
         -nosound \

mencoder "$INPUT" \
         -o "$OUTPUT" \
         -nosub \
         $VF $PASS2 \
         -nosound \

# extract the (AC3) audio track
mencoder -of rawaudio -ovc copy $VF $AF $INPUT -o en.ac3


  • I do not really understand the encoding options ENCOPTS. I’ve picked them up from various other posts and it looks to me, I can get reasonable results.
  • Using the option -nosound may desynchronize the video from the audio stream, the the video output-framerate is wrong.Watch out for warnings “duplicate frame” and check the length of the video stream and audio track!
  • For sharpening, use: -vf unsharp=l5x5:1.0:c5x5:1.0, but test the result!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s