-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
VideoCapture: change CAP_PROP_FOURCC to fix #22876
#23540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| CAP_PROP_CODEC_EXTRADATA_INDEX = 68, //!< Positive index indicates that returning extra data is supported by the video back end. This can be retrieved as cap.retrieve(data, <returned index>). E.g. When reading from a h264 encoded RTSP stream, the FFmpeg backend could return the SPS and/or PPS if available (if sent in reply to a DESCRIBE request), from calls to cap.retrieve(data, <returned index>). | ||
| CAP_PROP_FRAME_TYPE = 69, //!< (read-only) FFmpeg back-end only - Frame type ascii code (73 = 'I', 80 = 'P', 66 = 'B' or 63 = '?' if unknown) of the most recently read frame. | ||
| CAP_PROP_N_THREADS = 70, //!< (**open-only**) Set the maximum number of threads to use. Use 0 to use as many threads as CPU cores (applicable for FFmpeg back-end only). | ||
| CAP_PROP_CODEC_FOURCC = 71, //!< 4-character code representing type of the encoded data (the codec used). This differs from CAP_PROP_FOURCC which can represent additional information about the codec. e.g. CAP_PROP_FOURCC can return divx, xvid, mp4v etc. for an MPEG-4 video where CAP_PROP_CODEC_FOURCC would return only FMP4 (applicable for FFmpeg back-end only). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some mess with:
CAP_PROP_FOURCC =6, //!< 4-character code of codec. see VideoWriter::fourcc .
Both describes the "codec".
We could deprecate the old one, but we need robust and clear solution.
BTW, there are 3 different FOURCC could be used in some pipelines: camera firmware/device level(MJPEG compression), codec(YUV), output of VideoCapture(BGR24).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its currently confusing as CAP_PROP_FOURCC is a mixture of the codec_id and the codec_tag
/** * Specific type of the encoded data (the codec used). */ enum AVCodecID codec_id; /** * Additional information about the codec (corresponds to the AVI FOURCC). */ uint32_t codec_tag;
this makes sense for a fourcc code as the codec_tag is the fourcc and if it doesn't exist we fallback to generating one from the codec_id. That said the description 4-character code of codec is not correct.
My initial idea for the PR was to simply to generate the fourcc with the codec_id instead of the codec_tag and fall back to codec_tag if there were any issues. This would be clearer but it could break existing code which relies on the existing values.
As different video codecs can have the same codec_tag, e.g. the codec_tag returned for the three test video's below is mp4v
highgui/video/big_buck_bunny.mp4
highgui/video/sample_322x242_15frames.yuv420p.mpeg2video.mp4
highgui/video/sample_322x242_15frames.yuv420p.mjpeg.mp4
when they use MPEG-4, MPEG-2 and MJPG codec respectively. It might be better to remove codec_tag completely and return false (-1) if a fourcc cannot be generated from the codec_id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@opencv-alalek updated to translate codec_id to fourcc and fallback to codec_tag if this doesn't exist. This seems like a robust solution, the returned value will now "always" (apart from when the codec_id field doesn't exist) be the 4-character code of codec.
72b4425 to
88a438e
Compare
VideoCapture: add CAP_PROP_CODEC_FOURCC to fix #22876VideoCapture: change CAP_PROP_FOURCC to fix #22876
VideoCapture: change CAP_PROP_FOURCC to fix #22876VideoCapture: change CAP_PROP_FOURCC to fix #22876
1ae8920 to
46c91ad
Compare
|
@opencv-alalek Are you happy with the approach in this PR? Forcing |
asmorkalov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
46c91ad to
024c836
Compare
|
The issue is still there: |
|
@asmorkalov See my reply in the other PR opencv/opencv_contrib#3488 (comment) |
Address #22876 by adding a
CAP_PROP_CODEC_FOURCCto theVideoCaptureFFmpeg backend.Merge with opencv/opencv_contrib#3488
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.