[Libav-user] H.264 Looping
Matt Orlando
morlando616 at gmail.com
Wed Jul 23 23:06:49 CEST 2014
Hi everyone,
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.
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.
Here's the update code:
bool H264Stream::Update(int desiredFrame)
> {
> if( desiredFrame <= m_FrameRead )
> return true;
> int frameFinished = 0;
> if( av_read_frame( m_AVFormat, &m_Packet ) >= 0 )
> {
> if( m_Packet.stream_index == m_AVStream->index )
> {
> avcodec_decode_video2( m_AVContext, m_AVFrame, &frameFinished, &m_Packet );
> if( frameFinished != 0 )
> {
> sws_scale( m_SwsContext, m_AVFrame->data, m_AVFrame->linesize, 0,
> m_AVContext->height, m_Picture->data, m_Picture->linesize );
> m_FrameRead++;
> av_free_packet( &m_Packet );
> }
> }
> else
> {
> av_free_packet( &m_Packet );
> }
> }
> else if( !m_Completed )
> {
> m_Packet.data = NULL;
> m_Packet.size = 0;
> avcodec_decode_video2( m_AVContext, m_AVFrame, &frameFinished, &m_Packet );
> if( frameFinished != 0 )
> {
> sws_scale( m_SwsContext, m_AVFrame->data, m_AVFrame->linesize, 0,
> m_AVContext->height, m_Picture->data, m_Picture->linesize );
> m_FrameRead++;
> }
> else
> {
> m_Completed = true;
> av_free_packet( &m_Packet );
> }
> }
> return m_FrameRead >= desiredFrame;
> }
Thanks for the help!
-Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140723/9db81273/attachment.html>
More information about the Libav-user
mailing list