I'm trying to build my own video player. I used this manual as an example
http://dranger.com/ffmpeg/ and compiled and got work it quite good. Now i want
to change av_open_input_file on av_open_input_stream because i want to use some
network protocol. I found lot of information how i can do it and first of all I
want to overload "read" function as a similar file load:
int read_count = 0;
double kbytes = 0;
static int read_packet_stream(void *opaque, uint8_t *buf, int buf_size) {
FILE *pFile = (FILE *)opaque;
if (!pFile)
return -1;
if (buf_size < 0)
return -1;
int p = fread(buf, sizeof(uint8_t), buf_size, pFile);
read_count++;
kbytes += p/1024;
printf ("read %d: %d bytes\n",read_count,p);
return p? p:-1;
};
Than I do next in my "open and play" function:
VideoState *is = (VideoState *)arg;
AVFormatContext *pFormatCtx;
// init buffer
int buffer_size = 32768;
unsigned char *buffer = av_malloc(buffer_size);
FILE *f;
// Open video file
f = fopen(is->filename,"rb");
if (f==NULL) {
fprintf(stderr,"could not open input file: %s",is->filename);
return -1;
}
AVInputFormat* pAVInputFormat = av_find_input_format("avi");
if(!pAVInputFormat)
{
fprintf(stderr,"Probe not successfuln");
return -1;
}
fprintf(stderr,"name: %s long name:
%s\n",pAVInputFormat->name,pAVInputFormat->long_name);
pAVInputFormat->flags |= AVFMT_NOFILE;
// init ByteIOContext
ByteIOContext *io = av_mallocz(sizeof(ByteIOContext));
io->is_streamed = 1;
int ret = init_put_byte(io, buffer, buffer_size, 0, f, read_packet_stream,
NULL, NULL);
if (ret < 0)
{
fprintf(stderr,"init_put_byte error");
return -1;
}
// Open video file
if (ret = av_open_input_stream(&pFormatCtx, io, "", pAVInputFormat, NULL)
!=0) {
fprintf(stderr,"Failed to open input stream. err code: %d",ret);
return -1;
};
/* if(av_open_input_file(&pFormatCtx, is->filename, NULL, 0, NULL)!=0)
return -1; // Couldn't open file*/
is->pFormatCtx = pFormatCtx;
// Retrieve stream information
if(av_find_stream_info(pFormatCtx)<0)
return -1; // Couldn't find stream information
// Dump information about file onto standard error
dump_format(pFormatCtx, 0, is->filename, 0);
// Find the first video stream
for(i=0; i<pFormatCtx->nb_streams; i++) {
// and so on
}
After running this code I got entering my read_packet_stream ~5000 times and
every time got excatly 32768 bytes on read. And after this i got next error:
[avi @ 0x10201fe00]Could not find codec parameters (Video: mpeg4, 640x480)
Input #0, avi, from '/somewhere/ffmpeg_proj/Debug/malcolm.avi':
Duration: 00:20:07.76, start: 0.000000, bitrate: N/A
Stream #0.0: Video: mpeg4, 640x480, 25 tbr, 25 tbn, 25 tbc
Stream #0.1: Audio: mp3, 48000 Hz, mono, s16, 64 kb/s
What did I do wrong? Or how can I make ffmpeg to find those codec parameters?
Unfortunately, didn't find any info about how i can resolve it. Hope someone
can help me!
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user