[FFmpeg-devel] [PATCH] avcodec/noise_bsf: Add keyframes option.
Josh Allmann
joshua.allmann at gmail.com
Tue Mar 6 22:47:15 EET 2018
---
doc/bitstream_filters.texi | 5 +++++
libavcodec/noise_bsf.c | 12 ++++++++++++
libavcodec/version.h | 2 +-
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index cfd81fa12d..a9f17f32ec 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -399,6 +399,11 @@ every byte is modified.
A numeral string, whose value is related to how often packets will be dropped.
Therefore, values below or equal to 0 are forbidden, and the lower the more
frequent packets will be dropped, with 1 meaning every packet is dropped.
+ at item keyframes
+A numeral string, whose value indicates the number of keyframe packets that
+will be dropped from the beginning of the stream. This option will not add
+noise to the source data. If used with stream copy, then -copyinkf should
+be added to the output options as well.
@end table
The following example applies the modification to every byte but does not drop
diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
index 84b94032ad..363ea4fc71 100644
--- a/libavcodec/noise_bsf.c
+++ b/libavcodec/noise_bsf.c
@@ -32,6 +32,7 @@ typedef struct NoiseContext {
const AVClass *class;
int amount;
int dropamount;
+ int keyframes;
unsigned int state;
} NoiseContext;
@@ -49,6 +50,13 @@ static int noise(AVBSFContext *ctx, AVPacket *out)
if (ret < 0)
return ret;
+ if (s->keyframes > 0 && in->flags & AV_PKT_FLAG_KEY) {
+ s->keyframes--;
+ if (!s->keyframes) s->keyframes = -1;
+ av_packet_free(&in);
+ return AVERROR(EAGAIN);
+ }
+
if (s->dropamount > 0 && s->state % s->dropamount == 0) {
s->state++;
av_packet_free(&in);
@@ -65,6 +73,9 @@ static int noise(AVBSFContext *ctx, AVPacket *out)
memcpy(out->data, in->data, in->size);
+ if (s->keyframes)
+ return ret;
+
for (i = 0; i < out->size; i++) {
s->state += out->data[i] + 1;
if (s->state % amount == 0)
@@ -81,6 +92,7 @@ fail:
static const AVOption options[] = {
{ "amount", NULL, OFFSET(amount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX },
{ "dropamount", NULL, OFFSET(dropamount), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX },
+ { "keyframes", NULL, OFFSET(keyframes), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX },
{ NULL },
};
diff --git a/libavcodec/version.h b/libavcodec/version.h
index ca18ce6e8b..1e84410d68 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#define LIBAVCODEC_VERSION_MAJOR 58
#define LIBAVCODEC_VERSION_MINOR 13
-#define LIBAVCODEC_VERSION_MICRO 100
+#define LIBAVCODEC_VERSION_MICRO 101
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \
--
2.14.2
More information about the ffmpeg-devel
mailing list