ffmpeg - avcodec_open2: PCM channels out of bounds -


i trying read audio rtp stream in application, getting error:

[pcm_mulaw @ 03390580] pcm channels out of bounds 

i can read rtp stream fine ffplay:

ffplay -i test.sdp -protocol_whitelist file,udp,rtp 

i generate rtp stream using command:

ffmpeg -re -f lavfi -i aevalsrc="sin(400*2*pi*t)" -ar 8000 -f mulaw -f rtp rtp://127.0.0.1:8554  // sdp v=0 o=- 0 0 in ip4 127.0.0.1 s=no name c=in ip4 127.0.0.1 t=0 0 a=tool:libavformat 57.25.101 m=audio 8554 rtp/avp 0 b=as:64 

and here source code:

#include "stdafx.h" #include <math.h> extern "c" {     #include <libavutil/opt.h>     #include <libavcodec/avcodec.h>     #include <libavutil/channel_layout.h>     #include <libavutil/common.h>     #include <libavutil/imgutils.h>     #include <libavutil/mathematics.h>     #include <libavutil/samplefmt.h>     #include <libavformat/avformat.h> }  #define audio_inbuf_size 20480 #define audio_refill_thresh 4096  #define errbufflen 200 char errbuf[errbufflen]; #define av_err2str(ret) av_strerror(ret, errbuf, errbufflen)  /* * audio decoding. */ static void audio_decode_example(const char *outfilename, const char *filename) {     avcodec *incodec;     avcodeccontext *incodecctx = null;     int len;     file *f, *outfile;     uint8_t inbuf[audio_inbuf_size + av_input_buffer_padding_size];     avpacket avpkt;     avframe *decoded_frame = null;       avformatcontext *informatctx = null;     avframe *inframe = null;     avframe *outframe = null;      int ret;      av_init_packet(&avpkt);      avdictionary *d = null;           // "create" empty dictionary     int listen = false;     listen = true;     if (listen)     {         av_dict_set(&d, "protocol_whitelist", "file,udp,rtp", 0); // add entry         printf("listening mode.\n");     }     else {         printf("connecting mode.\n");     }      // open video file     ret = avformat_open_input(&informatctx, filename, null, &d);     if (ret <0)     {         printf_s("failed: cannot open input.\n");         av_strerror(ret, errbuf, errbufflen);         fprintf(stderr, "avformat_open_input() fail: %s\n", errbuf);         exit(1);     }      printf_s("retrieve stream information.\n");     ret = avformat_find_stream_info(informatctx, null);     if (ret <0)     {         printf_s("failed: cannot find stream.\n");         av_strerror(ret, errbuf, errbufflen);         fprintf(stderr, "avformat_find_stream_info() fail: %s\n", errbuf);         exit(1);     }      av_dump_format(informatctx, 0, filename, 0);      int stream_idx = -1;      (int = 0; < informatctx->nb_streams; i++)         if (informatctx->streams[i]->codec->codec_type == avmedia_type_audio) {             stream_idx = i;             break;         }     if (stream_idx == -1)     {         fprintf(stderr, "video stream not found\n");         exit(1);     }      incodec = avcodec_find_decoder(informatctx->streams[stream_idx]->codec->codec_id);     if (!incodec) {         fprintf(stderr, "codec not found\n");         exit(1);     }      incodecctx = avcodec_alloc_context3(incodec);     if (!incodecctx) {         fprintf(stderr, "could not allocate audio codec context\n");         exit(1);     }     /* error here */     ret = avcodec_open2(incodecctx, incodec, null);     if (ret < 0) {         fprintf(stderr, "could not open codec: %s\n", av_err2str(ret));         exit(1);     }     (...more code) 

i know wrong, it? suggestions , tips appreciated.

i found out stream attributes not set automatically, had manually set them before calling avcodec_open2():

incodecctx->sample_rate = 8000; incodecctx->sample_fmt = av_sample_fmt_s16; incodecctx->channels = 1; incodecctx->channel_layout = av_ch_layout_mono; 

hope helps encountered same issue do.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -