avconv: use avcodec_decode_audio4() instead of avcodec_decode_audio3()
This commit is contained in:
parent
6d23d19729
commit
d1241ff3b2
55
avconv.c
55
avconv.c
@ -137,8 +137,6 @@ static uint8_t *audio_buf;
|
|||||||
static uint8_t *audio_out;
|
static uint8_t *audio_out;
|
||||||
static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
|
static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
|
||||||
|
|
||||||
static void *samples;
|
|
||||||
|
|
||||||
#define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
|
#define DEFAULT_PASS_LOGFILENAME_PREFIX "av2pass"
|
||||||
|
|
||||||
typedef struct InputStream {
|
typedef struct InputStream {
|
||||||
@ -541,7 +539,6 @@ void exit_program(int ret)
|
|||||||
av_free(audio_buf);
|
av_free(audio_buf);
|
||||||
av_free(audio_out);
|
av_free(audio_out);
|
||||||
allocated_audio_buf_size= allocated_audio_out_size= 0;
|
allocated_audio_buf_size= allocated_audio_out_size= 0;
|
||||||
av_free(samples);
|
|
||||||
|
|
||||||
#if CONFIG_AVFILTER
|
#if CONFIG_AVFILTER
|
||||||
avfilter_uninit();
|
avfilter_uninit();
|
||||||
@ -737,14 +734,11 @@ static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_
|
|||||||
memset(buf, fill_char, size);
|
memset(buf, fill_char, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_audio_out(AVFormatContext *s,
|
static void do_audio_out(AVFormatContext *s, OutputStream *ost,
|
||||||
OutputStream *ost,
|
InputStream *ist, AVFrame *decoded_frame)
|
||||||
InputStream *ist,
|
|
||||||
unsigned char *buf, int size)
|
|
||||||
{
|
{
|
||||||
uint8_t *buftmp;
|
uint8_t *buftmp;
|
||||||
int64_t audio_out_size, audio_buf_size;
|
int64_t audio_out_size, audio_buf_size;
|
||||||
int64_t allocated_for_size= size;
|
|
||||||
|
|
||||||
int size_out, frame_bytes, ret, resample_changed;
|
int size_out, frame_bytes, ret, resample_changed;
|
||||||
AVCodecContext *enc= ost->st->codec;
|
AVCodecContext *enc= ost->st->codec;
|
||||||
@ -752,6 +746,9 @@ static void do_audio_out(AVFormatContext *s,
|
|||||||
int osize = av_get_bytes_per_sample(enc->sample_fmt);
|
int osize = av_get_bytes_per_sample(enc->sample_fmt);
|
||||||
int isize = av_get_bytes_per_sample(dec->sample_fmt);
|
int isize = av_get_bytes_per_sample(dec->sample_fmt);
|
||||||
const int coded_bps = av_get_bits_per_sample(enc->codec->id);
|
const int coded_bps = av_get_bits_per_sample(enc->codec->id);
|
||||||
|
uint8_t *buf = decoded_frame->data[0];
|
||||||
|
int size = decoded_frame->nb_samples * dec->channels * isize;
|
||||||
|
int64_t allocated_for_size = size;
|
||||||
|
|
||||||
need_realloc:
|
need_realloc:
|
||||||
audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels);
|
audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels);
|
||||||
@ -1620,39 +1617,40 @@ static void rate_emu_sleep(InputStream *ist)
|
|||||||
|
|
||||||
static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
|
static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
|
||||||
{
|
{
|
||||||
static unsigned int samples_size = 0;
|
AVFrame *decoded_frame;
|
||||||
|
AVCodecContext *avctx = ist->st->codec;
|
||||||
int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
|
int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
|
||||||
uint8_t *decoded_data_buf = NULL;
|
|
||||||
int decoded_data_size = 0;
|
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
if (pkt && samples_size < FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
|
if (!(decoded_frame = avcodec_alloc_frame()))
|
||||||
av_free(samples);
|
return AVERROR(ENOMEM);
|
||||||
samples_size = FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE);
|
|
||||||
samples = av_malloc(samples_size);
|
|
||||||
}
|
|
||||||
decoded_data_size = samples_size;
|
|
||||||
|
|
||||||
ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size,
|
ret = avcodec_decode_audio4(avctx, decoded_frame, got_output, pkt);
|
||||||
pkt);
|
if (ret < 0) {
|
||||||
if (ret < 0)
|
av_freep(&decoded_frame);
|
||||||
return ret;
|
return ret;
|
||||||
*got_output = decoded_data_size > 0;
|
}
|
||||||
|
|
||||||
/* Some bug in mpeg audio decoder gives */
|
|
||||||
/* decoded_data_size < 0, it seems they are overflows */
|
|
||||||
if (!*got_output) {
|
if (!*got_output) {
|
||||||
/* no audio frame */
|
/* no audio frame */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded_data_buf = (uint8_t *)samples;
|
/* if the decoder provides a pts, use it instead of the last packet pts.
|
||||||
ist->next_pts += ((int64_t)AV_TIME_BASE/bps * decoded_data_size) /
|
the decoder could be delaying output by a packet or more. */
|
||||||
(ist->st->codec->sample_rate * ist->st->codec->channels);
|
if (decoded_frame->pts != AV_NOPTS_VALUE)
|
||||||
|
ist->next_pts = decoded_frame->pts;
|
||||||
|
|
||||||
|
/* increment next_pts to use for the case where the input stream does not
|
||||||
|
have timestamps or there are multiple frames in the packet */
|
||||||
|
ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
|
||||||
|
avctx->sample_rate;
|
||||||
|
|
||||||
// preprocess audio (volume)
|
// preprocess audio (volume)
|
||||||
if (audio_volume != 256) {
|
if (audio_volume != 256) {
|
||||||
switch (ist->st->codec->sample_fmt) {
|
int decoded_data_size = decoded_frame->nb_samples * avctx->channels * bps;
|
||||||
|
void *samples = decoded_frame->data[0];
|
||||||
|
switch (avctx->sample_fmt) {
|
||||||
case AV_SAMPLE_FMT_U8:
|
case AV_SAMPLE_FMT_U8:
|
||||||
{
|
{
|
||||||
uint8_t *volp = samples;
|
uint8_t *volp = samples;
|
||||||
@ -1713,8 +1711,7 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
|
|||||||
|
|
||||||
if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
|
if (!check_output_constraints(ist, ost) || !ost->encoding_needed)
|
||||||
continue;
|
continue;
|
||||||
do_audio_out(output_files[ost->file_index].ctx, ost, ist,
|
do_audio_out(output_files[ost->file_index].ctx, ost, ist, decoded_frame);
|
||||||
decoded_data_buf, decoded_data_size);
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user