Revision 8afab686 ffmpeg.c

View differences:

ffmpeg.c
295 295
    /* audio only */
296 296
    int audio_resample;
297 297
    ReSampleContext *resample; /* for audio resampling */
298
    int resample_sample_fmt;
299
    int resample_channels;
300
    int resample_sample_rate;
298 301
    int reformat_pair;
299 302
    AVAudioConvert *reformat_ctx;
300 303
    AVFifoBuffer *fifo;     /* for compression: one audio fifo per codec */
......
768 771
    int64_t audio_out_size, audio_buf_size;
769 772
    int64_t allocated_for_size= size;
770 773

  
771
    int size_out, frame_bytes, ret;
774
    int size_out, frame_bytes, ret, resample_changed;
772 775
    AVCodecContext *enc= ost->st->codec;
773 776
    AVCodecContext *dec= ist->st->codec;
774 777
    int osize= av_get_bits_per_sample_fmt(enc->sample_fmt)/8;
......
802 805
    if (enc->channels != dec->channels)
803 806
        ost->audio_resample = 1;
804 807

  
805
    if (ost->audio_resample && !ost->resample) {
808
    resample_changed = ost->resample_sample_fmt  != dec->sample_fmt ||
809
                       ost->resample_channels    != dec->channels   ||
810
                       ost->resample_sample_rate != dec->sample_rate;
811

  
812
    if ((ost->audio_resample && !ost->resample) || resample_changed) {
813
        if (resample_changed) {
814
            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",
815
                   ist->file_index, ist->index,
816
                   ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels,
817
                   dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), dec->channels);
818
            ost->resample_sample_fmt  = dec->sample_fmt;
819
            ost->resample_channels    = dec->channels;
820
            ost->resample_sample_rate = dec->sample_rate;
821
            if (ost->resample)
822
                audio_resample_close(ost->resample);
823
        }
824
        if (ost->resample_sample_fmt  == enc->sample_fmt &&
825
            ost->resample_channels    == enc->channels   &&
826
            ost->resample_sample_rate == enc->sample_rate) {
827
            ost->resample = NULL;
828
            ost->audio_resample = 0;
829
        } else {
806 830
        if (dec->sample_fmt != AV_SAMPLE_FMT_S16)
807 831
            fprintf(stderr, "Warning, using s16 intermediate sample format for resampling\n");
808 832
        ost->resample = av_audio_resample_init(enc->channels,    dec->channels,
......
815 839
                    enc->channels, enc->sample_rate);
816 840
            ffmpeg_exit(1);
817 841
        }
842
        }
818 843
    }
819 844

  
820 845
#define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b))
......
2174 2199
                icodec->request_channels = codec->channels;
2175 2200
                ist->decoding_needed = 1;
2176 2201
                ost->encoding_needed = 1;
2202
                ost->resample_sample_fmt  = icodec->sample_fmt;
2203
                ost->resample_sample_rate = icodec->sample_rate;
2204
                ost->resample_channels    = icodec->channels;
2177 2205
                break;
2178 2206
            case AVMEDIA_TYPE_VIDEO:
2179 2207
                if (ost->st->codec->pix_fmt == PIX_FMT_NONE) {

Also available in: Unified diff