[Libav-user] Error in reading streaming context - using libavcodec 57.64.101

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Libav-user] Error in reading streaming context - using libavcodec 57.64.101

יוסף אלון

I am reading a udp data and recieve:

Input #0, mpegts, from 'udp://224.10.0.15:1234':
  Duration: N/A, start: 66502.042356, bitrate: N/A
  Program 29
    Metadata:
      service_name    : Galatz
      service_provider: Idan +
    Stream #0:0[0xb81]: Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp

But when I print the codec context I receive the following data:
Bits: 8, Channels:2048
sample_rate: 8.

What is the meaning of 2048 channels (2 - is stereo)?
and why do I have 8 bit for fltp?

The code part is:

 av_register_all();
   avformat_network_init();
 
 
    const char* input_filename=argv[1];
  
   AVFormatContext* container=avformat_alloc_context();
    if(avformat_open_input(&container,input_filename,NULL,NULL)<0)
        die("Could not open file");
  
    if(avformat_find_stream_info(container,NULL)<0)
        die("Could not find file info");
  
 
   av_dump_format(container,0,input_filename,0);

  
    int stream_id=-1;
    int i;
    for(i=0;i<container->nb_streams;i++)
    {
       if(container->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)
        {
            stream_id=i;//audio stream index
            break;
        }
    }
    if(stream_id==-1){
        die("Could not find Audio Stream");
    }

  //  AVDictionary *metadata=container->metadata;

    AVCodecContext *ctx=container->streams[stream_id]->codec;
    AVCodec *codec=avcodec_find_decoder(ctx->codec_id);
 
   // ctx=avcodec_alloc_context3(codec);
   
    if(codec==NULL){
        die("cannot find codec!");
    }

  
    if(avcodec_open2(ctx,codec, NULL)<0){
        die("Codec cannot be found");
    }
int bits;
if(sfmt==AV_SAMPLE_FMT_U8){
        printf("U8\n");

        bits=8;
    }else if(sfmt==AV_SAMPLE_FMT_S16){
        printf("S16\n");
        bits=16;
    }else if(sfmt==AV_SAMPLE_FMT_S32){
        printf("S32\n");
       bits=32;
    }
   else if(sfmt==AV_SAMPLE_FMT_FLTP){
        bits=32;
   }
printf("\nBits: %d, Channels:%d\nRate: %d, byte_format:%d matrix:%s\n",bits, ctx->channels, sformat.rate, sformat.byte_format,sformat.matrix);


Yosef Alon

_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error in reading streaming context - using libavcodec 57.64.101

Carl Eugen Hoyos-2
2017-04-04 12:15 GMT+02:00 יוסף אלון <[hidden email]>:

>
> I am reading a udp data and recieve:
>
> Input #0, mpegts, from 'udp://224.10.0.15:1234':
>   Duration: N/A, start: 66502.042356, bitrate: N/A
>   Program 29
>     Metadata:
>       service_name    : Galatz
>       service_provider: Idan +
>     Stream #0:0[0xb81]: Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011),
> 48000 Hz, stereo, fltp
>
> But when I print the codec context I receive the following data:
> Bits: 8, Channels:2048
> sample_rate: 8.

The code you posted looks different from this output.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Error in reading streaming context - using libavcodec 57.64.101

יוסף אלון
you right (I tried to make it simpler) this is the code:

#include "libavformat/avformat.h"
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <libavutil/rational.h>
#include <libavutil/samplefmt.h>
#include "libswresample/swresample.h"

#include <stdio.h>
#include <assert.h>

#define AVCODEC_MAX_AUDIO_FRAME_SIZE 19200

void die(const char *msg)
{
    fprintf(stderr,"%s\n",msg);
    exit(1);
}

