/* * Copyright (c) 2002 Mark Hills <mark@pogo.org.uk> * * 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
*/
/* Number of samples the user should send in each call. * This value is used because it is the LCD of all possible frame sizes, so * an output packet will always start at the same point as one of the input * packets.
*/ #define LIBVORBIS_FRAME_SIZE 64
#define BUFFER_SIZE (1024 * 64)
typedefstruct LibvorbisEncContext {
AVClass *av_class; /**< class for AVOptions */
vorbis_info vi; /**< vorbis_info used during init */
vorbis_dsp_state vd; /**< DSP state used for analysis */
vorbis_block vb; /**< vorbis_block used for analysis */
AVFifo *pkt_fifo; /**< output packet buffer */ int eof; /**< end-of-file flag */ int dsp_initialized; /**< vd has been initialized */
vorbis_comment vc; /**< VorbisComment info */ double iblock; /**< impulse block bias option */
AVVorbisParseContext *vp; /**< parse context to get durations */
AudioFrameQueue afq; /**< frame queue for timestamps */
} LibvorbisEncContext;
staticint vorbis_error_to_averror(int ov_err)
{ switch (ov_err) { case OV_EFAULT: return AVERROR_BUG; case OV_EINVAL: return AVERROR(EINVAL); case OV_EIMPL: return AVERROR(EINVAL); default: return AVERROR_UNKNOWN;
}
}
static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx)
{
LibvorbisEncContext *s = avctx->priv_data; int channels = avctx->ch_layout.nb_channels; double cfreq; int ret;
if (avctx->flags & AV_CODEC_FLAG_QSCALE || !avctx->bit_rate) { /* variable bitrate * NOTE: we use the oggenc range of -1 to 10 for global_quality for * user convenience, but libvorbis uses -0.1 to 1.0.
*/ float q = avctx->global_quality / (float)FF_QP2LAMBDA; /* default to 3 if the user did not set quality or bitrate */ if (!(avctx->flags & AV_CODEC_FLAG_QSCALE))
q = 3.0; if ((ret = vorbis_encode_setup_vbr(vi, channels,
avctx->sample_rate,
q / 10.0))) goto error;
} else { int minrate = avctx->rc_min_rate > 0 ? avctx->rc_min_rate : -1; int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1;
/* average bitrate */ if ((ret = vorbis_encode_setup_managed(vi, channels,
avctx->sample_rate, maxrate,
avctx->bit_rate, minrate))) goto error;
/* variable bitrate by estimate, disable slow rate management */ if (minrate == -1 && maxrate == -1) if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))) goto error; /* should not happen */
}
/* cutoff frequency */ if (avctx->cutoff > 0) {
cfreq = avctx->cutoff / 1000.0; if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))) goto error; /* should not happen */
}
/* impulse block bias */ if (s->iblock) { if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->iblock))) goto error;
}
duration = av_vorbis_parse_frame(s->vp, avpkt->data, avpkt->size); if (duration > 0) { /* we do not know encoder delay until we get the first packet from
* libvorbis, so we have to update the AudioFrameQueue counts */ if (!avctx->initial_padding && s->afq.frames) {
avctx->initial_padding = duration;
av_assert0(!s->afq.remaining_delay);
s->afq.frames->duration += duration; if (s->afq.frames->pts != AV_NOPTS_VALUE)
s->afq.frames->pts -= duration;
s->afq.remaining_samples += duration;
}
ff_af_queue_remove(&s->afq, duration, &avpkt->pts, &avpkt->duration);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.