<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Oct 9, 2013, at 6:28 AM, James Board <<a href="mailto:jpboard2@yahoo.com">jpboard2@yahoo.com</a>> wrote:</div><div><br></div><div><span style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px; background-color: rgb(255, 255, 255); ">Actually I have already wasted several weeks or months of coding time doing what you suggested: assume ffmpeg/libav works the way you want it, then start coding.  </span></div><div><span style="font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 16px; background-color: rgb(255, 255, 255); "><br></span></div><div>I didn't say that at all. Based on my experience, it's highly unlikely ffmpeg works the way you want. It works the way it works. Rather, I suggested building an app that does playback, then see if it will do what you want it to. </div><blockquote type="cite"><div><div style="background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt; position: static; z-index: auto; "><div><br></div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal; ">I want to have multiple threads decoding different parts of the AVI file concurrently.  No encoding will occur.  Seems like it should be thread-safe.  But I'd like to know for sure before I start coding.  That's all.  Ask questions first, code later.  That stops me from complaining when libav doesn't do what I want.  I'll just choose another route.</div></div></div></blockquote><div><br></div><div>Not sure anything would do that. There's too many assumptions about the file. File access doesn't even really work that way. Codecs that aren't i-frame only don't work that way. Even disk heads don't work that way.</div><div><br></div><div>If you're deadset on it, in order to solve the problem you think you might have, then use multiple instances of a whole ffmpeg pipeline - file context, audio and video codec contexts. That's multi-threaded safe. Use the lockmanager functions to protect access to specific calls (getting codec instances etc.).</div><div><br></div><div>My rule of thumb these days - is to assume that the collective intelligence of the people (not me, I'm just a 'user' of ffmpeg) who made the API I'm choosing is better than my singular, less specific experience. Every time I feel compelled to re-invent the wheel because I know better (coff, coff), it turns out the existing API decsions were better.</div><div><br></div><div>Bruce</div><div><br></div><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div><div style="background-color: rgb(255, 255, 255); font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 12pt; position: static; z-index: auto; "><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal; "><br></div><div style="font-size: 16px; font-family: HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: transparent; font-style: normal; "><br></div><div style="display: block;" class="yahoo_quoted"> <br> <br> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> On , Bruce Wheaton <<a href="mailto:bruce@spearmorgan.com">bruce@spearmorgan.com</a>> wrote:<br> </font> </div>  <div class="y_msg_container"><div id="yiv3076803796"><div><div>On Oct 8, 2013, at 12:05 PM, James Board <<a rel="nofollow" shape="rect" ymailto="mailto:jpboard2@yahoo.com" target="_blank" href="mailto:jpboard2@yahoo.com">jpboard2@yahoo.com</a>> wrote:</div><br class="yiv3076803796Apple-interchange-newline" clear="none"><blockquote type="cite"><div style="background-color:rgb(255, 255, 255);font-family:HelveticaNeue, 'Helvetica Neue', Helvetica,
 Arial, 'Lucida Grande', sans-serif;font-size:12pt;"><div>I want to create several pthreads in a C++ program (assuming you can call</div><div>libav routines from a C++ program) that each call libav subroutines.  <br clear="none"></div></div></blockquote><div><br clear="none"></div>Well, yes, you can call C from a C++ app. You need to mark the headers as C when you include them, but that's about it.</div><div><br clear="none"><blockquote type="cite"><div style="background-color:rgb(255, 255, 255);font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:12pt;"><div style="font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal;">Are the libav subroutines  thread-safe?  Specifically,</div><div>can several pthreads open the same AVI file and decode different video</div><div>frames
 concurrently?</div></div></blockquote><div><br clear="none"></div><div>No, not really. At least, you'd have to lock the access entirely, which would make it sequential. You can use each context in one thread, and there are a few overall functions that need locking, such as choosing the right codecs for a file.</div><div class="yiv3076803796yqt2178940347" id="yiv3076803796yqtfd69708"><br clear="none"><blockquote type="cite"><div style="background-color:rgb(255, 255, 255);font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:12pt;"><div><br clear="none"></div><div style="font-size:16px;font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;background-color:transparent;font-style:normal;">I'm doing this so I can write a real-time video
 that</div><div>can play the video forward and backwards, and the multiple threads will</div><div>help decode and process each frame quickly so there will be no delay when</div><div>I step through the video.</div></div></blockquote></div><br clear="none"></div><div>Most codecs are multi-threaded by now - so there already are threads running to decode frames. You can set the number of threads you want a codec to use when you open it.</div><div><br clear="none"></div><div>There's a number of other things you could do... multiple codecs open etc. But with codecs that need B and P frames, you pretty much have to decode in order anyway, and file access is always going to be one at a time.</div><div><br clear="none"></div><div>It sounds like you're trying to solve a problem that you don't have yet. Start with the basics - just getting going from a cold start in ffmpeg is enough trouble for most people, without trying to get clever.</div><div><br clear="none"></div><div>Bruce</div><div class="yiv3076803796yqt2178940347" id="yiv3076803796yqtfd74218"><div><br clear="none"></div><div><br clear="none"></div><div><br clear="none"></div><br clear="none"></div></div><br>_______________________________________________<br clear="none">Libav-user mailing list<br clear="none"><a shape="rect" ymailto="mailto:Libav-user@ffmpeg.org" href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br clear="none"><a shape="rect" href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><div class="yqt2178940347" id="yqtfd33330"><br clear="none"></div><br><br></div>  </div> </div>  </div> </div></div>_______________________________________________<br>Libav-user mailing list<br><a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>http://ffmpeg.org/mailman/listinfo/libav-user<br></blockquote></div><br></body></html>