int main(int argc, char** argv)
{
   
    av_register_all();
   avformat_network_init();
 
 
    const char* input_filename=argv[1];
  
   AVFormatContext* container=avformat_alloc_context();
    if(avformat_open_input(&container,input_filename,NULL,NULL)<0)
        die("Could not open file");
  
    if(avformat_find_stream_info(container,NULL)<0)
        die("Could not find file info");
  
 
   av_dump_format(container,0,input_filename,0);

  
    int stream_id=-1;
    int i;
    for(i=0;i<container->nb_streams;i++)
    {
       if(container->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO)
        {
            stream_id=i;//audio stream index
            break;
        }
    }
    if(stream_id==-1){
        die("Could not find Audio Stream");
    }

    AVDictionary *metadata=container->metadata;

    AVCodecContext *ctx=container->streams[stream_id]->codec;
    AVCodec *codec=avcodec_find_decoder(ctx->codec_id);
 
    ctx=avcodec_alloc_context3(codec);
   
    if(codec==NULL){
        die("cannot find codec!");
    }

  
    if(avcodec_open2(ctx,codec, NULL)<0){
        die("Codec cannot be found");
    }
    
    int bits;
    enum AVSampleFormat sfmt=ctx->sample_fmt;

    if(sfmt==AV_SAMPLE_FMT_U8){
        printf("U8\n");

        bits=8;
    }else if(sfmt==AV_SAMPLE_FMT_S16){
        printf("S16\n");
        bits=16;
    }else if(sfmt==AV_SAMPLE_FMT_S32){
        printf("S32\n");
        bits=32;
    }
   else if(sfmt==AV_SAMPLE_FMT_FLTP){
        bits=32;
   }
  
   printf("\nBits: %d, Channels:%d\nRate: %d\n",bits, ctx->channels, ctx->sample_rate );
  
    
    // prepare to read data
    AVPacket packet;
    av_init_packet(&packet);

    AVFrame *frame=av_frame_alloc();
    if (!frame)
    {
        fprintf(stderr, "Error allocating the frame\n");
        return -1;
    }
  
    int buffer_size=AVCODEC_MAX_AUDIO_FRAME_SIZE+ FF_INPUT_BUFFER_PADDING_SIZE;
  
    uint8_t buffer[buffer_size];
    packet.data=buffer;
    packet.size =buffer_size;
    packet.pos = 0; //add from https://lists.ffmpeg.org/pipermail/ffmpeg-user/2013-August/017040.html
  
    int len;
    int frameFinished=0;
    i = 0;
 
     while(av_read_frame(container,&packet)>=0)
    {

        if(packet.stream_index==stream_id){
            //printf("Audio Frame read  \n");
            int len=avcodec_decode_audio4(ctx,frame,&frameFinished,&packet);
            //frame->
            if(frameFinished){
              printf("Finished reading Frame len : %d , nb_samples:%d buffer_size:%d line size: %d \n",len,frame->nb_samples,buffer_size,frame->linesize[0]);
             
                if (i == 0)
                {
                    printf("play\n");
                    i++;
                }
            }else
            {
                printf("Not Finished\n");
            }

        }else {
            printf("Some other packet possibly Video\n");
        }


    }

    avformat_close_input(&container);
    return 0;
}

2017-04-04 13:35 GMT+03:00 Carl Eugen Hoyos <[hidden email]>:
2017-04-04 12:15 GMT+02:00 יוסף אלון <[hidden email]>:
>
> I am reading a udp data and recieve:
>
> Input #0, mpegts, from 'udp://224.10.0.15:1234':
>   Duration: N/A, start: 66502.042356, bitrate: N/A
>   Program 29
>     Metadata:
>       service_name    : Galatz
>       service_provider: Idan +
>     Stream #0:0[0xb81]: Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011),
> 48000 Hz, stereo, fltp
>
> But when I print the codec context I receive the following data:
> Bits: 8, Channels:2048
> sample_rate: 8.

The code you posted looks different from this output.

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user



--
בברכה, יוסף אלון
050-4916740

_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user
Loading...