Cette page rassemble un certain nombre de scripts pour convertir des videos prises avec un APN en Video H264 de super bonne qualité (600 kbits/s de video, 64kbit/s d'audio, encodage triple passe).

Voici un premier script qui va bien pour les appareils Canon et Fuji

#!/bin/sh
#X264 version of rencoder
# 16/03/2008  J. Kieffer
VBitrate=600
ABitRate=64
x264opts="subq=7:nr=100:me=umh:partitions=all:direct_pred=auto:b_pyramid:bframes=3:frameref=5"
IASampleRate=11025
case $(basename $0 rencoder.sh) in
  cw-)
        rotate="-vf rotate=1"
        ;;
  ccw-)
        rotate="-vf rotate=2"
        ;;
    * )
        rotate=""
        ;;
esac
BN=$(basename $1 .AVI)-H264.avi
rm "$BN"
mplayer -dumpaudio "$1"  -dumpfile audio_theme.raw
sox   -r $IASampleRate -c 1 -u -b -t raw audio_theme.raw  -r 44100 audio_theme.wav resample
rm audio_theme.raw
mencoder $rotate -oac copy -ovc x264  -x264encopts bitrate=$VBitrate:pass=1:turbo=1:$x264opts -ofps 24 -o "$BN" "$1"
rm "$BN"
cp divx2pass.log divx2pass.bak
mencoder $rotate -oac copy -ovc x264 -x264encopts bitrate=$VBitrate:pass=3:$x264opts -ofps 24  -o "$BN" "$1"
rm "$BN"
if [ ! -s divx2pass.log ]
then
        cp divx2pass.bak divx2pass.log
        touch backup
fi
mencoder $rotate -oac mp3lame -lameopts mode=3:vbr=3:br=$ABitRate -audiofile audio_theme.wav -ovc x264 -x264encopts bitrate=$VBitrate:pass=3:$x264opts -ofps 24 -o "$BN" "$1"
rm audio_theme.wav
rm divx2pass.log
if [ -s divx2pass.bak ]
then
        rm divx2pass.bak
fi
if [ -s divx2pass.log.temp ]
then
        rm divx2pass.log.temp
fi

Pour conserver la bande son originale, utile pour les MPEG fait par les APN sony :

#!/bin/sh
#X264 version of rencoder
# 16/03/2008  J. Kieffer
VBitrate=600
ABitRate=64
x264opts="subq=7:nr=100:me=umh:partitions=all:direct_pred=auto:b_pyramid:bframes=3:frameref=5"
case $(basename $0 rencoder-mpg.sh) in
  cw-)
        rotate="-vf rotate=1"
        ;;
  ccw-)
        rotate="-vf rotate=2"
        ;;
    * )
        rotate=""
        ;;
esac
BN=$(basename $1 .mpg)-H264.avi
rm "$BN"
mencoder $rotate -oac copy -ovc x264  -x264encopts bitrate=$VBitrate:pass=1:turbo=1:$x264opts -ofps 24 -o "$BN" "$1"
rm "$BN"
cp divx2pass.log divx2pass.bak
mencoder $rotate -oac copy -ovc x264 -x264encopts bitrate=$VBitrate:pass=3:$x264opts -ofps 24  -o "$BN" "$1"
rm "$BN"
if [ ! -s divx2pass.log ]
then
        cp divx2pass.bak divx2pass.log
        touch backup
fi
mencoder $rotate -oac copy -ovc x264 -x264encopts bitrate=$VBitrate:pass=3:$x264opts -ofps 24 -o "$BN" "$1"
rm divx2pass.log
if [ -s divx2pass.bak ]
then
        rm divx2pass.bak
fi
if [ -s divx2pass.log.temp ]
then
        rm divx2pass.log.temp
fi

La dernière version : la version en python qui essaye de devier quel est le meilleur traitement a effectuer pour la bande son :

#!/usr/bin/python
#X264 version of rencoder written in python
# 16/03/2008  J. Kieffer
#
#rencoder.py [-cw|-ccw] [-copyaudio] files.mpg files.avi
#
#
#
VBitrate=600
ABitRate=64
x264opts="subq=7:nr=100:me=umh:partitions=all:direct_pred=auto:b_pyramid:bframes=3:frameref=5 -ofps 24"
mplayer="/usr/bin/mplayer"
mencoder="/usr/bin/mencoder"
sox="/usr/bin/sox"
import sys,os,tempfile,shutil
rotate=" "
DoAudio=True
files=[]
for i in sys.argv[1:]:
        if i.lower()=="-cv": rotate=" -vf rotate=1 "
        elif i.lower()=="-ccw": rotate=" -vf rotate=2 "
        elif i.lower()=="-copyaudio":DoAudio=False
        elif os.path.isfile(i):files.append(i)
        else: print "Unreconized option: "+i
for file in files:
                - path.splitext(file)[0]+"-H264.avi"
        if os.path.isfile(basename): os.remove(basename)
        if DoAudio:
                print "Reading audio track"
                                - popen("%s %s -identify -vo null -ao null -frames 0 "%(mplayer,file))
                for i in sout.readlines():
                        if i.find("ID_AUDIO_NCH")==0:ID_AUDIO_NCH=i.split("=")[1].strip()
                        elif i.find("ID_AUDIO_RATE")==0:ID_AUDIO_RATE=i.split("=")[1].strip()
                        elif i.find("ID_AUDIO_BITRATE")==0:ID_AUDIO_BITRATE=i.split("=")[1].strip()
                print ID_AUDIO_NCH,ID_AUDIO_RATE,ID_AUDIO_BITRATE
                if float(ID_AUDIO_BITRATE)<=ABitRate*1000.0+1:DoAudio=False
                if DoAudio:
                                                - mkstemp(suffix=".raw")
                                                - system(mplayer+" %s -dumpaudio   -dumpfile %s "%(file,rawaudio))
                                                - mkstemp(suffix=".wav")
                                                - system(sox+" -r %s -c %s -u -b -t raw %s -r 44100 %s resample  "%(ID_AUDIO_RATE,ID_AUDIO_NCH,rawaudio,wavaudio))
                                                - remove(rawaudio)
                - system(mencoder+rotate+"-oac copy -ovc x264 -x264encopts bitrate=%s:pass=1:turbo=1:%s -o %s %s"%(VBitrate,x264opts,basename,file))
                - remove(basename)
                - system(mencoder+rotate+"-oac copy -ovc x264 -x264encopts bitrate=%s:pass=3:%s -o %s %s"%(VBitrate,x264opts,basename,file))
                - remove(basename)
        if not DoAudio:
                                - system(mencoder+rotate+"-oac copy -ovc x264 -x264encopts bitrate=%s:pass=3:%s -o %s %s"%(VBitrate,x264opts,basename,file))
        else:
                                - system(mencoder+rotate+"-oac mp3lame -lameopts mode=3:vbr=3:br=%s -audiofile %s -ovc x264 -x264encopts bitrate=%s:pass=3:%s -o %s %s "%(ABitRate,wavaudio,VBitrate,x264opts,basename,file))
                                - remove(wavaudio)
        if os.path.isfile("divx2pass.log"):os.remove("divx2pass.log")
        if os.path.isfile("divx2pass.log.temp"):os.remove("divx2pass.log.temp")