简体   繁体   中英

OpenCV C++ - Not able to show a video

Linux Debian 10 + OpenCV 320.

Very basic sample to play a video but the application soon ends without open a new window and witout errors.

My tests with same videos but in different types: mp4 and webm. The video are correctly shown by VLC and other video players.

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;

int main(int argc, char** argv )
{
    // check
    if ( argc != 2 )
    {
        printf("usage: %s <Video_Path>\n", argv[0]);
        return -1;
    }
    printf("Video: %s\n", argv[1]);

    // load video
    VideoCapture cap ( argv[1]);
    if (!cap.isOpened()){
        printf("Error opening video\n");
    }

    Mat frame;
    while(1){
        // cap.read(frame);
        cap >> frame;
          if (frame.empty()){
              printf(".. frame err\n");
              return -1;
          }
        imshow("Live", frame);
        if (waitKey(5)>=0) break;
    }
    printf("end\n");
    return 0;
}

The output is:

$ ./DisplayVideo 20200313_152914.webm 
Video: 20200313_152914.webm
end

我解决了转换为字符的问题:

if ((char)(waitKey(1))>=0){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM