使用OpenCV和gstreamer编写可以在Web Brauser(firefox / opera)中打开的MP4文件

时间:2018-07-13 13:22:59

标签: opencv gstreamer mp4

我正在尝试从IPCamera接收视频流,并想要编写可在firefox / bouser中打开的视频mp4

以下工作正常:

  gst-launch-1.0 -e rtspsrc location = rtsp://.... ! decodebin ! x264enc ! mp4mux ! filesink location=file.mp4$

我可以在firefox中打开此(file.mp4)文件。

但是当我从opencv写入文件时,我得到的是mp4视频文件,该文件可以在vlc中打开,但不能在brouser / firefox中打开:

    int main()
    {
        const char* gst = "rtspsrc location = rtsp://<ipcamera>  latency=0  ! rtph264depay ! avdec_h264 ! videoconvert ! appsink";
        const char*  gst_writer = "appsrc ! autovideoconvert ! x264enc ! mp4mux ! filesink location=test.mp4";
        cv::VideoCapture cap(gst);
        if (!cap.isOpened()) {
            std::cout << "Failed to open camera." << std::endl;
            return (-1);
        }
        unsigned int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
        unsigned int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
        unsigned int fps = cap.get(CV_CAP_PROP_FPS);
        unsigned int pixels = width * height;
        std::cout << " Frame size : " << width << " x " << height << ", " << pixels << " Pixels " << fps << " FPS" << std::endl;
        cv::VideoWriter writer(gst_writer, cap.get(CV_CAP_PROP_FOURCC), fps, cv::Size(width, height));
        if (!writer.isOpened()) {
            std::cout << "Failed to open writer." << std::endl;
            return (-2);
        }

        cv::Mat frame_in;
        while (1)
        {
            if (!cap.read(frame_in)) {
                std::cout << "Capture read error" << std::endl;
                break;
            }
            else {
                writer.write(frame_in);
            }
            cv::imshow("webCamera", frame_in);
            char c = (char)cv::waitKey(10);
            if (c == 27 || c == 'q' || c == 'Q')//ESC
                break;

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

如何解决此问题?请帮忙!

0 个答案:

没有答案