<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 2, 2020 at 2:20 AM Denis Gottardello <<a href="mailto:info@denisgottardello.it">info@denisgottardello.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div style="font-family:"Noto Sans";font-size:10pt;font-weight:400;font-style:normal">
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;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:0px;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></div></blockquote><div><br></div><div>I'm sorry - I don't know anything about storing or playing raw S16 files. I don't see anything obviously wrong with your code. You could try doing this:</div><div><font face="monospace">ffmpeg -i input -f s16le -c:a pcm_s16le output.raw</font></div><div>That will give you a raw S16 file. Feed that file into your program, and see how the output differs from the input. That should give some clue to what is wrong.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:"Noto Sans";font-size:10pt;font-weight:400;font-style:normal">
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">    <span style="font-weight:600">SwrContext</span> *pSwrContext= swr_alloc();</p>
<p style="margin:0px;text-indent:0px">    if (!pSwrContext) emit UpdateLog("swr_alloc Error!!!");</p>
<p style="margin:0px;text-indent:0px">    else {</p>
<p style="margin:0px;text-indent:0px">        av_opt_set_int(pSwrContext, "in_channel_layout", av_get_default_channel_layout(pAVCodecContextAudio->channels), 0);</p>
<p style="margin:0px;text-indent:0px">        av_opt_set_int(pSwrContext, "in_sample_fmt", pAVCodecContextAudio->sample_fmt, 0);</p>
<p style="margin:0px;text-indent:0px">        av_opt_set_int(pSwrContext, "in_sample_rate", pAVCodecContextAudio->sample_rate, 0);</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">        av_opt_set_int(pSwrContext, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);</p>
<p style="margin:0px;text-indent:0px">        av_opt_set_int(pSwrContext, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);</p>
<p style="margin:0px;text-indent:0px">        av_opt_set_int(pSwrContext, "out_sample_rate", 44100, 0);</p>
<p style="margin:0px;text-indent:0px">        if (<span style="font-weight:600">swr_init</span>(pSwrContext)< 0) {</p>
<p style="margin:0px;text-indent:0px">            swr_free(&pSwrContext);</p>
<p style="margin:0px;text-indent:0px">            pSwrContext= nullptr;</p>
<p style="margin:0px;text-indent:0px">        }</p>
<p style="margin:0px;text-indent:0px">        ...</p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px"> </p>
<p style="margin:0px;text-indent:0px">    int gotFrameAudio= 0;</p>
<p style="margin:0px;text-indent:0px">    int Ret= <span style="font-weight:600">avcodec_decode_audio4</span>(pAVCodecContextAudio, pAVFrame, &gotFrameAudio, &pAVPacket);</p>
<p style="margin:0px;text-indent:0px">    if (Ret< 0) break;</p>
<p style="margin:0px;text-indent:0px">    if (gotFrameAudio) {</p>
<p style="margin:0px;text-indent:0px">        uint8_t* buffer;</p>
<p style="margin:0px;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:0px;text-indent:0px">        if (Ret< 0) emit UpdateLog("av_samples_alloc Error!!!");</p>
<p style="margin:0px;text-indent:0px">        else {</p>
<p style="margin:0px;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:0px;text-indent:0px">            if (Ret< 0) emit UpdateLog("swr_convert Error!!!");</p>
<p style="margin:0px;text-indent:0px">            else {</p>
<p style="margin:0px;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:0px;text-indent:0px">                if (Ret< 0) emit UpdateLog("av_samples_get_buffer_size Error!!!");</p>
<p style="margin:0px;text-indent:0px">                else {</p>
<p style="margin:0px;text-indent:0px">                    <span style="font-weight:600">fwrite(buffer, 1, static_cast<size_t>(Ret), dst_file);</span></p>
<p style="margin:0px;text-indent:0px">                }</p>
<p style="margin:0px;text-indent:0px">            }</p>
<p style="margin:0px;text-indent:0px">            av_freep(&buffer);</p>
<p style="margin:0px;text-indent:0px">        }</p>
<p style="margin:0px;text-indent:0px">    }</p>
<p style="margin:0px;text-indent:0px"><br><br>In data venerdì 1 maggio 2020 21:53:36 CEST, Richard Hussong ha scritto:<br></p>
<p style="margin:12px 40px 0px;text-indent:0px"><br><br></p>
<p style="margin:0px 40px;text-indent:0px">On Thu, Apr 30, 2020 at 9:27 AM Denis Gottardello <<a href="mailto:info@denisgottardello.it" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">info@denisgottardello.it</span></a>> wrote:<br></p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"> </p>
<p style="margin:0px 40px 0px 46px;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:0px 40px 0px 46px;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:0px 40px 0px 46px;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:0px 40px 0px 46px;text-indent:0px"> </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"><span style="font-weight:600">AVAudioResampleContext</span>* resample_context_ = NULL;</p>
<p style="margin:0px 40px 0px 46px;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:0px 40px 0px 46px;text-indent:0px">av_opt_set_int(resample_context_, "out_channel_layout", av_get_default_channel_layout(outputFormat_.channels), 0);</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">av_opt_set_int(resample_context_, "in_sample_rate", codec_context_->sample_rate, 0);</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">av_opt_set_int(resample_context_, "out_sample_rate", outputFormat_.rate, 0);</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">av_opt_set_int(resample_context_, "in_sample_fmt", codec_context_->sample_fmt, 0);</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">av_opt_set_int(resample_context_, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">if (avresample_open(resample_context_) < 0) {</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">qDebug() << "Could not open resample context.";</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">avresample_free(&resample_context_);</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">return;</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">}</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"> </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">but <span style="font-weight:600">AVAudioResampleContext</span> but it is deprecated too.</p>
<p style="margin:0px 40px;text-indent:0px"><br></p>
<p style="margin:0px 40px;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" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">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" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">https://ffmpeg.org/doxygen/trunk/resampling_audio_8c-example.html</span></a>.</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"> </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">Can someone suggest me a way from </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"> </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">while (av_read_frame(pAVFormatContext, &pAVPacket)>= 0 && DoStart) {</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">if (pAVPacket.stream_index== StreamAudio) {</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">...</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">..</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"> </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">??</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">Many thanks</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"><br>-- </p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">+39.347.4070897</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"><a href="http://www.labcsp.com" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">http://www.labcsp.com</span></a></p>
<p style="margin:0px 40px 0px 46px;text-indent:0px"><a href="http://www.denisgottardello.it" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">http://www.denisgottardello.it</span></a></p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">GMT+1</p>
<p style="margin:0px 40px 0px 46px;text-indent:0px">Skype: mrdebug</p>
<p style="margin:0px;text-indent:0px">_______________________________________________<br>Libav-user mailing list<br><a href="mailto:Libav-user@ffmpeg.org" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">Libav-user@ffmpeg.org</span></a><br><a href="https://ffmpeg.org/mailman/listinfo/libav-user" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">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" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">libav-user-request@ffmpeg.org</span></a> with subject "unsubscribe".</p>
<p style="margin:0px;text-indent:0px"><br><br>-- </p>
<p style="margin:0px;text-indent:0px">+39.347.4070897</p>
<p style="margin:0px;text-indent:0px"><a href="http://www.labcsp.com" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">http://www.labcsp.com</span></a></p>
<p style="margin:0px;text-indent:0px"><a href="http://www.denisgottardello.it" target="_blank"><span style="text-decoration:underline;color:rgb(41,128,185)">http://www.denisgottardello.it</span></a></p>
<p style="margin:0px;text-indent:0px">GMT+1</p>
<p style="margin:0px;text-indent:0px">Skype: mrdebug</p></div>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".</blockquote></div></div>