[FFmpeg-cvslog] lavd/kmsgrab: Fix packet flag setting

2017-09-14 Thread Mark Thompson
ffmpeg | branch: master | Mark Thompson  | Thu Sep 14 09:14:36 
2017 +0100| [16b44d9ab9fd81e4dfc5631a5fbc081b564f1037] | committer: Mark 
Thompson

lavd/kmsgrab: Fix packet flag setting

Found-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=16b44d9ab9fd81e4dfc5631a5fbc081b564f1037
---

 libavdevice/kmsgrab.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavdevice/kmsgrab.c b/libavdevice/kmsgrab.c
index d0b9cf5001..d222abfd60 100644
--- a/libavdevice/kmsgrab.c
+++ b/libavdevice/kmsgrab.c
@@ -190,10 +190,10 @@ static int kmsgrab_read_packet(AVFormatContext *avctx, 
AVPacket *pkt)
 if (!pkt->buf)
 return AVERROR(ENOMEM);
 
-pkt->data  = (uint8_t*)frame;
-pkt->size  = sizeof(*frame);
-pkt->pts   = now;
-pkt->flags = AV_PKT_FLAG_TRUSTED;
+pkt->data   = (uint8_t*)frame;
+pkt->size   = sizeof(*frame);
+pkt->pts= now;
+pkt->flags |= AV_PKT_FLAG_TRUSTED;
 
 return 0;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avfilter/vf_despill: fix assigment

2017-09-14 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Thu Sep 14 18:05:57 
2017 +0200| [133002e8ae51078709d626ffa2eff9ec8779bd80] | committer: Paul B Mahol

avfilter/vf_despill: fix assigment

Reported-by: Moritz Barsnick
Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=133002e8ae51078709d626ffa2eff9ec8779bd80
---

 libavfilter/vf_despill.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/vf_despill.c b/libavfilter/vf_despill.c
index eff9877a1c..64c27f4060 100644
--- a/libavfilter/vf_despill.c
+++ b/libavfilter/vf_despill.c
@@ -161,7 +161,7 @@ static const AVOption despill_options[] = {
 {   "blue", "bluescreen",  0,   
AV_OPT_TYPE_CONST,   {.i64=1}, 0,   0, FLAGS, "type" },
 { "mix","set the spillmap mix",OFFSET(spillmix),
AV_OPT_TYPE_FLOAT,   {.dbl=0.5},   0,   1, FLAGS },
 { "expand", "set the spillmap expand", OFFSET(spillexpand), 
AV_OPT_TYPE_FLOAT,   {.dbl=0}, 0,   1, FLAGS },
-{ "red","set red scale",   OFFSET(bluescale),   
AV_OPT_TYPE_FLOAT,   {.dbl=0},  -100, 100, FLAGS },
+{ "red","set red scale",   OFFSET(redscale),
AV_OPT_TYPE_FLOAT,   {.dbl=0},  -100, 100, FLAGS },
 { "green",  "set green scale", OFFSET(greenscale),  
AV_OPT_TYPE_FLOAT,   {.dbl=-1}, -100, 100, FLAGS },
 { "blue",   "set blue scale",  OFFSET(bluescale),   
AV_OPT_TYPE_FLOAT,   {.dbl=0},  -100, 100, FLAGS },
 { "brightness", "set brightness",  OFFSET(brightness),  
AV_OPT_TYPE_FLOAT,   {.dbl=0},   -10,  10, FLAGS },

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] kmsgrab: Fix build failure with old libdrm

2017-09-14 Thread Jun Zhao
ffmpeg | branch: master | Jun Zhao  | Wed Sep 13 20:21:38 
2017 -0400| [462568185b0af4d651441ae397cc83bdb7e573ed] | committer: Mark 
Thompson

kmsgrab: Fix build failure with old libdrm

DRM_FORMAT_R8 was added in libdrm 2.4.68.
DRM_FORMAT_R16 was added in libdrm 2.4.82.

Signed-off-by: Jun Zhao 
Signed-off-by: Mark Thompson 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=462568185b0af4d651441ae397cc83bdb7e573ed
---

 libavdevice/kmsgrab.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavdevice/kmsgrab.c b/libavdevice/kmsgrab.c
