Using environment variable to store capture options#9292
Using environment variable to store capture options#9292vpisarev merged 4 commits intoopencv:masterfrom
Conversation
…tring(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")
|
Hello, I'm having trouble identifying which version of ffmpeg is used for the build. I set up a linux build of FFMPEG/OpenCV and I don't get any compile issues. Any help would be appreciated. |
|
from here (quite at the bottom), that's the failed one: while the linux opencl bot (success) has: |
|
These builders are based on Ubuntu 14.04 (failed) and Ubuntu 16.04 (passed). |
| #endif | ||
|
|
||
| #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0) | ||
| #if LIBAVFORMAT_BUILD > CALC_FFMPEG_VERSION(51,11,0) |
There was a problem hiding this comment.
Why is this change here?
- Condition must be ">=". ">" should not be used at all for version checks.
- Perhaps we should check for 53.4.0 (avformat_open_input)
- These change must be propagated to many places with "dict" (av_dict_free / declaration / etc)
There was a problem hiding this comment.
Ah crap, this is a mistake. Sorry about the sloppy commits.
There was a problem hiding this comment.
With regards to 53.4.0, that makes sense to me. However, I am already making mistakes with regards to ffmpeg version checks, so ideally I would make as few changes as possible.
| } | ||
| else | ||
| { | ||
| #if LIBAVUTIL_BUILD > CALC_FFMPEG_VERSION(52,6,0) |
There was a problem hiding this comment.
#if LIBAVUTIL_BUILD >= (LIBAVUTIL_VERSION_MICRO >= 100 ? CALC_FFMPEG_VERSION(52, 17, 100) : CALC_FFMPEG_VERSION(52, 7, 0))
There was a problem hiding this comment.
Thanks, I am unfamiliar with the ffmpeg versioning. Fixes incoming.
Copy/paste error due to coder mistake reverted Proper version checking for LIBAVUTIL_BUILD
|
New code usage could be as follows: #if WIN32
_putenv_s("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp");
#else
setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "rtsp_transport;udp");
#endif
auto capture = cv::VideoCapture(someURL, cv::CAP_FFMPEG);
#if WIN32
_putenv_s("OPENCV_FFMPEG_CAPTURE_OPTIONS", "");
#else
unsetenv("OPENCV_FFMPEG_CAPTURE_OPTIONS");
#endif |
|
Definitely interesting, thanks a lot 👍 And is there a place in the documentation where your latest comment could be added? |
|
Hmm, that does seem cleaner. The only pro to this method (I was inspired by another bug report of a similar topic) is that now you can pass any option(s) to ffmpeg. I'm happy to write it up, but I'm not familiar with the docs. I'd appreciate any pointer to the right spot! |
|
Both ways have their pros/cons. I'm unsure which one to prefer. |
|
I think I would stay with the current implementation. Is this mergeable? |
|
how robust is the solution? Assume that there are 2 apps on a system, one just uses opencv + ffmpeg to read videos from disk, another one reads videos via network and so the options are relevant. This solution is global and so the first app will stop working. Shall we come up with some better solution? |
|
@vpisarev I'm open to other solutions, but this solution is only global if the env variable is set permanently. Given my code example above, the options can be set in the code (more advanced code could cache any pre-existing options, and then restore them after connecting) without applying to other programs. |
|
Environment variables have process scope, so solution/workaround is fine until we have some configuration API in OpenCV. |
* Using environment variable to store options parsed by av_dict_parse_string(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")
* Adding missing mandatory flags parameter
* Guarding against missing function via LIBAVUTIL version
* Code review fixes
Copy/paste error due to coder mistake reverted
Proper version checking for LIBAVUTIL_BUILD
|
Hey, Guys, I'm happy to find out that TCP issue is fixed in this patch. But only by reading code, I'm a little bit confused how to tell OpenCV to use UDP whenever reading RTSP streams. Can you guys kindly provide a simple example? |
|
You'll have to set an environment variable when creating the device |
|
This solution doesn't work on windows when using a dynamic library. Something like this seems to occure. The use case is when mixing several rtsp stream with mixed protocol (udp,tcp) in the same executable. The environment variable set by code isn't reflected in the opencv library. Works fine on linux ... |
|
What a pain, thank you for catching this. I recommend opening a new issue to change the env var approach! |
hi, how can I set this env. on Java OpenCV? |
String is parsed by av_dict_parse_string(ENV{OPENCV_FFMPEG_CAPTURE_OPTIONS}, ";", "|")
resolves #9290
This pullrequest changes
Allows configuration of ffmpeg capture options via environment variable. If variable is not set or OpenCV cannot read env variables, defaults to TCP as per previous behaviour.