diff options
author | Dmitry Samonenko <shreddingwork@gmail.com> | 2012-09-29 15:47:28 +0400 |
---|---|---|
committer | Martin Storsjö <martin@martin.st> | 2012-10-03 19:23:39 +0300 |
commit | ad11681acd59a9eb00952d07224a78bfc71c48ea (patch) | |
tree | 6ee04bd00fff3b92c92560fb3b62dfa3afeee1c7 /libavcodec/libspeexenc.c | |
parent | f0fce9f33e604544c678b6de4c29301ed4d0751f (diff) | |
download | ffmpeg-ad11681acd59a9eb00952d07224a78bfc71c48ea.tar.gz |
libspeex: Add a private option for enabling VAD
Speex detects non-speech periods and encodes them with just enough bits
to reproduce the background noise, aka ``comfort noise generation''.
Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavcodec/libspeexenc.c')
-rw-r--r-- | libavcodec/libspeexenc.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libavcodec/libspeexenc.c b/libavcodec/libspeexenc.c index 38fa4cd5ca..43f84dc5f4 100644 --- a/libavcodec/libspeexenc.c +++ b/libavcodec/libspeexenc.c @@ -84,6 +84,7 @@ typedef struct { float vbr_quality; ///< VBR quality 0.0 to 10.0 int cbr_quality; ///< CBR quality 0 to 10 int abr; ///< flag to enable ABR + int vad; ///< flag to enable VAD int pkt_frame_count; ///< frame count for the current packet AudioFrameQueue afq; ///< frame queue } LibSpeexEncContext; @@ -118,6 +119,7 @@ static av_cold void print_enc_params(AVCodecContext *avctx, s->frames_per_packet); av_log(avctx, AV_LOG_DEBUG, "packet size: %d\n", avctx->frame_size * s->frames_per_packet); + av_log(avctx, AV_LOG_DEBUG, "voice activity detection: %d\n", s->vad); } static av_cold int encode_init(AVCodecContext *avctx) @@ -158,6 +160,7 @@ static av_cold int encode_init(AVCodecContext *avctx) if (avctx->flags & CODEC_FLAG_QSCALE) { /* VBR */ s->header.vbr = 1; + s->vad = 1; /* VAD is always implicitly activated for VBR */ speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR, &s->header.vbr); s->vbr_quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA, 0.0f, 10.0f); @@ -189,6 +192,10 @@ static av_cold int encode_init(AVCodecContext *avctx) avctx->bit_rate = s->header.bitrate + (avctx->channels == 2 ? 800 : 0); } + /* VAD is activated with VBR or can be turned on by itself */ + if (s->vad) + speex_encoder_ctl(s->enc_state, SPEEX_SET_VAD, &s->vad); + /* set encoding complexity */ if (avctx->compression_level > FF_COMPRESSION_DEFAULT) { complexity = av_clip(avctx->compression_level, 0, 10); @@ -310,6 +317,7 @@ static const AVOption options[] = { { "abr", "Use average bit rate", OFFSET(abr), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE }, { "cbr_quality", "Set quality value (0 to 10) for CBR", OFFSET(cbr_quality), AV_OPT_TYPE_INT, { .i64 = 8 }, 0, 10, AE }, { "frames_per_packet", "Number of frames to encode in each packet", OFFSET(frames_per_packet), AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 8, AE }, + { "vad", "Voice Activity Detection", OFFSET(vad), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AE }, { NULL }, }; |