<p>Hi, you should use CODEC_ID_H264, cause libx264 produces h.264 video stream and ffmpeg mpeg4 decoder can not decode h.264 video stream.</p>
<p>Hung, Nguyen Viet</p>
<div class="gmail_quote">On Mar 23, 2012 8:11 PM, "ZHAO Yinxia" <<a href="mailto:hydezhao@gmail.com">hydezhao@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi huanggh0108,<div><br></div><div>I am sure I have no audio frame... While, I use libx264 to encode the frames, and I am not sure I chose the right CODEC_ID for decoding.</div><div><br></div><div>I use CODEC_ID_MPEG4. CODEC_ID_H264 looks more reasonable, but returns a "no frame" error.<br>


<br><div class="gmail_quote">2012/3/23 huanggh0108 <span dir="ltr"><<a href="mailto:huanggh0108@sina.com" target="_blank">huanggh0108@sina.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<u></u>





<div style="MARGIN:10px;FONT-FAMILY:verdana;FONT-SIZE:10pt">
<div><font color="#000080" face="Verdana">I guess the data may be 
audio frame, not video frame.  The data should be filtered before sending 
at the server end.</font></div>
<div><font color="#000080" face="Verdana"></font> </div>
<div><font color="#000080" face="Verdana"></font> </div>
<div><font color="#c0c0c0" face="Verdana">2012-03-23 </font></div><font color="#000080" face="Verdana">
<hr style="WIDTH:100px" align="left" color="#b5c4df" size="1"><span><font color="#888888">
</font></span></font><span><font color="#888888">
<div><font color="#c0c0c0" face="Verdana"><span>huanggh0108</span> 
</font></div>
<hr color="#b5c4df" size="1">

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



<div>Sent from the libav-users mailing list archive at Nabble.com.</div>
<div>_______________________________________________</div>
<div>Libav-user mailing list</div>
<div><a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a></div>
<div><a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a></div>
<div></div></font></div></div></div></div>
<br>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br></blockquote></div>