<html><head><style>P {margin-top:2px;margin-bottom:2px;}</style></head><body><div style="font-size:10pt; font-family:gulim,Gulim,AppleGothic,sans-serif;"><P>Hi All,</P>
<P> </P>
<P>H.264 decoding picture does not display properly.</P>
<P>I refer to output-example.c in ffmpeg and SDL display example.</P>
<P>SDL does not display a picture. I can see gray color only.</P>
<P>Are there any missing point to decode H.264?</P>
<P> </P>
<P>I'm writing my code as below.</P>
<P>When I tested H.263 decoding, there was no problem.</P>
<P> </P>
<P>Thank you for your help.</P>
<P> </P>
<P>-------------------------------------------------</P>
<P>codec = avcodec_find_decoder(CODEC_ID_H264);<BR>if (!codec) {<BR> fprintf(stderr, "codec not found\n");<BR> exit(1);<BR> }<BR><BR>dec_picture= avcodec_alloc_frame();</P>
<P>c= avcodec_alloc_context();<BR>c->codec_type = AVMEDIA_TYPE_VIDEO;<BR>c->codec_id = CODEC_ID_H264;<BR>c->width = width;<BR>c->height = height;<BR>c->pix_fmt = PIX_FMT_YUV420P; </P>
<P>c->bits_per_raw_sample = 8;<BR>if(codec->capabilities&CODEC_CAP_TRUNCATED)<BR> c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */</P>
<P> /* open it */<BR> if (avcodec_open(c, codec) < 0) {<BR> fprintf(stderr, "could not open codec\n");<BR> exit(1);<BR> }<BR> <BR> // Allocate an AVFrame structure<BR> pFrameRGB = avcodec_alloc_frame();<BR> if (pFrameRGB == NULL) return;<BR> numBytes = avpicture_get_size(PIX_FMT_RGB24, width,height);<BR> buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t));<BR> avpicture_fill((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGB24,width, height);</P>
<P> </P>
<P> f = fopen("h264.sample", "rb");<BR> if (!f) {<BR> fprintf(stderr, "could not open %s\n", "sample file");<BR> exit(1);<BR> }</P>
<P> </P>
<P>for(;;) {<BR> len = fread(inbuf, 1, INBUF_SIZE, f);<BR> if (len == 0)<BR> break;<BR> <BR> av_new_packet(&avpkt, len);<BR> avpkt.data = inbuf;</P>
<P> </P>
<P> while (avpkt.size > 0) { <BR> len = avcodec_decode_video2(c, dec_picture, &got_picture, &avpkt);<BR> if (len < 0) {<BR> fprintf(stderr, "Error while decoding frame %d\n", frame);<BR> // exit(1);<BR> break;<BR> }</P>
<P> if (got_picture) {</P>
<P>/////////////////////////SDL Copy Start//////////////////////////// <BR> SDL_LockYUVOverlay(bmp);<BR>// AVPicture pict;<BR> pict.data[0] = bmp->pixels[0];<BR> pict.data[1] = bmp->pixels[2];<BR> pict.data[2] = bmp->pixels[1];</P>
<P> pict.linesize[0] = bmp->pitches[0];<BR> pict.linesize[1] = bmp->pitches[2];<BR> pict.linesize[2] = bmp->pitches[1];<BR>/////////////////////////SDL Copy End////////////////////////////<BR> img_convert_ctx = sws_getContext(c->width,c->height, PIX_FMT_YUV420P,<BR> c ->width,c->height, PIX_FMT_YUV420P,<BR> sws_flags, NULL, NULL, NULL);</P>
<P> sws_scale(img_convert_ctx, dec_picture->data, dec_picture->linesize, 0,<BR> c->height, pict.data, pict.linesize);</P>
<P> sws_freeContext(img_convert_ctx);</P>
<P> SDL_UnlockYUVOverlay(bmp);</P>
<P> rect.x = 0;<BR> rect.y = 0;<BR> rect.w = c->width;<BR> rect.h = c->height;<BR> SDL_DisplayYUVOverlay(bmp, &rect)</P>
<P> }<BR> avpkt.size -= len;<BR> avpkt.data += len;<BR> } </P>
<P> } //end of for();</P>
<P> </P>
<P>Best Regards,</P>
<P>HSK</P></div></body></html><!--navermail.footer.start-->
<!--navermail.footer.end-->
<IMG SRC="http://mail2.naver.com/newmailcheck/KPbmW60Obr2/KqUYaqElK43vpoISKqk0FzpCaA+SFqKrKxtrK4twaAu/K6pg+H+0MoKX7xU5W4dQarwGM4Jr7BkqpBigp4pRbzkN74eZpm==.gif" border=0 width=0 height=0 style="display:none">