index d222abfd60..67a83ef84a 100644
--- a/libavdevice/kmsgrab.c
+++ b/libavdevice/kmsgrab.c
@@ -202,8 +202,12 @@ static const struct {
 enum AVPixelFormat pixfmt;
 uint32_t drm_format;
 } kmsgrab_formats[] = {
+#ifdef DRM_FORMAT_R8
 { AV_PIX_FMT_GRAY8,DRM_FORMAT_R8   },
+#endif
+#ifdef DRM_FORMAT_R16
 { AV_PIX_FMT_GRAY16LE, DRM_FORMAT_R16  },
+#endif
 { AV_PIX_FMT_RGB24,DRM_FORMAT_RGB888   },
 { AV_PIX_FMT_BGR24,DRM_FORMAT_BGR888   },
 { AV_PIX_FMT_0RGB, DRM_FORMAT_XRGB },

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] hwcontext_vaapi: Fix build failure with old libdrm

2017-09-14 Thread Jun Zhao
ffmpeg | branch: master | Jun Zhao  | Wed Sep 13 20:21:38 
2017 -0400| [197d298ab3b27d1ec2ee7bf568debca105881a54] | committer: Mark 
Thompson

hwcontext_vaapi: Fix build failure with old libdrm

Signed-off-by: Jun Zhao 
Signed-off-by: Mark Thompson 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=197d298ab3b27d1ec2ee7bf568debca105881a54
---

 libavutil/hwcontext_vaapi.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 2cc6f26715..852f0abda2 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -918,9 +918,11 @@ static const struct {
 int   nb_layer_formats;
 uint32_t layer_formats[AV_DRM_MAX_PLANES];
 } vaapi_drm_format_map[] = {
+#ifdef DRM_FORMAT_R8
 DRM_MAP(NV12, 2, DRM_FORMAT_R8,  DRM_FORMAT_RG88),
+#endif
 DRM_MAP(NV12, 1, DRM_FORMAT_NV12),
-#ifdef VA_FOURCC_P010
+#if defined(VA_FOURCC_P010) && defined(DRM_FORMAT_R16)
 DRM_MAP(P010, 2, DRM_FORMAT_R16, DRM_FORMAT_RG1616),
 #endif
 DRM_MAP(BGRA, 1, DRM_FORMAT_BGRA),

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog


[FFmpeg-cvslog] avcodec/mips: Improve hevc idct msa functions

2017-09-14 Thread Kaustubh Raste
ffmpeg | branch: master | Kaustubh Raste  | Tue Sep 
12 17:19:58 2017 +0530| [c6314cd750dfba2505a232cc16541395c986613a] | committer: 
Michael Niedermayer

avcodec/mips: Improve hevc idct msa functions

Align the buffers. Remove reduandant constant array.

Signed-off-by: Kaustubh Raste 
Reviewed-by: Manojkumar Bhosale 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c6314cd750dfba2505a232cc16541395c986613a
---

 libavcodec/mips/hevc_idct_msa.c | 255 +++-
 1 file changed, 171 insertions(+), 84 deletions(-)

diff --git a/libavcodec/mips/hevc_idct_msa.c b/libavcodec/mips/hevc_idct_msa.c
index d483707e72..09431196bb 100644
--- a/libavcodec/mips/hevc_idct_msa.c
+++ b/libavcodec/mips/hevc_idct_msa.c
@@ -21,18 +21,18 @@
 #include "libavutil/mips/generic_macros_msa.h"
 #include "libavcodec/mips/hevcdsp_mips.h"
 
-static const int16_t gt8x8_cnst[16] = {
+static const int16_t gt8x8_cnst[16] __attribute__ ((aligned (64))) = {
 64, 64, 83, 36, 89, 50, 18, 75, 64, -64, 36, -83, 75, -89, -50, -18
 };
 
-static const int16_t gt16x16_cnst[64] = {
+static const int16_t gt16x16_cnst[64] __attribute__ ((aligned (64))) = {
 64, 83, 64, 36, 89, 75, 50, 18, 90, 80, 57, 25, 70, 87, 9, 43,
 64, 36, -64, -83, 75, -18, -89, -50, 87, 9, -80, -70, -43, 57, -25, -90,
 64, -36, -64, 83, 50, -89, 18, 75, 80, -70, -25, 90, -87, 9, 43, 57,
 64, -83, 64, -36, 18, -50, 75, -89, 70, -87, 90, -80, 9, -43, -57, 25
 };
 
-static const int16_t gt32x32_cnst0[256] = {
+static const int16_t gt32x32_cnst0[256] __attribute__ ((aligned (64))) = {
 90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4,
 90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
 88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22,
@@ -51,21 +51,17 @@ static const int16_t gt32x32_cnst0[256] = {
 4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90
 };
 
-static const int16_t gt32x32_cnst1[64] = {
+static const int16_t gt32x32_cnst1[64] __attribute__ ((aligned (64))) = {
 90, 87, 80, 70, 57, 43, 25, 9, 87, 57, 9, -43, -80, -90, -70, -25,
 80, 9, -70, -87, -25, 57, 90, 43, 70, -43, -87, 9, 90, 25, -80, -57,
 57, -80, -25, 90, -9, -87, 43, 70, 43, -90, 57, 25, -87, 70, 9, -80,
 25, -70, 90, -80, 43, 9, -57, 87, 9, -25, 43, -57, 70, -80, 87, -90
 };
 
-static const int16_t gt32x32_cnst2[16] = {
+static const int16_t gt32x32_cnst2[16] __attribute__ ((aligned (64))) = {
 89, 75, 50, 18, 75, -18, -89, -50, 50, -89, 18, 75, 18, -50, 75, -89
 };
 
-static const int16_t gt32x32_cnst3[16] = {
-64, 64, 64, 64, 83, 36, -36, -83, 64, -64, -64, 64, 36, -83, 83, -36
-};
-
 #define HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1,  \
  sum0, sum1, sum2, sum3, shift)   \
 { \
@@ -323,8 +319,12 @@ static void hevc_idct_4x4_msa(int16_t *coeffs)
 HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1, sum0, sum1, sum2, sum3, 7);
 TRANSPOSE4x4_SW_SW(sum0, sum1, sum2, sum3, in_r0, in_l0, in_r1, in_l1);
 HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1, sum0, sum1, sum2, sum3, 12);
-TRANSPOSE4x4_SW_SW(sum0, sum1, sum2, sum3, sum0, sum1, sum2, sum3);
-PCKEV_H2_SH(sum1, sum0, sum3, sum2, in0, in1);
+
+/* Pack and transpose */
+PCKEV_H2_SH(sum2, sum0, sum3, sum1, in0, in1);
+ILVRL_H2_SW(in1, in0, sum0, sum1);
+ILVRL_W2_SH(sum1, sum0, in0, in1);
+
 ST_SH2(in0, in1, coeffs, 8);
 }
 
@@ -432,27 +432,35 @@ static void hevc_idct_8x32_column_msa(int16_t *coeffs, 
uint8_t buf_pitch,
 const int16_t *filter_ptr0 = >32x32_cnst0[0];
 const int16_t *filter_ptr1 = >32x32_cnst1[0];
 const int16_t *filter_ptr2 = >32x32_cnst2[0];
-const int16_t *filter_ptr3 = >32x32_cnst3[0];
+const int16_t *filter_ptr3 = >8x8_cnst[0];
 int16_t *src0 = (coeffs + buf_pitch);
 int16_t *src1 = (coeffs + 2 * buf_pitch);
 int16_t *src2 = (coeffs + 4 * buf_pitch);
 int16_t *src3 = (coeffs);
 int32_t cnst0, cnst1;
-int32_t tmp_buf[8 * 32];
-int32_t *tmp_buf_ptr = &tmp_buf[0];
+int32_t tmp_buf[8 * 32 + 15];
+int32_t *tmp_buf_ptr = tmp_buf + 15;
 v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
 v8i16 src0_r, src1_r, src2_r, src3_r, src4_r, src5_r, src6_r, src7_r;
 v8i16 src0_l, src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l;
 v8i16 filt0, filter0, filter1, filter2, filter3;
 v4i32 sum0_r, sum0_l, sum1_r, sum1_l, tmp0_r, tmp0_l, tmp1_r, tmp1_l;
 
+/* Align pointer to 64 byte boundary */
+tmp_buf_ptr = (int32_t *)(((uintptr_t) tmp_buf_ptr) & ~(uintptr_t) 63);
+
 /* process coeff 4, 12, 20, 28 */
 LD_SH4(src2, 8 * buf_pitch, in0, in1, in2, in3);
 ILVR_H2_SH(in1, in0, in3, in2, src0_r, src1_r);
 ILVL_H2_SH(in1, in0, in3, in2, src0_l, src1_l);
 
+LD_SH2(src3, 16 * buf_pitch, in4, in6);
+LD_SH2((src3 + 8 * buf_pitch), 16 

[FFmpeg-cvslog] avcodec/mips: Improve hevc lpf msa functions

2017-09-14 Thread Kaustubh Raste
ffmpeg | branch: master | Kaustubh Raste  | Tue Sep 
12 17:03:12 2017 +0530| [f692e55aab79729ca6d6b00c2671cac116903958] | committer: 
Michael Niedermayer

avcodec/mips: Improve hevc lpf msa functions

Seperate the filter processing in all strong, all weak and strong + weak cases.

Signed-off-by: Kaustubh Raste 
Reviewed-by: Manojkumar Bhosale 
Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f692e55aab79729ca6d6b00c2671cac116903958
---

 libavcodec/mips/hevc_lpf_sao_msa.c | 750 +++--
 1 file changed, 556 insertions(+), 194 deletions(-)

diff --git a/libavcodec/mips/hevc_lpf_sao_msa.c 
b/libavcodec/mips/hevc_lpf_sao_msa.c
index da1db51ef5..79b156fe5c 100644
--- a/libavcodec/mips/hevc_lpf_sao_msa.c
+++ b/libavcodec/mips/hevc_lpf_sao_msa.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Manojkumar Bhosale (manojkumar.bhos...@imgtec.com)
+ * Copyright (c) 2015 -2017 Manojkumar Bhosale (manojkumar.bhos...@imgtec.com)
  *
  * This file is part of FFmpeg.
  *
@@ -35,12 +35,14 @@ static void hevc_loopfilter_luma_hor_msa(uint8_t *src, 
int32_t stride,
 uint8_t *q3 = src + (stride << 1) + stride;
 uint8_t flag0, flag1;
 int32_t dp00, dq00, dp30, dq30, d00, d30;
+int32_t d0030, d0434;
 int32_t dp04, dq04, dp34, dq34, d04, d34;
 int32_t tc0, p_is_pcm0, q_is_pcm0, beta30, beta20, tc250;
 int32_t tc4, p_is_pcm4, q_is_pcm4, tc254, tmp;
 uint64_t dst_val0, dst_val1;
 v16u8 dst0, dst1, dst2, dst3, dst4, dst5;
 v2i64 cmp0, cmp1, cmp2, p_is_pcm_vec, q_is_pcm_vec;
+v2i64 cmp3;
 v8u16 temp0, temp1;
 v8i16 temp2;
 v8i16 tc_pos, tc_neg;
@@ -54,62 +56,86 @@ static void hevc_loopfilter_luma_hor_msa(uint8_t *src, 
int32_t stride,
 dq30 = abs(q2[3] - (q1[3] << 1) + q0[3]);
 d00 = dp00 + dq00;
 d30 = dp30 + dq30;
-p_is_pcm0 = p_is_pcm[0];
-q_is_pcm0 = q_is_pcm[0];
 dp04 = abs(p2[4] - (p1[4] << 1) + p0[4]);
 dq04 = abs(q2[4] - (q1[4] << 1) + q0[4]);
 dp34 = abs(p2[7] - (p1[7] << 1) + p0[7]);
 dq34 = abs(q2[7] - (q1[7] << 1) + q0[7]);
 d04 = dp04 + dq04;
 d34 = dp34 + dq34;
+
+p_is_pcm0 = p_is_pcm[0];
 p_is_pcm4 = p_is_pcm[1];
+q_is_pcm0 = q_is_pcm[0];
 q_is_pcm4 = q_is_pcm[1];
 
-if (!p_is_pcm0 || !p_is_pcm4 || !q_is_pcm0 || !q_is_pcm4) {
-if (!(d00 + d30 >= beta) || !(d04 + d34 >= beta)) {
-p3_src = LD_UH(p3);
-p2_src = LD_UH(p2);
-p1_src = LD_UH(p1);
-p0_src = LD_UH(p0);
-q0_src = LD_UH(q0);
-q1_src = LD_UH(q1);
-q2_src = LD_UH(q2);
-q3_src = LD_UH(q3);
-
-tc0 = tc[0];
-beta30 = beta >> 3;
-beta20 = beta >> 2;
-tc250 = ((tc0 * 5 + 1) >> 1);
-tc4 = tc[1];
-tc254 = ((tc4 * 5 + 1) >> 1);
-
-flag0 = (abs(p3[0] - p0[0]) + abs(q3[0] - q0[0]) < beta30 &&
- abs(p0[0] - q0[0]) < tc250 &&
- abs(p3[3] - p0[3]) + abs(q3[3] - q0[3]) < beta30 &&
- abs(p0[3] - q0[3]) < tc250 &&
- (d00 << 1) < beta20 && (d30 << 1) < beta20);
-cmp0 = __msa_fill_d(flag0);
-
-flag1 = (abs(p3[4] - p0[4]) + abs(q3[4] - q0[4]) < beta30 &&
- abs(p0[4] - q0[4]) < tc254 &&
- abs(p3[7] - p0[7]) + abs(q3[7] - q0[7]) < beta30 &&
- abs(p0[7] - q0[7]) < tc254 &&
- (d04 << 1) < beta20 && (d34 << 1) < beta20);
-cmp1 = __msa_fill_d(flag1);
-cmp2 = __msa_ilvev_d(cmp1, cmp0);
-cmp2 = __msa_ceqi_d(cmp2, 0);
-
-ILVR_B8_UH(zero, p3_src, zero, p2_src, zero, p1_src, zero, p0_src,
-   zero, q0_src, zero, q1_src, zero, q2_src, zero, q3_src,
-   p3_src, p2_src, p1_src, p0_src, q0_src, q1_src, q2_src,
-   q3_src);
-
-cmp0 = (v2i64) __msa_fill_h(tc0);
-cmp1 = (v2i64) __msa_fill_h(tc4);
-tc_pos = (v8i16) __msa_ilvev_d(cmp1, cmp0);
+cmp0 = __msa_fill_d(p_is_pcm0);
+cmp1 = __msa_fill_d(p_is_pcm4);
+p_is_pcm_vec = __msa_ilvev_d(cmp1, cmp0);
+p_is_pcm_vec = __msa_ceqi_d(p_is_pcm_vec, 0);
+
+d0030 = (d00 + d30) >= beta;
+d0434 = (d04 + d34) >= beta;
+
+cmp0 = (v2i64) __msa_fill_w(d0030);
+cmp1 = (v2i64) __msa_fill_w(d0434);
+cmp3 = (v2i64) __msa_ilvev_w((v4i32) cmp1, (v4i32) cmp0);
+cmp3 = (v2i64) __msa_ceqi_w((v4i32) cmp3, 0);
+
+if ((!p_is_pcm0 || !p_is_pcm4 || !q_is_pcm0 || !q_is_pcm4) &&
+(!d0030 || !d0434)) {
+p3_src = LD_UH(p3);
+p2_src = LD_UH(p2);
+p1_src = LD_UH(p1);
+p0_src = LD_UH(p0);
+
+cmp0 = __msa_fill_d(q_is_pcm0);
+cmp1 = __msa_fill_d(q_is_pcm4);
+q_is_pcm_vec = __msa_ilvev_d(cmp1, cmp0);
+q_is_pcm_vec = __msa_ceqi_d(q_is_pcm_vec, 0);
+
+tc0 = tc[0];
+beta

[FFmpeg-cvslog] vf_fps: when reading EOF, using current_pts to duplicate the last frame if needed.

2017-09-14 Thread Thierry Foucu
ffmpeg | branch: master | Thierry Foucu  | Tue Sep 12 
18:45:57 2017 -0700| [eea64ef4cfb593cbe28465f45e6bd4c41a79cae1] | committer: 
Michael Niedermayer

vf_fps: when reading EOF, using current_pts to duplicate the last frame if 
needed.

Fix ticket #2674
Tested with examples from ticket 2674.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=eea64ef4cfb593cbe28465f45e6bd4c41a79cae1
---

 libavfilter/vf_fps.c | 44 +++-
 tests/ref/fate/filter-fps|  6 ++
 tests/ref/fate/filter-fps-r  |  4 
 tests/ref/fate/filter-mpdecimate |  1 -
 tests/ref/fate/m4v-cfr   |  1 -
 5 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
index 20ccd797d1..09fc66a73c 100644
--- a/libavfilter/vf_fps.c
+++ b/libavfilter/vf_fps.c
@@ -34,6 +34,8 @@
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 
+#define FF_INTERNAL_FIELDS 1
+#include "framequeue.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "video.h"
@@ -137,13 +139,45 @@ static int request_frame(AVFilterLink *outlink)
 AVFrame *buf;
 
 av_fifo_generic_read(s->fifo, &buf, sizeof(buf), NULL);
-buf->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base,
-outlink->time_base) + s->frames_out;
+if (av_fifo_size(s->fifo)) {
+buf->pts = av_rescale_q(s->first_pts, 
ctx->inputs[0]->time_base,
+outlink->time_base) + s->frames_out;
 
-if ((ret = ff_filter_frame(outlink, buf)) < 0)
-return ret;
+if ((ret = ff_filter_frame(outlink, buf)) < 0)
+return ret;
 
-s->frames_out++;
+s->frames_out++;
+} else {
+/* This is the last frame, we may have to duplicate it to match
+ * the last frame duration */
+int j;
+int delta = av_rescale_q_rnd(ctx->inputs[0]->current_pts - 
s->first_pts,
+ ctx->inputs[0]->time_base,
+ outlink->time_base, s->rounding) 
- s->frames_out ;
+/* if the delta is equal to 1, it means we just need to output
+ * the last frame. Greater than 1 means we will need duplicate
+ * delta-1 frames */
+if (delta > 0 ) {
+for (j = 0; j < delta; j++) {
+AVFrame *dup = av_frame_clone(buf);
+
+av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n");
+dup->pts = av_rescale_q(s->first_pts, 
ctx->inputs[0]->time_base,
+outlink->time_base) + 
s->frames_out;
+
+if ((ret = ff_filter_frame(outlink, dup)) < 0)
+return ret;
+
+s->frames_out++;
+if (j > 0) s->dup++;
+}
+} else {
+/* for delta less or equal to 0, we should drop the frame,
+ * otherwise, we will have one or more extra frames */
+av_frame_free(&buf);
+s->drop++;
+}
+}
 }
 return 0;
 }
diff --git a/tests/ref/fate/filter-fps b/tests/ref/fate/filter-fps
index 55712cfb1c..242fb04e85 100644
--- a/tests/ref/fate/filter-fps
+++ b/tests/ref/fate/filter-fps
@@ -85,3 +85,9 @@
 0, 79, 79,1,30576, 0xa2fcd06f
 0, 80, 80,1,30576, 0xa2fcd06f
 0, 81, 81,1,30576, 0xd4150aad
+0, 82, 82,1,30576, 0xd4150aad
+0, 83, 83,1,30576, 0xd4150aad
+0, 84, 84,1,30576, 0xd4150aad
+0, 85, 85,1,30576, 0xd4150aad
+0, 86, 86,1,30576, 0xd4150aad
+0, 87, 87,1,30576, 0xd4150aad
diff --git a/tests/ref/fate/filter-fps-r b/tests/ref/fate/filter-fps-r
index 826b1ed6c6..c1bc7d1547 100644
--- a/tests/ref/fate/filter-fps-r
+++ b/tests/ref/fate/filter-fps-r
@@ -72,3 +72,7 @@
 0, 79, 79,1,30576, 0xa2fcd06f
 0, 80, 80,1,30576, 0xa2fcd06f
 0, 82, 82,1,30576, 0xd4150aad
+0, 83, 83,1,30576, 0xd4150aad
+0, 84, 84,1,30576, 0xd4150aad
+0, 85, 85,1,30576, 0xd4150aad
+0, 86, 86,1,30576, 0xd4150aad
diff --git a/tests/ref/fate/filter-mpdecimate b/tests/ref/fate/filter-mpdecimate
index d438dacc2e..9c1dc36562 100644
--- a/tests/ref/fate/filter-mpdecimate
+++ b/tests/ref/fate/filter-mpdecimate
@@ -22,4 +22,3 @@