[Ffmpeg-devel] Bad image with H.263
Cool_Zer0
c00jz3r0
Thu Dec 14 17:10:01 CET 2006
Hi there!
I'm having some problems decoding H.263.
Here's the situation:
I'm receiving the H.263 frame on a RTP packets. I can extract the H.263
packet from the RTP Packet.
After that I send the full H.263 packet to ffmpeg with something like:
{
...
video_decode((unsigned char*)payload, payloadlen);
...
}
At the end I put the code that I use to handle video...
The problem is that the image looks very strange (I can't explain in in
English...)... I've upload to a server two things:
- Print screen of image problems:
http://student.dei.uc.pt/~ncenteio/ffmpeg/raw_images.bmp (890kb)
- RAW format in RGB24 of the images in
http://student.dei.uc.pt/~ncenteio/ffmpeg/raw.zip (4Mb)
I appreciate any help that you can give me.
Thanks
---------------------------
AVCodec *codec;
AVCodecContext *c = NULL;
int frame, size, got_picture, len;
AVFrame *picture;
uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
char buf[1024];
AVFrame *pFrameRGB;
int numBytes;
uint8_t *buffer;
void video_decode_init() {
/* must be called before using avcodec lib */
avcodec_init();
/* register all the codecs (you can also register only the codec
you wish to have smaller code */
register_avcodec(&h263_decoder);
av_register_codec_parser(&h263_parser);
// Allocate an AVFrame structure
pFrameRGB=avcodec_alloc_frame();
if(pFrameRGB==NULL) {
printf("Error no avcodec_alloc_frame do RGB!!!\n");
exit(1);
}
// Determine required buffer size and allocate buffer
numBytes=avpicture_get_size(PIX_FMT_RGB24, 176, 144);
buffer=new uint8_t[numBytes];
// Assign appropriate parts of buffer to image planes in pFrameRGB
avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, 176, 144);
/* set end of buffer to 0 (this ensures that no overreading happens
for damaged mpeg streams) */
memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
printf("Video decoding\n");
/* find the mpeg1 video decoder */
codec = avcodec_find_decoder(CODEC_ID_H263);
if (!codec) {
fprintf(stderr, "codec not found\n");
exit(1);
}
c= avcodec_alloc_context();
picture= avcodec_alloc_frame();
if(codec->capabilities&CODEC_CAP_TRUNCATED)
c->flags|= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */
/* for some codecs, such as msmpeg4 and mpeg4, width and height
MUST be initialized there because these info are not available
in the bitstream */
//c->width=176;
//c->height=144;
/* open it */
if (avcodec_open(c, codec) < 0) {
fprintf(stderr, "could not open codec\n");
exit(1);
}
img_convert_create(); // I need this because the initialization of
the array doesn't work in Microsoft Visual C++ Compiler
frame = 0;
}
void video_decode_terminate() {
avcodec_close(c);
av_free(c);
av_free(picture);
}
void video_decode(unsigned char* payload, int payloadsize)
{
//dump_frame_header(payload, frame);
inbuf_ptr = payload;
size = payloadsize;
while (size > 0) {
len = avcodec_decode_video(c, picture, &got_picture, inbuf_ptr,
size);
if (len < 0) {
return;
}
if (got_picture) {
img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
(AVPicture*)picture, c->pix_fmt, 176, 144);
rgb_save(pFrameRGB->data[0], "frame");
frame++;
}
size -= len;
inbuf_ptr += len;
}
len = avcodec_decode_video(c, picture, &got_picture, NULL, 0);
if (got_picture) {
img_convert((AVPicture *)pFrameRGB, PIX_FMT_RGB24,
(AVPicture*)picture, c->pix_fmt, 176, 144);
rgb_save(pFrameRGB->data[0], "frame");
frame++;
}
}
void rgb_save(unsigned char *buf, char *filename)
{
static int frame_nbr = 0;
char file[200];
sprintf(file, "0%d_frame.raw", (frame_nbr++));
FILE *f;
f=fopen(file,"wb");
fwrite(buf, 1, 176*144*3, f);
fclose(file);
}
More information about the ffmpeg-devel
mailing list