From 12bca148ff4f9860ad32dd2887603f13185b9e68 Mon Sep 17 00:00:00 2001
From: Christina Brien <christina.brien@polygonindustrial.com>
Date: Thu, 30 Mar 2017 23:38:03 +0100
Subject: [PATCH] H.261 chroma motion vectors round towards zero.

ITU-T H.261 (03/93) Section 3.2.2 states "The motion vector for both colour
difference blocks is derived by halving the component values of the macroblock
vector and truncating the magnitude parts towards zero to yield integer
components."

Simple integer division rounds towards negative infinity, not towards zero.
Negative numbers need to be rounded up, by adding (divisor/2) before division.
---
 libavcodec/mpegvideo_motion.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c
index c913504..e92fb0d 100644
--- a/libavcodec/mpegvideo_motion.c
+++ b/libavcodec/mpegvideo_motion.c
@@ -268,8 +268,8 @@ void mpeg_motion_internal(MpegEncContext *s,
         }
     // Even chroma mv's are full pel in H261
     } else if (!is_mpeg12 && s->out_format == FMT_H261) {
-        mx      = motion_x / 4;
-        my      = motion_y / 4;
+        mx      = ((motion_x < 0) ? (motion_x + 2) : motion_x) / 4;
+        my      = ((motion_y < 0) ? (motion_y + 2) : motion_y) / 4;
         uvdxy   = 0;
         uvsrc_x = s->mb_x * 8 + mx;
         uvsrc_y = mb_y * 8 + my;
-- 
2.8.4 (Apple Git-73)

