src/main/java/org/jcodec/codecs/h264/decode/MBlockDecoderUtils.java
public static int calcMVPredictionMedian(int a, int b, int c, int d, boolean aAvb, boolean bAvb, boolean cAvb,
            boolean dAvb, int ref, int comp) {

        if (!cAvb) {
            c = d;
            cAvb = dAvb;
        }

        if (aAvb && !bAvb && !cAvb) {
            b = c = a;
            bAvb = cAvb = aAvb;
        }

        a = aAvb ? a : NULL_VECTOR;
        b = bAvb ? b : NULL_VECTOR;
        c = cAvb ? c : NULL_VECTOR;

        if (mvRef(a) == ref && mvRef(b) != ref && mvRef(c) != ref)
            return mvC(a, comp);
        else if (mvRef(b) == ref && mvRef(a) != ref && mvRef(c) != ref)
            return mvC(b, comp);
        else if (mvRef(c) == ref && mvRef(a) != ref && mvRef(b) != ref)
            return mvC(c, comp);

        return mvC(a, comp) + mvC(b, comp) + mvC(c, comp) - min(mvC(a, comp), mvC(b, comp), mvC(c, comp))
                - max(mvC(a, comp), mvC(b, comp), mvC(c, comp));
    }
public static int calcMVPredictionMedian(int a, int b, int c, int d, boolean aAvb, boolean bAvb, boolean cAvb,
            boolean dAvb, int ref, int comp) {

        if (!cAvb) {
            c = d;
            cAvb = dAvb;
        }

        if (aAvb && !bAvb && !cAvb) {
            b = c = a;
            bAvb = cAvb = aAvb;
        }

        a = aAvb ? a : NULL_VECTOR;
        b = bAvb ? b : NULL_VECTOR;
        c = cAvb ? c : NULL_VECTOR;

        if (mvRef(a) == ref && mvRef(b) != ref && mvRef(c) != ref)
            return mvC(a, comp);
        else if (mvRef(b) == ref && mvRef(a) != ref && mvRef(c) != ref)
            return mvC(b, comp);
        else if (mvRef(c) == ref && mvRef(a) != ref && mvRef(b) != ref)
            return mvC(c, comp);

        return mvC(a, comp) + mvC(b, comp) + mvC(c, comp) - min(mvC(a, comp), mvC(b, comp), mvC(c, comp))
                - max(mvC(a, comp), mvC(b, comp), mvC(c, comp));
    }
Calculates median prediction
@param a, b, c and d are packed motion vectors