[FFmpeg-devel] [PATCH 2/2] ffmpeg: take audio_resample flag out of OutputStream.
Clément Bœsch
ubitux at gmail.com
Tue Oct 18 10:17:59 CEST 2011
From: Clément Bœsch <clement.boesch at smartjog.com>
---
ffmpeg.c | 26 ++++++++++++--------------
1 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index 45cc4b6..2227eb3 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -230,7 +230,6 @@ typedef struct OutputStream {
int forced_kf_index;
/* audio only */
- int audio_resample;
int resample_sample_fmt;
int resample_channels;
int resample_sample_rate;
@@ -808,7 +807,7 @@ static void do_audio_out(AVFormatContext *s,
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, audio_resample, resample_changed;
AVCodecContext *enc= ost->st->codec;
AVCodecContext *dec= ist->st->codec;
int osize = av_get_bytes_per_sample(enc->sample_fmt);
@@ -839,18 +838,17 @@ need_realloc:
exit_program(1);
}
- if (enc->channels != dec->channels ||
- enc->sample_fmt != dec->sample_fmt ||
- enc->channel_layout != dec->channel_layout ||
- enc->sample_rate != dec->sample_rate ||
- audio_sync_method > 1)
- ost->audio_resample = 1;
+ audio_resample = enc->channels != dec->channels ||
+ enc->sample_fmt != dec->sample_fmt ||
+ enc->channel_layout != dec->channel_layout ||
+ enc->sample_rate != dec->sample_rate ||
+ audio_sync_method > 1;
resample_changed = ost->resample_sample_fmt != dec->sample_fmt ||
ost->resample_channels != dec->channels ||
ost->resample_sample_rate != dec->sample_rate;
- if ((ost->audio_resample && !ost->swr) || resample_changed) {
+ if ((audio_resample && !ost->swr) || resample_changed) {
if (resample_changed) {
av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n",
ist->file_index, ist->st->index,
@@ -867,7 +865,7 @@ need_realloc:
ost->resample_channels == enc->channels &&
ost->resample_sample_rate == enc->sample_rate) {
//ost->swr = NULL;
- ost->audio_resample = 0;
+ audio_resample = 0;
} else {
ost->swr = swr_alloc2(ost->swr,
enc->channel_layout, enc->sample_fmt, enc->sample_rate,
@@ -890,7 +888,7 @@ need_realloc:
}
}
- av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt);
+ av_assert0(audio_resample || dec->sample_fmt==enc->sample_fmt);
if(audio_sync_method){
double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts
@@ -926,7 +924,7 @@ need_realloc:
}
}else if(audio_sync_method>1){
int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
- av_assert0(ost->audio_resample);
+ av_assert0(audio_resample);
av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n",
delta, comp, enc->sample_rate);
// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
@@ -937,7 +935,7 @@ need_realloc:
ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate)
- av_fifo_size(ost->fifo)/(enc->channels * 2); //FIXME wrong
- if (ost->audio_resample) {
+ if (audio_resample) {
buftmp = audio_buf;
size_out = swr_convert(ost->swr, ( uint8_t*[]){buftmp}, audio_buf_size / (enc->channels * osize),
(const uint8_t*[]){buf }, size / (dec->channels * isize));
@@ -947,7 +945,7 @@ need_realloc:
size_out = size;
}
- av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt);
+ av_assert0(audio_resample || dec->sample_fmt==enc->sample_fmt);
/* now encode as many frames as possible */
if (enc->frame_size > 1) {
--
1.7.5.4
More information about the ffmpeg-devel
mailing list