h4tr3d / avcpp

C++ wrapper for FFmpeg
Other
429 stars 78 forks source link

Why disable socket timeout temporarily in FormatContext::findStreamInfo? #90

Closed ccsnake closed 3 years ago

ccsnake commented 3 years ago

image

This will block in some cases.

thx

h4tr3d commented 3 years ago

@ccsnake , thanks for report. Could you please attach code via code tags in textual format?

  1. It starts to be copyable.
  2. It still to be colorized
  3. It is simple to copy-paste code text.

According to your question, avformat_find_stream_info() for most header-less formats like MPEG-TS received via network requires a lot of time.

If you can provide a problematic source, that blocks in some cases call of the findStreamInfo(), I will debug it and provide a better solution.

ccsnake commented 3 years ago

thx for your reply.

Code location: https://github.com/h4tr3d/avcpp/blob/fe8847aa740aa4c2868c020c82d6765c8520c1a1/src/formatcontext.cpp#L907

My programe may blocked when i opened a local IPC stream(rtsp) which has bad network. In my case I will open and close stream with fixed interval .

h4tr3d commented 3 years ago

I analyse code. av_find_stream_info() is a complex function that some times requires so much time for internal work. FormatContext::setTimeout() useful for simple cases and mainly targeted for use with FormatContext::readPacket(). For complex cases you should use FormatContext::setInterruptCallback(). In such way, you can setup some flag, that your callback check and return 1 if findStreamInfo is timed out.

In any case, socketTimeout() is not a good choose for this option name... Maybe frameReadTimeout() is better.