树莓派 ubuntu mate opencv4.5.3环境下的opencv程序错误

安装好opencv4.5.3之后,写了一个运行摄像头的程序:

int main(){
    Mat frame;
    VideoCapture cap(0);
    if(!cap.isOpened()){
          cout<<"error"<<endl;
}

namedWindow("output");

while(1){
      cout<<"1"<<endl;
      cap>>frame;
      if(frame.empty()){
          break;
}
      imshow("output",frame);
       cout<<"2"<<endl;
       if(waitKey()==27){
          break;
}
}
return 0;
}

运行后只显示摄像头读取画面的第一帧,在循环中输出1和2,在bash中只输出了第一次循环的1和2,之后程序就不动了,也不继续执行,不报错,只提示: gstreamer warning: cannot query video position: status=0,value=-1,duration=-1
网上查了一些,并没有解决。