[FFmpeg-devel] [PATCH] avcodec/keyframe_bsf: add keyframe bitstream filter

Aman Gupta ffmpeg at tmm1.net
Tue Jun 3 21:20:30 CEST 2014


Signed-off-by: Aman Gupta <ffmpeg at tmm1.net>
---
 libavcodec/Makefile       |  1 +
 libavcodec/allcodecs.c    |  1 +
 libavcodec/keyframe_bsf.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 libavcodec/keyframe_bsf.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ce8521f..3bddb03 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -805,6 +805,7 @@ OBJS-$(CONFIG_VP9_PARSER)              += vp9_parser.o
 OBJS-$(CONFIG_AAC_ADTSTOASC_BSF)          += aac_adtstoasc_bsf.o aacadtsdec.o \
                                              mpeg4audio.o
 OBJS-$(CONFIG_CHOMP_BSF)                  += chomp_bsf.o
+OBJS-$(CONFIG_KEYFRAME_BSF)               += keyframe_bsf.o
 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF)         += dump_extradata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)       += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)        += imx_dump_header_bsf.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 7650543..382b928 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -578,6 +578,7 @@ void avcodec_register_all(void)
     /* bitstream filters */
     REGISTER_BSF(AAC_ADTSTOASC,         aac_adtstoasc);
     REGISTER_BSF(CHOMP,                 chomp);
+    REGISTER_BSF(KEYFRAME,              keyframe);
     REGISTER_BSF(DUMP_EXTRADATA,        dump_extradata);
     REGISTER_BSF(H264_MP4TOANNEXB,      h264_mp4toannexb);
     REGISTER_BSF(IMX_DUMP_HEADER,       imx_dump_header);
diff --git a/libavcodec/keyframe_bsf.c b/libavcodec/keyframe_bsf.c
new file mode 100644
index 0000000..0705df1
--- /dev/null
+++ b/libavcodec/keyframe_bsf.c
@@ -0,0 +1,48 @@
+/*
+ * Keyframe bitstream filter
+ * Copyright (c) 2014 Aman Gupta <ffmpeg at tmm1.net>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "internal.h"
+
+static int keyframe_filter(AVBitStreamFilterContext *bsfc,
+                           AVCodecContext *avctx, const char *args,
+                           uint8_t  **poutbuf, int *poutbuf_size,
+                           const uint8_t *buf, int      buf_size,
+                           int keyframe)
+{
+    if (keyframe) {
+      *poutbuf = (uint8_t*) buf;
+      *poutbuf_size = buf_size;
+    } else {
+      *poutbuf = NULL;
+      *poutbuf_size = 0;
+    }
+
+    return 0;
+}
+
+/**
+ * This filter only allows keyframes through.
+ */
+AVBitStreamFilter ff_keyframe_bsf = {
+    .name   = "keyframe",
+    .filter = keyframe_filter,
+};
-- 
1.9.1



More information about the ffmpeg-devel mailing list