While executing the following piece of code extended from apiexample code in
libavcodec. What I am trying to do is decoding the byte buffer of video
packets.

void decode_video(uint8_t *ibuf, int size, int codec_id)
{

AVCodec *codec;
AVCodecContext *c= NULL;
int frame, got_picture, len;
FILE *f;
AVFrame *picture;
uint8_t *inbuf_ptr;
char buf[1024];

/* set end of buffer to 0 (this ensures that no overreading happens for
damaged mpeg streams) */


printf("Video decoding\n");


printf("Video decoding 2\n");
/* find the mpeg1 video decoder */
codec = avcodec_find_decoder(codec_id);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}else {
printf("codec found\n");
}

c= avcodec_alloc_context();
picture= avcodec_alloc_frame();

if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */

/* For some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because this information is not
available in the bitstream. */

/* open it */
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}else {
printf("codec opened\n");
}

/* the codec gives us the frame size, in samples */


frame = 0;


inbuf_ptr = ibuf;
while (size > 0) {
printf("size is found \n");
len = avcodec_decode_video(c, picture, &got_picture,
inbuf_ptr, size);
if (len < 0) {
fprintf(stderr, "Error while decoding frame %d\n", frame);
exit(1);
}else {
printf("decoding now: got_picture %d \n",got_picture);
}

if (got_picture) {
printf("saving frame %3d\n", frame);
fflush(stdout);

/* the picture is allocated by the decoder. no need to
free it */
snprintf(buf, sizeof(buf), "out%d.ppm", frame);
pgm_save(picture->data[0], picture->linesize[0],
c->width, c->height, buf);
frame++;
}else {
printf("no picture got\n");
}
size -= len;
inbuf_ptr += len;
}


if (got_picture) {
printf("saving last frame %3d\n", frame);
fflush(stdout);

/* the picture is allocated by the decoder. no need to
free it */
snprintf(buf, sizeof(buf), "final", frame);
pgm_save(picture->data[0], picture->linesize[0],
c->width, c->height, buf);
frame++;
}

//fclose(f);

//avcodec_close(c);
//av_free(c);
//av_free(picture);
printf("\n");
}


#define INBUF_SIZE 4096

int main(void) {

uint8_t inbuf[INBUF_SIZE + 1024];
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
FILE *f = fopen("/opt/barsandtone.flv", "rb");
int size;
if (!f) {
fprintf(stderr, "could not open \n");
exit(1);
}

/* must be called before using avcodec lib */
avcodec_init();


printf("Video decoding 1\n");
/* register all the codecs */
avcodec_register_all();


for(;;) {

size = fread(inbuf, 1, INBUF_SIZE, f);
fprintf(stdout, "Size %d \n",size);
decode_video(inbuf, size, CODEC_ID_FLV1);
if(size <= 0) break;
}
}


I am getting the following error:

[flv @ 0x9eed170]Bad picture start code
[flv @ 0x9eed170]header damaged
Error while decoding frame 0

Any help will be appreciated.
_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to