Hi,

I am trying to decode an live MPEGTS. I am following the tutorials:

http://cdry.wordpress.com/2009/09/09/using-custom-io-callbacks-with-ffmpeg/
http://www.taoframework.com/node/599

Here i am trying to open TS file as stream but not succeeded.

and here is my code:

int IO_read_packet(void* arg,uint8_t *buffer,int buffer_size)

{

FILE * fp = (FILE *) arg;

if (!fp)

{

return -1;

}

int readDataSize;

if( buffer_size < 0 ) return -1;

readDataSize = fread(buffer,sizeof(uint8_t),buffer_size,fp);

return readDataSize? readDataSize:-1;

}

int64_t SeekFunc(void *opaque, int64_t offset, int whence)

{

FILE * fp = (FILE *) opaque;

int64_t i_absolute = (int64_t)offset;

int64_t i_size = 2048;

switch( whence )

{

#ifdef AVSEEK_SIZE

case AVSEEK_SIZE:

return i_size;

#endif

case SEEK_SET:

i_absolute = (int64_t)offset;

break;

case SEEK_CUR:

i_absolute = ftell(fp) + (int64_t)offset;

break;

case SEEK_END:

i_absolute = i_size + (int64_t)offset;

break;

default:

return -1;

}

if( i_absolute < 0 )

{

fprintf( stderr, "Trying to seek before the beginning" );

return -1;

}

if( i_size > 0 && i_absolute >= i_size )

{

fprintf( stderr, "Trying to seek too far : EOF?" );

return -1;

}

return ftell(fp);

}

AVFormatContext *pFormatCtx;

 AVInputFormat *fmt = NULL;

AVCodecContext *vdo;

AVCodec *codec;

ByteIOContext io;

AVFormatParameters params;

uint8_t pDataBuffer[2048];

long int lSize = 2048;

av_register_all();

int c;

 AVProbeData pd;

pd.filename = "/home/dvb-test1.ts";

pd.buf_size =2048;

pd.buf = (unsigned char *) av_malloc(2048);

FILE *pf1 = fopen ( "/home/dvb-test1.ts" , "r" );

if (pf1==NULL){

printf("file m1 open failed");

}


#if 1

void *pf2 = (void *)pf1;

// Read a tini bit of the input.

c = IO_read_packet(pf2,pd.buf,pd.buf_size);

fprintf(stderr,"\t d=%d",c);


 // Check input format

if( !( fmt = av_probe_input_format( &pd, 1 ) ) )

printf("Can't find input format");


 fprintf(stderr,"\nVideo Format:%s",fmt->name);


 *fmt->flags |= AVFMT_NOFILE;*


 init_put_byte( &io, pd.buf, pd.buf_size, 0,pf2,IO_read_packet, NULL,
SeekFunc);

memset(&params, 0, sizeof(params));

fprintf(stderr,"\n buf_size = %d",io.buffer_size);


 //io.is_streamed=1;

if( av_open_input_stream( &pFormatCtx, &io,"", fmt, NULL ) )

fprintf(stderr,"\n av_open_input_stream FAILED");

fprintf(stderr,"\n after open stream %d" ,pFormatCtx->nb_streams);

Now the av_probe_input_format() function returning the correct format and
init_put_byte() function is also working fine.
The av_open_input_stream() function is also not failing but returns with
pFormatCtx->nb_streams = 0
so when i pass this *pFormatCtx *to av_find_stream_info() function it fails.
Its giving error : Invalid Qsocket ...unable to read
I think this is related to file descriptor.

There is no error with the file, I can play it with mplayer and ffplay.
I tried it for other files too but getting same error.

Thank you
Amol
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to