<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">May thanks for your reply. Now I can extract the audio track from an avi file and to store it in a s16 file.</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">There is a problem, the audio duration is two times than the original track so I can listen but not correctly. There is the error for you?</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    <span style=" font-weight:600;">SwrContext</span> *pSwrContext= swr_alloc();</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    if (!pSwrContext) emit UpdateLog("swr_alloc Error!!!");</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    else {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        av_opt_set_int(pSwrContext, "in_channel_layout", av_get_default_channel_layout(pAVCodecContextAudio->channels), 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        av_opt_set_int(pSwrContext, "in_sample_fmt", pAVCodecContextAudio->sample_fmt, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        av_opt_set_int(pSwrContext, "in_sample_rate", pAVCodecContextAudio->sample_rate, 0);</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        av_opt_set_int(pSwrContext, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        av_opt_set_int(pSwrContext, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        av_opt_set_int(pSwrContext, "out_sample_rate", 44100, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        if (<span style=" font-weight:600;">swr_init</span>(pSwrContext)< 0) {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            swr_free(&pSwrContext);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            pSwrContext= nullptr;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        }</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        ...</p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; "> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    int gotFrameAudio= 0;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    int Ret= <span style=" font-weight:600;">avcodec_decode_audio4</span>(pAVCodecContextAudio, pAVFrame, &gotFrameAudio, &pAVPacket);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    if (Ret< 0) break;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    if (gotFrameAudio) {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        uint8_t* buffer;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        Ret= <span style=" font-weight:600;">av_samples_alloc</span>(static_cast<uint8_t**>(&buffer), nullptr, AV_CH_LAYOUT_STEREO, pAVFrame->nb_samples, AV_SAMPLE_FMT_DBL, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        if (Ret< 0) emit UpdateLog("av_samples_alloc Error!!!");</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        else {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            Ret= <span style=" font-weight:600;">swr_convert</span>(pSwrContext, static_cast<uint8_t**>(&buffer), pAVFrame->nb_samples, (const uint8_t**)pAVFrame->data, pAVFrame->nb_samples);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            if (Ret< 0) emit UpdateLog("swr_convert Error!!!");</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            else {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">                Ret= <span style=" font-weight:600;">av_samples_get_buffer_size</span>(nullptr, pAVCodecContextAudio->channels, Ret, AV_SAMPLE_FMT_S16, 1);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">                if (Ret< 0) emit UpdateLog("av_samples_get_buffer_size Error!!!");</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">                else {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">                    <span style=" font-weight:600;">fwrite(buffer, 1, static_cast<size_t>(Ret), dst_file);</span></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">                }</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            }</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">            av_freep(&buffer);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">        }</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">    }</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /><br />In data venerd́ 1 maggio 2020 21:53:36 CEST, Richard Hussong ha scritto:<br /></p>
<p style=" margin-top:12px; margin-bottom:0px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"><br /><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">On Thu, Apr 30, 2020 at 9:27 AM Denis Gottardello <<a href="mailto:info@denisgottardello.it"><span style=" text-decoration: underline; color:#2980b9;">info@denisgottardello.it</span></a>> wrote:<br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">Hi, I need to extract audio packets from an rtsp stream and to listen them with a Qt program.</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">The examples are based on <span style=" font-weight:600;">avcodec_decode_audio4</span> function but it is deprecated.</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">Now I already have an audio packet. Now I have to trascode it in a format that I can manage with Qt, something like</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">AVAudioResampleContext</span>* resample_context_ = NULL;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">av_opt_set_int(resample_context_, "in_channel_layout", av_get_default_channel_layout(codec_context_->channels), 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">av_opt_set_int(resample_context_, "out_channel_layout", av_get_default_channel_layout(outputFormat_.channels), 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">av_opt_set_int(resample_context_, "in_sample_rate", codec_context_->sample_rate, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">av_opt_set_int(resample_context_, "out_sample_rate", outputFormat_.rate, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">av_opt_set_int(resample_context_, "in_sample_fmt", codec_context_->sample_fmt, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">av_opt_set_int(resample_context_, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">if (avresample_open(resample_context_) < 0) {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">qDebug() << "Could not open resample context.";</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">avresample_free(&resample_context_);</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">return;</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">}</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">but <span style=" font-weight:600;">AVAudioResampleContext</span> but it is deprecated too.</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"><br /></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:40px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">The entire libavresample library is deprecated. You should use libswresample instead. Library documentation is at <a href="https://ffmpeg.org/doxygen/trunk/group__lswr.html"><span style=" text-decoration: underline; color:#2980b9;">https://ffmpeg.org/doxygen/trunk/group__lswr.html</span></a>, and there is a usage example at <a href="https://ffmpeg.org/doxygen/trunk/resampling_audio_8c-example.html"><span style=" text-decoration: underline; color:#2980b9;">https://ffmpeg.org/doxygen/trunk/resampling_audio_8c-example.html</span></a>.</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">Can someone suggest me a way from </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">while (av_read_frame(pAVFormatContext, &pAVPacket)>= 0 && DoStart) {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">if (pAVPacket.stream_index== StreamAudio) {</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">...</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">..</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"> </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">??</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">Many thanks</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"><br />-- </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">+39.347.4070897</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.labcsp.com"><span style=" text-decoration: underline; color:#2980b9;">http://www.labcsp.com</span></a></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.denisgottardello.it"><span style=" text-decoration: underline; color:#2980b9;">http://www.denisgottardello.it</span></a></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">GMT+1</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:46px; margin-right:40px; -qt-block-indent:0; text-indent:0px;">Skype: mrdebug</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">_______________________________________________<br />Libav-user mailing list<br /><a href="mailto:Libav-user@ffmpeg.org"><span style=" text-decoration: underline; color:#2980b9;">Libav-user@ffmpeg.org</span></a><br /><a href="https://ffmpeg.org/mailman/listinfo/libav-user"><span style=" text-decoration: underline; color:#2980b9;">https://ffmpeg.org/mailman/listinfo/libav-user</span></a><br /><br />To unsubscribe, visit link above, or email<br /><a href="mailto:libav-user-request@ffmpeg.org"><span style=" text-decoration: underline; color:#2980b9;">libav-user-request@ffmpeg.org</span></a> with subject "unsubscribe".</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /><br />-- </p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">+39.347.4070897</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.labcsp.com"><span style=" text-decoration: underline; color:#2980b9;">http://www.labcsp.com</span></a></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="http://www.denisgottardello.it"><span style=" text-decoration: underline; color:#2980b9;">http://www.denisgottardello.it</span></a></p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">GMT+1</p>
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Skype: mrdebug</p></body></html>