opencv借助ffmpeg读取sdp文件进行rtp拉流 20231019

20231019

ffmpeg装起来很快

编译命令

g++ rtp_ffmpeg_test.cpp -o output $(pkg-config --libs opencv4)

代码如下 

#include 
#include 
#include 
#include 

using namespace std;
using namespace cv;
int main(int argc, char** argv) {

    cout << "--- OpenCV Verson: " << CV_VERSION << " ---" << endl;

    char env[] = "OPENCV_FFMPEG_CAPTURE_OPTIONS=protocol_whitelist;file,rtp,udp";
    int rc = putenv(env);
    if (rc != 0){
        cout << "Could not set environment variables\n" << endl;
    }

    VideoCapture cap;
    char input[] = "/home/nvidia/test.sdp";
    cap.open(input, CAP_FFMPEG);
    if(!cap.isOpened()) {
        cout << "Could not open Stream" << endl;
        return 1;
    }

    string windowName = "Test";
    namedWindow(windowName, cv::WindowFlags::WINDOW_NORMAL);
    Mat frame;

    while(1){

        cap >> frame;
        if (frame.empty()){
            cout << "Application closed due to empty frame" << endl;
            return 1;
        }

        imshow(windowName, frame);
        int c = waitKey(1);
        if (c == 27){
            break;
        }
    }

    cap.release();
    destroyAllWindows();
    return 0;
}

opencvj借助于ffmpeg读取sdp文件拉流,虽然终端很多报红,但是显示出来了。延时哟两三秒左右,运行平台是OrinNX。

你可能感兴趣的:(rtsp,用简单代码实现功能,OpenCV,rtp)