As its a dynamic payload profile, you have to assign it somewhere..  ffplay won't be able to decode the sdp untill its specifically defined about the profile type...   <br><br>On Sunday, October 30, 2016, Yu Ang Tan <<a href="mailto:yuang86@gmail.com">yuang86@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p dir="ltr">On Sun, 30 Oct 2016 18:33 NITIN GOYAL <<a href="javascript:_e(%7B%7D,'cvml','nitinkumgoyal@gmail.com');" target="_blank">nitinkumgoyal@gmail.com</a>> wrote:<br></p><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>RTP payload 96,97 are dynamic payloads and can be assigned as needed. RFC 2833<br><br></div>in general when we have both video and audio, Video goes for 96 while audio goes for 97.<br><br><br><br></div><div class="gmail_extra"><br><div class="gmail_quote"></div></div><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 26, 2016 at 7:08 AM, Yu Ang Tan <span dir="ltr"><<a href="javascript:_e(%7B%7D,'cvml','yuang86@gmail.com');" target="_blank">yuang86@gmail.com</a>></span> wrote:<br></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>On Thu, Sep 22, 2016 at 11:46 AM Yu Ang Tan <<a href="javascript:_e(%7B%7D,'cvml','yuang86@gmail.com');" target="_blank">yuang86@gmail.com</a>> wrote:<br></div></div></div><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I want to create an rtp audio stream with ffmpeg. When I run my application I get the following SDP file configuration: </div><div><br></div><div>    Output #0, rtp, to 'rtp://<a href="http://127.0.0.1:8554" target="_blank">127.0.0.1:8554</a>':</div><div>        Stream #0:0: Audio: pcm_s16be, 8000 Hz, stereo, s16, 256 kb/s</div><div>        </div><div>    SDP:    </div><div>    v=0</div><div>    o=- 0 0 IN IP4 127.0.0.1</div><div>    s=No Name</div><div>    c=IN IP4 127.0.0.1</div><div>    t=0 0</div><div>    a=tool:libavformat 57.25.101</div><div>    m=audio 8554 RTP/AVP 96</div><div>    b=AS:256</div><div>    a=rtpmap:96 L16/8000/2</div><div><br></div><div>However, when I try to read it with `ffplay -i test.sdp -protocol_whitelist file,udp,rtp`, it fails,shows the following:</div><div><br></div><div>    ffplay version N-78598-g98a0053 Copyright (c) 2003-2016 the FFmpeg developers</div><div>      built with gcc 5.3.0 (GCC)</div><div>      configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib</div><div>      libavutil      55. 18.100 / 55. 18.100</div><div>      libavcodec     57. 24.103 / 57. 24.103</div><div>      libavformat    57. 25.101 / 57. 25.101</div><div>      libavdevice    57.  0.101 / 57.  0.101</div><div>      libavfilter     6. 34.100 /  6. 34.100</div><div>      libswscale      4.  0.100 /  4.  0.100</div><div>      libswresample   2.  0.101 /  2.  0.101</div><div>      libpostproc    54.  0.100 / 54.  0.100</div><div>        nan    :  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0</div><div>        (...waits indefinitely.)</div><div><br></div><div>The only way to make it work again is to modify the payload type in the SDP file from 96 to 97. Can someone tell me why? Where and how is this number defined?</div><div>        </div><div><br></div><div>Here is my source. </div><div><br></div><div>    #include <math.h></div><div>    extern "C"</div><div>    {</div><div>    #include <libavutil/opt.h></div><div>    #include <libavcodec/avcodec.h></div><div>    #include <libavutil/channel_layout.h></div><div>    #include <libavutil/common.h></div><div>    #include <libavutil/imgutils.h></div><div>    #include <libavutil/mathematics.h></div><div>    #include <libavutil/samplefmt.h></div><div>    #include <libavformat/avformat.h></div><div>    }</div><div><br></div><div><br></div><div>    static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)</div><div>    {</div><div>        /* rescale output packet timestamp values from codec to stream timebase */</div><div>        av_packet_rescale_ts(pkt, *time_base, st->time_base);</div><div><br></div><div>        /* Write the compressed frame to the media file. */</div><div>        return av_interleaved_write_frame(<wbr>fmt_ctx, pkt);</div><div>    }</div><div><br></div><div>    /*</div><div>    * Audio encoding example</div><div>    */</div><div>    static void audio_encode_example(const char *filename)</div><div>    {</div><div>        AVPacket pkt;</div><div>        int i, j, k, ret, got_output;</div><div>        int buffer_size;</div><div><br></div><div>        uint16_t *samples;</div><div>        float t, tincr;</div><div><br></div><div>        AVCodec *outCodec = NULL;</div><div>        AVCodecContext *outCodecCtx = NULL;</div><div>        AVFormatContext *outFormatCtx = NULL;</div><div>        AVStream * outAudioStream = NULL;</div><div>        AVFrame *outFrame = NULL;</div><div><br></div><div>        ret = avformat_alloc_output_<wbr>context2(&outFormatCtx, NULL, "rtp", filename);</div><div>        if (!outFormatCtx || ret < 0)</div><div>        {</div><div>            fprintf(stderr, "Could not allocate output context");</div><div>        }</div><div><br></div><div>        outFormatCtx->flags |= AVFMT_FLAG_NOBUFFER | AVFMT_FLAG_FLUSH_PACKETS;</div><div>        outFormatCtx->oformat->audio_<wbr>codec = AV_CODEC_ID_PCM_S16BE;</div><div><br></div><div>        /* find the encoder */</div><div>        outCodec = avcodec_find_encoder(<wbr>outFormatCtx->oformat->audio_<wbr>codec);</div><div>        if (!outCodec) {</div><div>            fprintf(stderr, "Codec not found\n");</div><div>            exit(1);</div><div>        }</div><div><br></div><div>        outAudioStream = avformat_new_stream(<wbr>outFormatCtx, outCodec);</div><div>        if (!outAudioStream)</div><div>        {</div><div>            fprintf(stderr, "Cannot add new audio stream\n");</div><div>            exit(1);</div><div>        }</div><div><br></div><div>        outAudioStream->id = outFormatCtx->nb_streams - 1;</div><div>        outCodecCtx = outAudioStream->codec;</div><div>        outCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;</div><div><br></div><div>        /* select other audio parameters supported by the encoder */</div><div>        outCodecCtx->sample_rate = 8000;</div><div>        outCodecCtx->channel_layout = AV_CH_LAYOUT_STEREO;</div><div>        outCodecCtx->channels = 2;</div><div><br></div><div>        /* open it */</div><div>        if (avcodec_open2(outCodecCtx, outCodec, NULL) < 0) {</div><div>            fprintf(stderr, "Could not open codec\n");</div><div>            exit(1);</div><div>        }</div><div><br></div><div>        // PCM has no frame, so we have to explicitly specify</div><div>        outCodecCtx->frame_size = 1152;</div><div><br></div><div>        av_dump_format(outFormatCtx, 0, filename, 1);</div><div><br></div><div>        char buff[10000] = { 0 };</div><div>        ret = av_sdp_create(&outFormatCtx, 1, buff, sizeof(buff));</div><div>        printf("%s", buff);</div><div><br></div><div>        ret = avio_open2(&outFormatCtx->pb, filename, AVIO_FLAG_WRITE, NULL, NULL);</div><div>        ret = avformat_write_header(<wbr>outFormatCtx, NULL);</div><div>        printf("ret = %d\n", ret);</div><div>        if (ret <0) {</div><div>            exit(1);</div><div>        }</div><div><br></div><div>        /* frame containing input audio */</div><div>        outFrame = av_frame_alloc();</div><div>        if (!outFrame) {</div><div>            fprintf(stderr, "Could not allocate audio frame\n");</div><div>            exit(1);</div><div>        }</div><div><br></div><div>        outFrame->nb_samples = outCodecCtx->frame_size;</div><div>        outFrame->format = outCodecCtx->sample_fmt;</div><div>        outFrame->channel_layout = outCodecCtx->channel_layout;</div><div><br></div><div>        /* we calculate the size of the samples buffer in bytes */</div><div>        buffer_size = av_samples_get_buffer_size(<wbr>NULL, outCodecCtx->channels, outCodecCtx->frame_size,</div><div>            outCodecCtx->sample_fmt, 0);</div><div>        if (buffer_size < 0) {</div><div>            fprintf(stderr, "Could not get sample buffer size\n");</div><div>            exit(1);</div><div>        }</div><div>        samples = (uint16_t*)av_malloc(buffer_<wbr>size);</div><div>        if (!samples) {</div><div>            fprintf(stderr, "Could not allocate %d bytes for samples buffer\n",</div><div>                buffer_size);</div><div>            exit(1);</div><div>        }</div><div>        /* setup the data pointers in the AVFrame */</div><div>        ret = avcodec_fill_audio_frame(<wbr>outFrame, outCodecCtx->channels, outCodecCtx->sample_fmt,</div><div>            (const uint8_t*)samples, buffer_size, 0);</div><div>        if (ret < 0) {</div><div>            fprintf(stderr, "Could not setup audio frame\n");</div><div>            exit(1);</div><div>        }</div><div><br></div><div>        /* encode a single tone sound */</div><div>        t = 0;</div><div>        int next_pts = 0;</div><div>        tincr = 2 * M_PI * 440.0 / outCodecCtx->sample_rate;</div><div>        for (i = 0; i < 400000; i++) {</div><div>            av_init_packet(&pkt);</div><div>            pkt.data = NULL; // packet data will be allocated by the encoder</div><div>            pkt.size = 0;</div><div><br></div><div>            for (j = 0; j < outCodecCtx->frame_size; j++) {</div><div>                samples[2 * j] = (uint16_t)(sin(t) * 10000);</div><div><br></div><div>                for (k = 1; k < outCodecCtx->channels; k++)</div><div>                    samples[2 * j + k] = samples[2 * j];</div><div>                t += tincr;</div><div>            }</div><div>            t = (t > 50000) ? 0 : t;</div><div><br></div><div>            // Sets time stamp</div><div>            next_pts += outFrame->nb_samples;</div><div>            outFrame->pts = next_pts;</div><div><br></div><div>            /* encode the samples */</div><div>            ret = avcodec_encode_audio2(<wbr>outCodecCtx, &pkt, outFrame, &got_output);</div><div>            if (ret < 0) {</div><div>                fprintf(stderr, "Error encoding audio frame\n");</div><div>                exit(1);</div><div>            }</div><div>            if (got_output) {</div><div>                write_frame(outFormatCtx, &outCodecCtx->time_base, outAudioStream, &pkt);</div><div>                av_packet_unref(&pkt);</div><div>            }</div><div><br></div><div>            printf("i:%d\n", i); // waste some time to avoid over-filling jitter buffer</div><div>            printf("Audio: %d\t%d\n", samples[0], samples[1]); // waste some time to avoid over-filling jitter buffer</div><div>            printf("t: %f\n", t); // waste some time to avoid over-filling jitter buffer</div><div>        }</div><div><br></div><div>        /* get the delayed frames */</div><div>        for (got_output = 1; got_output; i++) {</div><div>            ret = avcodec_encode_audio2(<wbr>outCodecCtx, &pkt, NULL, &got_output);</div><div>            if (ret < 0) {</div><div>                fprintf(stderr, "Error encoding frame\n");</div><div>                exit(1);</div><div>            }</div><div><br></div><div>            if (got_output) {</div><div>                pkt.pts = AV_NOPTS_VALUE;</div><div>                write_frame(outFormatCtx, &outCodecCtx->time_base, outAudioStream, &pkt);</div><div>                av_packet_unref(&pkt);</div><div>            }</div><div>        }</div><div><br></div><div>        av_freep(&samples);</div><div>        av_frame_free(&outFrame);</div><div>        avcodec_close(outCodecCtx);</div><div>        av_free(outCodecCtx);</div><div>    }</div><div><br></div><div><br></div><div>    int main(int argc, char **argv)</div><div>    {</div><div>        const char *output;</div><div><br></div><div>        av_register_all();</div><div>        avformat_network_init(); // for network streaming</div><div><br></div><div>        audio_encode_example("rtp://<a href="http://127.0.0.1:8554" target="_blank">12<wbr>7.0.0.1:8554</a>");</div><div><br></div><div>        return 0;</div><div>    }</div><div>    </div><div><br></div></div></blockquote><div><br></div></div></div><span style="font-size:13px">Interestingly, the same code when compiled in Linux Ubuntu gives the following:</span><div style="font-size:13px"><br></div><div style="font-size:13px"><span><div>Output #0, rtp, to 'rtp://<a href="http://127.0.0.1:8554" target="_blank">127.0.0.1:8554</a>':</div></span><div>    Stream #0:0: Unknown: none (pcm_s16be)</div><span><div>v=0</div><div>o=- 0 0 IN IP4 127.0.0.1</div><div>s=No Name</div><div>c=IN IP4 127.0.0.1</div><div>t=0 0</div></span><div>a=tool:libavformat 57.48.100</div><div>m=application 8554 RTP/AVP 3</div></div><div style="font-size:13px"><br></div><div style="font-size:13px">I noticed that the Output stream is now labeled as "Unknown". And in the SDP dump, the media name is switched from audio to application. RTP/AVP is now 3 instead of 96/97. What's going on?</div><div style="font-size:13px"><br></div><div style="font-size:13px">Would really appreciate it if any of you could shine some light on this.</div><div> </div></div></div>
<br></blockquote></div></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','Libav-user@ffmpeg.org');" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/<wbr>listinfo/libav-user</a><br>
<br></blockquote></div><br></div>
______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="javascript:_e(%7B%7D,'cvml','Libav-user@ffmpeg.org');" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/<wbr>listinfo/libav-user</a></blockquote><div><br></div><p dir="ltr">Fair enough. But how do I assign the payload ID? In Ubuntu, the RTP/AVP is 3 instead of 96/97 and using ffplay didn't work. Should I be manually specifying the SDP file, differently from the SDP dump?</p><div>Thanks,</div><div>Ang </div></div></div>
</blockquote>