[Libav-user] Decoding opus

Aboobeker Sidhik Koyamparambil mammu aboosidhik at gmail.com
Wed Jan 11 14:00:06 EET 2017

Dear All,

I am trying to decode opus. When I use both methods
avcodec_decode_audio4 and (avcodec_send_packet /avcodec_receive_frame) . I
am receiving the same opus packet that I send for decoding. I got this by
using the packet size of the decoded frame. Packet size is same as the
input opus packet size.

I followed the decoding example given in github of ffmpeg. Please help me.
Why I am receiving same packet as input?

AVCodec *codec;
AVCodecContext *c = NULL;
AVPacket avpkt;
AVFrame *decoded_frame = NULL;
codec = avcodec_find_decoder(AV_CODEC_ID_OPUS);
if (!codec) {
     printf("Codec not found\n");
c = avcodec_alloc_context3(codec);
if (!c) {
   printf("Could not allocate audio codec context\n");
/* put sample parameters */
c->sample_rate = 48000;
c->request_sample_fmt = AV_SAMPLE_FMT_FLT;
c->channels = 2;
/* open it */
if (avcodec_open2(c, codec, NULL) < 0) {
    printf("Could not open codec\n");

AVPacket avpkt;
AVFrame *decoded_frame = NULL;
avpkt.data = Buffer;  // Buffer is packet data here
avpkt.size = len;    // length of the packet
int i, ch;

if (!decoded_frame) {
    if (!(decoded_frame = av_frame_alloc())) {
        RELAY_SERVER_PRINT("Could not allocate audio frame\n");
int ret;
int got_frame = 0;
ret = avcodec_decode_audio4(client_sockt_num_1->c, decoded_frame,
&got_frame, &avpkt);
if (ret < 0) {
        fprintf(stderr, "Error decoding audio frame (%s)\n", av_err2str(ret));
        return ret;
printf("length %i\n", decoded_frame->pkt_size);

Kind Regards

Aboobeker Sidhik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20170111/90c27c00/attachment.html>

More information about the Libav-user mailing list