[Libav-user] Decoding Problem (got_picture always return 0)
Yinxia
hydezhao at gmail.com
Thu Mar 22 17:32:22 CET 2012
Hi dear all,
I am a newbie to ffmpeg and I would like to decode the bitstream, which is
encoded using libx264 at the server end and sent to client frame by frame.
I wrote a function decodeFrame to decode this bitstream frame by frame,
this function is called in a loop, each time recieves a new frame:
void decodeFrame( int size, unsigned char *data)
{
avpkt.size = size;
avpkt.data = (uint8_t *)(data);
/*decode each frame*/
len = avcodec_decode_video2(c, picture, &got_picture, avpkt.size);
if (len < 0) {
fprintf(stderr, "[avcodec][Err] Error while decoding frame %d\n",frame);
exit(1);
}
if (got_picture) {
printf("[avcodec] Saving frame %3d\n",frame);
fflush(stdout);
_snprintf(buf, sizeof(buf), "/temp/video%d.pgm", frame); // not found
pgmSave(picture->data[0], picture->linesize[0], c->width, c->height, buf);
frame++;
}
}
I can successfully get the value of len, which is exactly the size of
frame, however, *the value of *got_picture *is always 0. *Can anyone help
me with this?
*
*
PS. this is the init function of decoder.
void initDecoder()
{
avcodec_register_all();
av_init_packet(&avpkt);
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
printf("[avcodec] Frame decoding initializing\n");
/*choose correct video decoder*/
codec = avcodec_find_decoder(CODEC_ID_MPEG4);
if ( !codec ) {
fprintf(stderr, "[avcodec][Err] codec not found!\n");
exit(1);
}
c = avcodec_alloc_context3(codec);
picture = avcodec_alloc_frame();
if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete
frames */
/* open it */
if (avcodec_open2(c, codec, NULL) < 0) {
fprintf(stderr, "[avcodec][Err] could not open codec\n");
exit(1);
}
frame = 0;
}
Thank you very much!
Yinxia
--
View this message in context: http://libav-users.943685.n4.nabble.com/Decoding-Problem-got-picture-always-return-0-tp4496039p4496039.html
Sent from the libav-users mailing list archive at Nabble.com.
More information about the Libav-user
mailing list