Can't get total frame count of mp4 video file using OpneCV API.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't get total frame count of mp4 video file using OpneCV API.

Jump to solution
864 Views
takayuki_ishii
Contributor IV

Hello community,

 

I try to get total frame count of video file using OpenCV API.

    cv::VideoCapture capture(video_path);
    if (!capture.isOpened()){
        throw "Error when reading video";
    }
    double frame_count = capture.get(cv::CAP_PROP_FRAME_COUNT);
    double org_height = capture.get(cv::CAP_PROP_FRAME_HEIGHT);
    double org_width = capture.get(cv::CAP_PROP_FRAME_WIDTH);
    capture.release();

	std::cout << "frame count = " << frame_count << std::endl;
	std::cout << "height      = " << org_height << std::endl;
	std::cout << "width       = " << org_width << std::endl;

 

I just try on iMX8MP-EVK and iMX8QXP-MEK with Linux BSP 5.15.71_2.2.0.

But function will be returned error status (-1).

root@imx8qxpc0mek:~/work/opencv/test_capture# g++ -O -g test_capture.cpp -l/usr/include/opencv4 -o test_capture -std=c++11 -lopencv_videoio
root@imx8qxpc0mek:~/work/opencv/test_capture# ./test_capture -video=bunny_480p.mp4
frame count = -1
height = 480
width = 854
root@imx8qxpc0mek:~/work/opencv/test_capture# ./test_capture -video=bunny_1080p.mp4
frame count = -1
height = 1080
width = 1920

 

On HOST PC Linux, it will return correct value of total frame count.

tte@evmhost20:~/imx-bsp-5.15.71/work/opencv/test_capture$ ./test_capture -video=bunny_480p.mp4
frame count = 720
height = 480
width = 854
tte@evmhost20:~/imx-bsp-5.15.71/work/opencv/test_capture$ ./test_capture -video=bunny_1080p.mp4
frame count = 1800
height = 1080
width = 1920

 

Is this file parser problem? or not a bug but a specification?

Evaluation environment as following

board : MIMX8MPLUS-EVK LPDDR4, MIMX8QXP-C0-MEK

Linux BSP : L5.15.71_2.2.0

Video file : URL https://github.com/bower-media-samples

 bunny_480p = https://github.com/bower-media-samples/big-buck-bunny-480p-30s

 bunny_1080p = https://github.com/bower-media-samples/big-buck-bunny-1080p-60fps-30s

 

Host PC : Ubuntu 20.04.2LTE x86-64

Attached are source code of test program and message log of MIMX6QXP-C0-MEK.

 

Best regards,

Ishii.

 

0 Kudos
1 Solution
842 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @takayuki_ishii,

I hope you are doing well.

In the host PC, OpenCV seems to be compiled with ffmpeg and in i.MX opencv is compiled with Gstreamer.

One can refer to a similar issue in the below thread.
https://github.com/opencv/opencv/issues/12091

Please try the example given in opencv-imx.
opencv-imx/samples/cpp/application_trace.cpp

Thanks & Regards,
Dhruvit Vasavada

View solution in original post

0 Kudos
4 Replies
843 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @takayuki_ishii,

I hope you are doing well.

In the host PC, OpenCV seems to be compiled with ffmpeg and in i.MX opencv is compiled with Gstreamer.

One can refer to a similar issue in the below thread.
https://github.com/opencv/opencv/issues/12091

Please try the example given in opencv-imx.
opencv-imx/samples/cpp/application_trace.cpp

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
827 Views
takayuki_ishii
Contributor IV

Hello @Dhruvit 

 

Thank you for your reply.

I just try to run application_trace.cpp on the target board of imx8qxp.

But nframes = (int)capture.get(CAP_PROP_FRAME_COUNT); fonction return -1.

root@imx8qxpc0mek:~/work/opencv/application_trace# ./application_trace bunny_480p.mp4
Video bunny_480p.mp4: width=854, height=480, nframes=-1
Start processing...
Press ESC key to terminate

root@imx8qxpc0mek:~/work/opencv/application_trace# ./application_trace bunny_1080p.mp4
Video bunny_1080p.mp4: width=1920, height=1080, nframes=-1
Start processing...
Press ESC key to terminate

 

Attached file is all messages to run application_trace.

 

By https://github.com/opencv/opencv/issues/12091

To solve this issue, we must build opencv with ffmpeg flag.

I'll try it later.

 

Best regards,

Ishii.

0 Kudos
818 Views
Dhruvit
NXP TechSupport
NXP TechSupport

Hi @takayuki_ishii,

I hope you are doing well.

Gstreamer might not have support for CAP_PROP_FRAME_COUNT APIs.

Please try building opencv with ffmpeg flag.

If this issue is solved, can I mark this case as close?

Thanks & Regards,
Dhruvit Vasavada

0 Kudos
779 Views
takayuki_ishii
Contributor IV

Hello @Dhruvit 

 

I add following options to my local.conf and re-build image with ffmpeg.

IMAGE_INSTALL:append = " ffmpeg "
LICENSE_FLAGS_ACCEPTED = "commercial"

 

As a result, it works fine.

root@imx8qxpc0mek:~/work/opencv/test_capture# ./test_capture -video=bunny_1080p.mp4
frame count = 1800
height      = 1080
width       = 1920
root@imx8qxpc0mek:~/work/opencv/test_capture# ./test_capture -video=bunny_480p.mp4
frame count = 720
height      = 480
width       = 854

 

Thank you for your support.

I will close this thread.

 

Best regards,

Ishii.

0 Kudos