Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

philipphutterer
Copy link
Contributor

Adds functionality to read the frame type for an ffmpeg VideoCapture via property syntax. The new property CAP_PROP_FRAME_TYPE is readonly. It returns the frame type ascii code of the most recently read frame (i.e. 73 = 'I', 80 = 'P', 66 = 'B' or 63 = '?' if unknown)

closes #21859

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@philipphutterer
Copy link
Contributor Author

thanks @LukasBommes and his project mv-extractor for the idea

@alalek
Copy link
Member

alalek commented Jun 26, 2022

There is already CAP_PROP_LRF_HAS_KEY_FRAME property for the I frames.
Do we really need detailed B/P frames too?

@philipphutterer
Copy link
Contributor Author

philipphutterer commented Jun 26, 2022

I mean in order to use CAP_PROP_LRF_HAS_KEY_FRAME you need to read the video in raw mode. Also, in some tests the output of CAP_PROP_LRF_HAS_KEY_FRAME actually did not result in correct I-frames information for me with a mpegts file.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @vpisarev @asmorkalov . Let put this in as is.

Thank you for the contribution!

@opencv-pushbot opencv-pushbot merged commit 6656793 into opencv:4.x Jul 1, 2022
@alalek alalek mentioned this pull request Aug 21, 2022
@yanteng
Copy link

yanteng commented Apr 27, 2023

I mean in order to use CAP_PROP_LRF_HAS_KEY_FRAME you need to read the video in raw mode. Also, in some tests the output of CAP_PROP_LRF_HAS_KEY_FRAME actually did not result in correct I-frames information for me with a mpegts file.

I also meet this problem.
I receive some rtsp streams by raw mode , sometims the CAP_PROP_LRF_HAS_KEY_FRAME never return true. In order to decode more rtsp streams, I want to only decode I-frames. So how detect I-frame more reliably under raw mode?

@philipphutterer
Copy link
Contributor Author

Does the property CAP_PROP_FRAME_TYPE not work for you? Did you try something like this:

cap = cv2.VideoCapture(...)
ret, frame = cap.read()
if cap.get(cv2.CAP_PROP_FRAME_TYPE) == ord("I"):
    # do something with this I-frame

@yanteng
Copy link

yanteng commented Apr 27, 2023

Yes, it work. However the read function decode every frame. I just wan to decode I-frame.
I use cv::cudacodec::VideoReader and implement interfacecv::cudacodec::RawVideoSource to decode, so I need use raw mode VideoCatpure to receive raw data and send only I frame data to VideoReader

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to extract frame type (I, P, B) info for better post-process without ffmpeg/ffprobe

4 participants