#make fprofiled

IN="The.Matrix.Reloaded.2003.720p.HDDVD.DTS.x264-ESiR.clip.mkv -vf crop=1280:528 -ss 85 -frames 10000"

run() {
    LOG="x264.prof.$1.0"
    echo "x264 $2" > $LOG
    ./x264 --version >> $LOG
    echo gcc 4.2.3 fprofiled >> $LOG
    rm -f fifo.y4m
    mkfifo fifo.y4m
    sudo opcontrol --deinit
    sudo opcontrol --reset
    sudo opcontrol --start $EVENT
    mplayer $IN -vo yuv4mpeg:file=fifo.y4m -nosound -benchmark -nocache &
    ./x264 fifo.y4m $2 --no-ssim --no-psnr --aq-mode 0 --threads 3 --thread-input -o /dev/null >> $LOG 2>&1
    sudo opcontrol --stop
    sudo opcontrol --dump
    opreport -l ./x264 >> $LOG
}

runs() {
    run vf  "--crf 20 -b3 -r1 -m1 -Anone --me dia"
    run f   "--crf 20 -b3 -r1 -m3 -t0 -8"
    run vlc "--crf 20 -b3 -r4 -m7 -t0 -8 -w --mixed-refs --me umh --merange 12 --no-cabac"
    run m   "--crf 20 -b3 -r4 -m7 -t1 -8 -w --mixed-refs --me umh --merange 12"
    run s   "--crf 20 -b3 -r6 -m9 -t2 -8 -w --mixed-refs --me umh -Aall --direct auto --no-fast-pskip"
    run l   "-q0 -m4 --scenecut 5"
    rm -f fifo.y4m
    for i in x264.prof.*.0 ; do head -3 $i > ${i%\.0}.1 ; merge_oprof_x264.pl $i >> ${i%\.0}.1 ; done
}

EVENT="--event CPU_CLK_UNHALTED:100000"
runs
