<div dir="ltr">Hi folks,<div><br></div><div>I'm having some trouble with the decoding of my h.264 movies. I've tested with different videos, one 64 frames long and another 52 frames long. In both cases, the first 8 frames (exactly 8) weren't decoding. In other words, the call to avcodec_decode_video2 returns 0 for the got_picture variable. I track the frames read and received for our system and I never get notice that all the frames were read because my counter doesn't increase for the first 8...however all of the subsequent calls to av_read_frame return EOF. To prevent any confusion (or perhaps just to add some context), I need the raw data from each decoded frame since I don't treat them as a frame to a movie but rather a frame of x,y,z positional data.</div>
<div><br></div><div>I work in Unity but made a plugin to communicate with the libraries to read and decode the h.264 movies. This is our update function:</div><div><br></div><div><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">bool H264Stream::Update(int desiredFrame)</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">{</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> if( desiredFrame <= m_FrameRead )</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> return true;</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> int frameFinished = 0;</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> if( av_read_frame( m_AVFormat, &m_Packet ) >= 0 )</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> {</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> if( m_Packet.stream_index == m_AVStream->index )</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> {</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> av_frame_unref( m_AVFrame );</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> avcodec_decode_video2( m_AVContext, m_AVFrame, &frameFinished, &m_Packet );</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> if( frameFinished != 0 )</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> {</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> sws_scale( m_SwsContext, m_AVFrame->data, m_AVFrame->linesize, 0, m_AVContext->height, m_Picture->data, m_Picture->linesize );</span></div>
<div><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> m_FrameRead++;</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> av_free_packet( &m_Packet );</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> }</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> }</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> }</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"><span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px"> return m_FrameRead >= desiredFrame;</span><br style="margin:0px;padding:0px;color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">
<span style="color:rgb(46,139,87);font-family:Monaco,'Andale Mono','Courier New',Courier,mono;font-size:12px;line-height:15.210000038146973px">}</span><br></div><div><br></div><div><br></div><div>Oh, quick note, this is my first time using these libraries so if there's something blatantly wrong with how I'm doing this, please let me know. :) Just keep in mind, it's the full frame of 'raw' data I use (post-decode) that I pass back into my Unity c# scripts.</div>
<div><br></div><div>Thanks for the help everyone!</div><div>-Matt</div></div>