English 中文(简体)
使用症状时的颜色
原标题:Choppy sound when using ffmpeg

I suffered some choppy audio when i try to capture audio from a live stream. Another essential problem which could explain the problem is that the Wav file created is twice longer than the capture time.

听话语是完美无缺的,因为一只手.子,就在抓捕中还是用瓦夫书写。

收集:

av_read_frame(pFormatCtx, &packet)

if(packet.stream_index == mAudioStream)
{
    int buff_size = sizeof(mAudioBuffer);
    std::cout << "Buff_size " << buff_size << std::endl;
    len = avcodec_decode_audio3(pAudioCodecCtx,(int16_t*)mAudioBuffer, &buff_size,&packet);
    if(len < 0){
        qDebug("Extractor - Audio isEnd = -1;");
        mAudioBufferSize = 0;
        isEnd = ERROR_;
        return isEnd;
    }

    // Set packet result type
    mFrameType = AUDIO_PKT;
    mAudioBufferSize = buff_size;
    //store audio synchronization informations:
    if(packet.pts != AV_NOPTS_VALUE) {
         mAudioPts_ = av_q2d(pFormatCtx->streams[mAudioStream]->time_base);
         mAudioPts_ *= packet.pts;
    }
}

        // store a copy of current audio frame in _frame
        _frame.audioFrame = new decoded_frame_t::audio_frame_t();
        _frame.audioFrame->sampleRate = mediaInfos.audioSampleRate;
        _frame.audioFrame->sampleSize = mediaInfos.audioSampleSize;
        _frame.audioFrame->nbChannels = mediaInfos.audioNbChannels;
        _frame.audioFrame->nbSamples = mAudioBufferSize / ((mediaInfos.audioSampleSize/8) * mediaInfos.audioNbChannels);
        _frame.audioFrame->buf.resize(mAudioBufferSize);
        memcpy(&_frame.audioFrame->buf[0],mAudioBuffer,mAudioBufferSize);

然后,在Wav文档中使用校正仪储存:

SNDFILE*            fd;
SF_INFO             sfInf;

sfInf.frames = 0;
sfInf.channels = p_capt->ui_nbChannels;
sfInf.samplerate = p_capt->ui_sampleRate;
sfInf.format = SF_FORMAT_WAV | SF_FORMAT_PCM_U8;
sfInf.sections = 0;
sfInf.seekable = 0;

if (sf_format_check(&sfInf) == FALSE)
    std::cout << "Format parameter are uncorrect ! Exit saving !" << std::endl;
else
{
    fd = sf_open(fileName.toStdString().c_str(), SFM_WRITE, &sfInf);
    if (fd == NULL)
    {
        std::cout << "Unable to open the file " << fileName.toStdString() << std::endl;
        return GRAB_ST_NOK;
    }

    //little trick because v_buf is a uint8_t vector
    sf_count_t l = sf_write_short(fd, (const short *)(&(p_capt->v_buf[0])), p_capt->v_buf.size()/2);

    if (l != p_capt->v_buf.size()/2)
    {
       std::cout << "sf_write didn t write the right amoung of bits " << l << " != " << p_capt->v_buf.size()/2 << std::endl;
       ret = GRAB_ST_NOK;
    }
    else
    {
        sf_write_sync(fd);
        sf_close(fd);
        ret = GRAB_ST_OK;
    }
}

I hope it s understandable. Waiting for remarks.

Kurt

最佳回答

奥基问题已经解决。

有两个主要问题:

  • resize DO add n element and is not just preparing the vector for further push etc...
  • the buff_size of avcodec_decode_audio3 return a length in bytes but is copying in a int16_t array so it can be disturbing.
问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签