Skip to content
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

How to read lenght of file in frame and how to jump to specific frame #53

Closed
4 tasks done
TomasTrnkaPLC opened this issue Sep 8, 2019 · 5 comments
Closed
4 tasks done
Labels
INVALID 🛑 This doesn't seem right or non-applicable or missing information QUESTION ❓ User asked about the working/usage of VidGear APIs.

Comments

@TomasTrnkaPLC
Copy link

TomasTrnkaPLC commented Sep 8, 2019

Hi.
I want to use vidgear with for webcam and also the file loading.
For webcam or youtube run everything well problem is when I load the video.
My program is based on frame position so I use code like this:

video_pos =int(cap.get(cv2.CAP_PROP_POS_FRAMES))

but I get error
AttributeError: 'CamGear' object has no attribute 'get' how I can fix it?

Some question is how I can jump to specific frame.

Thanks for the answer

Question

Acknowledgment

  • A brief but descriptive Title of your issue.
  • I have searched the issues for my issue and found nothing related or helpful.
  • I have read the FAQ.
  • I have read the Wiki.

Context

Your Environment

  • VidGear version:
  • Branch:
  • Python version:
  • pip version:
  • Operating System and version:

Optional

@TomasTrnkaPLC
Copy link
Author

I want to use vidgear with for webcam and also the file loading.
For webcam or youtube run everything well problem is when I load the video.
My program is based on frame position so I use code like this:

video_pos =int(cap.get(cv2.CAP_PROP_POS_FRAMES))

but I get error
AttributeError: 'CamGear' object has no attribute 'get' how I can fix it?

Some question is how I can jump to specific frame.

Thanks for the answer

@abhiTronix
Copy link
Owner

My program is based on frame position so I use code like this:

video_pos =int(cap.get(cv2.CAP_PROP_POS_FRAMES))

but I get error
AttributeError: 'CamGear' object has no attribute 'get' how I can fix it?

Some question is how I can jump to specific frame.

@TomasTrnkaPLC This is not a bug or issue with vidgear, you can easily access frame position with vidgear as follows:

from vidgear.gears import CamGear
import cv2

cap =  CamGear(source='test.mp4').start()
video_pos =int(cap.stream.get(cv2.CAP_PROP_POS_FRAMES))

⚠️ But it is not advisable nor it is guaranteed that it will work and here are some reasons for this conclusion:

Why it is not advisable to use VidGear for jumping/seeking specific frame?

VidGear provides a high-level Threaded wrapper around OpenCV's API that targets only specific methods and classes related to Video Processing. It is possible to access other methods too but not advisable with VidGear as it uses Threads and Queue structure for capturing frame, which can result in undesired effects with those methods. Therefore you should refrain yourself from using frame jumping/seeking in VidGear but rather use OpenCV directly for this purpose.

Why it is not advisable to use Frame Jumping/Seeking in OpenCV at all?

OpenCV is still in beta stage, with many bugs that remain unsolved. The VideoCapture::set (CAP_PROP_POS_FRAMES, frameNumber) method itself is not exact or reliable in OpenCV and can lead to wrong frame seeking at any instance. You can see this famous issue in OpenCV github repository related to this bug: opencv/opencv#9053 which is still unsolved.

Here is the comment from Alexander Alekhin(Lead developer at OpenCV):

OpenCV highly uses FFmpeg (in case of FFmpeg backend).
But FFmpeg itself doesn't work well with seeking on non "key" frames. There are many workarounds, but they are not very reliable. Sometimes seeking code works, sometimes doesn't.
If your have worked FFmpeg's code with accurate seeking, then we could try to integrate it into OpenCV.

Hence, Kindly refrain from using Frame Jumping/Seeking with OpenCV at all. Hope this helps good luck.

@abhiTronix abhiTronix added INVALID 🛑 This doesn't seem right or non-applicable or missing information QUESTION ❓ User asked about the working/usage of VidGear APIs. labels Sep 9, 2019
@TomasTrnkaPLC
Copy link
Author

TomasTrnkaPLC commented Sep 9, 2019 via email

@abhiTronix
Copy link
Owner

abhiTronix commented Sep 9, 2019

I have one more question
when I try run = cap.stream.set(cv2.CAP_PROP_POS_FRAMES,trackbarValue) I
get reply True but stream never jump there. I talking about the jump when
is file loaded.

@TomasTrnkaPLC I already told you that OpenCV is still buggy and cannot reliably seek/jump frame due to a inherit bug. You can see this issue in OpenCV Github repository related to this bug: opencv/opencv#9053 which is still unsolved.

on Windows 10 scripts only create
an empty .mp4 file and never record anything. Why?

@TomasTrnkaPLC Wrong, I tested all my VidGear scripts on Windows 10 x64 machine, There must a problem at your end. Kindly paste the terminal log here for further debugging the error which is causing this problem.

@TomasTrnkaPLC
Copy link
Author

TomasTrnkaPLC commented Sep 9, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INVALID 🛑 This doesn't seem right or non-applicable or missing information QUESTION ❓ User asked about the working/usage of VidGear APIs.
Projects
None yet
Development

No branches or pull requests

2 participants