<div dir="ltr">Hi everyone,<div><br></div><div>I need to implement a means of looping some h.264 videos. I'll copy my current implementation here for my update so you can see how it's currently working. I use Unity so this code resides in a native plug-in that I turn into a DLL. My C# scripts track the current frame they've acquired since multiple streams run in conjunction with each other to form a single "asset". For any looping clips, I'd like to reset the desired frame to 0 and have the DLL start streaming again from the beginning.</div>
<div><br></div><div>If anyone can help point me in the right direction for handling this, that'd be amazing. I'm sure there are simple ways I could go that'd basically re-open the streams; however, I need to make sure there's no hiccup of course.</div>
<div><br></div><div>Here's the update code:</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
bool H264Stream::Update(int desiredFrame)<br>{<br><span class="" style="white-space:pre"> </span>if( desiredFrame <= m_FrameRead )<br><span class="" style="white-space:pre"> </span>return true;<br><span class="" style="white-space:pre"> </span>int frameFinished = 0;<br>
<span class="" style="white-space:pre"> </span>if( av_read_frame( m_AVFormat, &m_Packet ) >= 0 )<br><span class="" style="white-space:pre"> </span>{<br><span class="" style="white-space:pre"> </span>if( m_Packet.stream_index == m_AVStream->index )<br>
<span class="" style="white-space:pre"> </span>{<br><span class="" style="white-space:pre"> </span>avcodec_decode_video2( m_AVContext, m_AVFrame, &frameFinished, &m_Packet );<br><span class="" style="white-space:pre"> </span>if( frameFinished != 0 )<br>
<span class="" style="white-space:pre"> </span>{<br><span class="" style="white-space:pre"> </span>sws_scale( m_SwsContext, m_AVFrame->data, m_AVFrame->linesize, 0, m_AVContext->height, m_Picture->data, m_Picture->linesize );<br>
<span class="" style="white-space:pre"> </span>m_FrameRead++;<br><span class="" style="white-space:pre"> </span>av_free_packet( &m_Packet );<br><span class="" style="white-space:pre"> </span>}<br><span class="" style="white-space:pre"> </span>}<br>
<span class="" style="white-space:pre"> </span>else<br><span class="" style="white-space:pre"> </span>{<br><span class="" style="white-space:pre"> </span>av_free_packet( &m_Packet );<br><span class="" style="white-space:pre"> </span>}<br>
<span class="" style="white-space:pre"> </span>}<br><span class="" style="white-space:pre"> </span>else if( !m_Completed )<br><span class="" style="white-space:pre"> </span>{<br><span class="" style="white-space:pre"> </span>m_Packet.data = NULL;<br>
<span class="" style="white-space:pre"> </span>m_Packet.size = 0;<br><span class="" style="white-space:pre"> </span>avcodec_decode_video2( m_AVContext, m_AVFrame, &frameFinished, &m_Packet );<br><span class="" style="white-space:pre"> </span>if( frameFinished != 0 )<br>
<span class="" style="white-space:pre"> </span>{<br><span class="" style="white-space:pre"> </span>sws_scale( m_SwsContext, m_AVFrame->data, m_AVFrame->linesize, 0, m_AVContext->height, m_Picture->data, m_Picture->linesize );<br>
<span class="" style="white-space:pre"> </span>m_FrameRead++;<br><span class="" style="white-space:pre"> </span>}<br><span class="" style="white-space:pre"> </span>else<br><span class="" style="white-space:pre"> </span>{<br>
<span class="" style="white-space:pre"> </span>m_Completed = true;<br><span class="" style="white-space:pre"> </span>av_free_packet( &m_Packet );<br><span class="" style="white-space:pre"> </span>}<br><span class="" style="white-space:pre"> </span>}<br>
<span class="" style="white-space:pre"> </span>return m_FrameRead >= desiredFrame;<br>}</blockquote><div><br></div><div><br></div><div>Thanks for the help!</div><div>-Matt </div></div></div>