Note that there are some explanatory texts on larger screens.

plurals
  1. POChoppy sound when using ffmpeg
    text
    copied!<p>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.</p> <p>The audio is perfect when i play the avs input file with ffplay, so the avs is ok, the problem is after whether in the capture or in the Wav writing.</p> <p>To capture :</p> <pre><code>av_read_frame(pFormatCtx, &amp;packet) if(packet.stream_index == mAudioStream) { int buff_size = sizeof(mAudioBuffer); std::cout &lt;&lt; "Buff_size " &lt;&lt; buff_size &lt;&lt; std::endl; len = avcodec_decode_audio3(pAudioCodecCtx,(int16_t*)mAudioBuffer, &amp;buff_size,&amp;packet); if(len &lt; 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-&gt;streams[mAudioStream]-&gt;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-&gt;sampleRate = mediaInfos.audioSampleRate; _frame.audioFrame-&gt;sampleSize = mediaInfos.audioSampleSize; _frame.audioFrame-&gt;nbChannels = mediaInfos.audioNbChannels; _frame.audioFrame-&gt;nbSamples = mAudioBufferSize / ((mediaInfos.audioSampleSize/8) * mediaInfos.audioNbChannels); _frame.audioFrame-&gt;buf.resize(mAudioBufferSize); memcpy(&amp;_frame.audioFrame-&gt;buf[0],mAudioBuffer,mAudioBufferSize); </code></pre> <p>Then i store in a Wav File using libsndfile :</p> <pre><code>SNDFILE* fd; SF_INFO sfInf; sfInf.frames = 0; sfInf.channels = p_capt-&gt;ui_nbChannels; sfInf.samplerate = p_capt-&gt;ui_sampleRate; sfInf.format = SF_FORMAT_WAV | SF_FORMAT_PCM_U8; sfInf.sections = 0; sfInf.seekable = 0; if (sf_format_check(&amp;sfInf) == FALSE) std::cout &lt;&lt; "Format parameter are uncorrect ! Exit saving !" &lt;&lt; std::endl; else { fd = sf_open(fileName.toStdString().c_str(), SFM_WRITE, &amp;sfInf); if (fd == NULL) { std::cout &lt;&lt; "Unable to open the file " &lt;&lt; fileName.toStdString() &lt;&lt; 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 *)(&amp;(p_capt-&gt;v_buf[0])), p_capt-&gt;v_buf.size()/2); if (l != p_capt-&gt;v_buf.size()/2) { std::cout &lt;&lt; "sf_write didn't write the right amoung of bits " &lt;&lt; l &lt;&lt; " != " &lt;&lt; p_capt-&gt;v_buf.size()/2 &lt;&lt; std::endl; ret = GRAB_ST_NOK; } else { sf_write_sync(fd); sf_close(fd); ret = GRAB_ST_OK; } } </code></pre> <p>I hope it's understandable. Waiting for remarks.</p> <p>Kurt</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload