IN="matrix2.mkv -vf crop=1280:528 -ss 85 -frames 10000"

run() {
    LOG="x264.prof.$1.0"
    echo "x264 $2" > $LOG
    ./x264 --version >> $LOG
    perl -pi -e 's/gcc: \S+/$& 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-progress -o /dev/null >> $LOG 2>&1
    sudo opcontrol --stop
    sudo opcontrol --dump
    opreport -l ./x264 >> $LOG
}

runs() {
    run p0  "--crf 20 --preset ultrafast"
    run p1  "--crf 20 --preset veryfast"
    run p2  "--crf 20 --preset faster"
    run p3  "--crf 20 --preset fast"
    run p4  "--crf 20 --preset medium"
    run p5  "--crf 20 --preset slow"
    run p6  "--crf 20 --preset slower"
    run p7  "--crf 20 --preset veryslow"
    run p8  "--crf 20 --preset placebo"
    run baseline "--crf 20 --preset medium --profile baseline"
    run lossless "--qp 0 --preset fast"
    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
