bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.51k stars 1.58k forks source link

getLengthInVideoFrames's return value is not accurate frame count #1941

Open ggslayer opened 1 year ago

ggslayer commented 1 year ago

Hi, I'm using FFMpegFrameGrabber to a mp4 file , I use getLengthInvideoFrame after start method, and I get 2108 frames, But when I grab every video frames, totally only 2107 frames, the getLengthInvideoFrame returned is not the real frame count, How can I get the accurately frame count beore grab one by one? Thank you

anotherche commented 1 year ago

You may try this count technique

AVPacket pkt;
int videoFrameNumber = 0;
int vsInd = grabber.getVideoStream();
while ((pkt=grabber.grabPacket())!=null) {
     if (pkt.stream_index() == vsInd) videoFrameNumber++;
}
ggslayer commented 1 year ago

thank you, I will try it