diff --git a/libavcodec/h264dsp_template.c b/libavcodec/h264dsp_template.c
index 91162ea900473fda0b715529e308cb2cc5d0625b..be88f7487fb6f512c79f300bf1ac1a8b01c07fff 100644
--- a/libavcodec/h264dsp_template.c
+++ b/libavcodec/h264dsp_template.c
@@ -63,6 +63,7 @@ static void FUNCC(biweight_h264_pixels ## W ## x ## H)(uint8_t *_dst, uint8_t *_
     pixel *dst = (pixel*)_dst; \
     pixel *src = (pixel*)_src; \
     stride /= sizeof(pixel); \
+    offset <<= (BIT_DEPTH-8); \
     offset = ((offset + 1) | 1) << log2_denom; \
     for(y=0; y<H; y++, dst += stride, src += stride){ \
         op_scale2(0); \