Skip to content

try to fix VideoCapture different time stamp(issue 8834)#14901

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
fishjam:issue_8834
Aug 6, 2019
Merged

try to fix VideoCapture different time stamp(issue 8834)#14901
opencv-pushbot merged 1 commit intoopencv:3.4from
fishjam:issue_8834

Conversation

@fishjam
Copy link
Copy Markdown

@fishjam fishjam commented Jun 26, 2019

resolves #8834

This pullrequest changes

please refer 8834's issue comment

force_builders=linux,docs

{
case CAP_PROP_POS_MSEC:
return 1000.0*(double)frame_number/get_fps();
return (dts_to_sec(picture_pts) * 1000 + 0.5);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Initial undefined value (AV_NOPTS_VALUE) is not properly handled here.
  2. Why we need 0.5?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You are right.
1.I forget the AV_NOPTS_VALUE, so I add the logical for handle it.
2.add 0.5 is for my round requirements, not need in opencv.

After refactor, I write some test code to compare result with ffprobe, it's almost same.

  • Test Code
 VideoCapture capture;
    if (capture.open(argv[1])) {
        double width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
        double height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
        double timePos = capture.get(CV_CAP_PROP_POS_MSEC);
        printf("width=%f, height=%f, index=0, timePos=%f\n", width, height, timePos);

        int index = 0;
        Mat img;
        do 
        {
            capture >> img;
            if (!img.empty())
            {
                index++;
                double timePos = capture.get(CV_CAP_PROP_POS_MSEC);
                printf("index=%d, timePos=%f\n", index, timePos);
            }
        } while (!img.empty());
    }
  • Result for opencv
width=720.000000, height=1280.000000, index=0, timePos=0.000000
index=1, timePos=0.000000
index=2, timePos=37.877778
index=3, timePos=65.933333
index=4, timePos=88.311111
index=5, timePos=101.544444
index=6, timePos=132.033333
index=7, timePos=149.877778
index=8, timePos=181.844444
index=9, timePos=215.888889
index=10, timePos=265.566667
  • Result for ffprobe
ffprobe -show_frames -print_format json Xxxx.mp4 | grep pkt_dts_time
            "pkt_dts_time": "0.000000",
            "pkt_dts_time": "0.037878",
            "pkt_dts_time": "0.065933",
            "pkt_dts_time": "0.088311",
            "pkt_dts_time": "0.101544",
            "pkt_dts_time": "0.132033",
            "pkt_dts_time": "0.149878",
            "pkt_dts_time": "0.181844",
            "pkt_dts_time": "0.215889",
            "pkt_dts_time": "0.265567",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In my case , it is not solved .still Timepos is 0.00. Don't Know why? Any more changes required?

Copy link
Copy Markdown
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.

Thank you 👍

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.

4 participants