[FFmpeg-devel] H.261 chroma motion vector rounding.

Michael Niedermayer michael at niedermayer.cc
Mon Apr 3 02:29:57 EEST 2017

On Sun, Apr 02, 2017 at 09:48:12PM +0100, Christina Brien wrote:
> > wouldn't
> > ROUNDED_DIV() macro be more appropriate?
> ROUNDED_DIV rounds to nearest. The specification states to round towards zero.
> > the Changelog is not supposed to include these kind of changes.
> I assumed Changelog was for incompatible changes, of which this would be. I have removed the change.
> Thanks,
> Christina

>  mpegvideo_motion.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> f301a70a49498419b0d5cde4c5939fbd328e8546  0001-H.261-chroma-motion-vectors-round-towards-zero.patch
> From 12bca148ff4f9860ad32dd2887603f13185b9e68 Mon Sep 17 00:00:00 2001
> From: Christina Brien <christina.brien at 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.

This is not correct


5 The result of the / operator is the quotient from the division of the first operand by the
  second; the result of the % operator is the remainder. In both operations, if the value of
  the second operand is zero, the behavior is undefined.
6 When integers are divided, the result of the / operator is the algebraic quotient with any
  fractional part discarded.90) If the quotient a/b is representable, the expression
  (a/b)*b + a%b shall equal a.

> 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(-)

breaks make fate

If you are still unsure what is correct, it would probably be best
if you used a reference h261 files or a reference implementation
that originates from the ITU committe and compare agaist that

Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170403/e3187472/attachment.sig>

More information about the ffmpeg-devel mailing list