@@ -534,20 +534,17 @@ container. Can be used for fuzzing or testing error resilience/concealment.
Parameters:
@table @option
@item amount
-A numeral string, whose value is related to how often output bytes will
-be modified. Therefore, values below or equal to 0 are forbidden, and
-the lower the more frequent bytes will be modified, with 1 meaning
-every byte is modified.
+Accepts a positive integer. Lower the value, more frequently bytes will be modified,
+with @var{1} meaning every byte is modified. Default is @var{0}.
@item dropamount
-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.
+Accepts a positive integer. Lower the value, more frequently packets will be dropped,
+with @var{1} meaning every packet is dropped. Default is @var{0}.
@end table
The following example applies the modification to every byte but does not drop
any packets.
@example
-ffmpeg -i INPUT -c copy -bsf noise[=1] output.mkv
+ffmpeg -i INPUT -c copy -bsf noise=amount=1 output.mkv
@end example
@section null
@@ -33,20 +33,28 @@ typedef struct NoiseContext {
unsigned int state;
} NoiseContext;
-static int noise(AVBSFContext *ctx, AVPacket *pkt)
+static int noise_init(AVBSFContext *ctx)
{
NoiseContext *s = ctx->priv_data;
- int amount = s->amount > 0 ? s->amount : (s->state % 10001 + 1);
- int i, ret;
- if (amount <= 0)
+ if (!s->amount && !s->dropamount) {
+ av_log(ctx, AV_LOG_ERROR, "At least one of amount and dropamount must be set.\n");
return AVERROR(EINVAL);
+ }
+
+ return 0;
+}
+
+static int noise(AVBSFContext *ctx, AVPacket *pkt)
+{
+ NoiseContext *s = ctx->priv_data;
+ int i, ret;
ret = ff_bsf_get_packet_ref(ctx, pkt);
if (ret < 0)
return ret;
- if (s->dropamount > 0 && s->state % s->dropamount == 0) {
+ if (s->dropamount && s->state % s->dropamount == 0) {
s->state++;
av_packet_unref(pkt);
return AVERROR(EAGAIN);
@@ -60,7 +68,7 @@ static int noise(AVBSFContext *ctx, AVPacket *pkt)
for (i = 0; i < pkt->size; i++) {
s->state += pkt->data[i] + 1;
- if (s->state % amount == 0)
+ if (s->amount && s->state % s->amount == 0)
pkt->data[i] = s->state;
}
@@ -86,5 +94,6 @@ const AVBitStreamFilter ff_noise_bsf = {
.name = "noise",
.priv_data_size = sizeof(NoiseContext),
.priv_class = &noise_class,
+ .init = noise_init,
.filter = noise,
};