简体   繁体   English

Raspberry Pi 4 上的 H.265 编码速度慢

[英]H.265 encoding slow on Raspberry Pi 4

OpenCV is so slow on video encoding, like 20 frames per minute , (On 8GB Pi4, 256MB GPU memory, 850MHz GPU Clock, and 2147MHz on CPU Clock) OpenCV is so slow on video encoding, like 20 frames per minute , (On 8GB Pi4, 256MB GPU memory, 850MHz GPU Clock, and 2147MHz on CPU Clock)

I think, threading it to one core for taking frames, another one for saving to video will make a better performance but I don't know how I can do it我认为,将其线程化到一个核心以获取帧,另一个用于保存到视频会产生更好的性能,但我不知道我该怎么做

The code:编码:

#include <opencv4/opencv2/opencv.hpp>
using namespace cv;

int main() {
    Mat image;
    VideoWriter video("outcpp.mp4", cv::VideoWriter::fourcc('H','V','C','1'), 30, Size(640, 480));
    namedWindow("main");
    VideoCapture cap(0);
    while (1) {
        cap >> image;
        video.write(image);
        imshow("main", image);
        if ((char)waitKey(1) == 27)
            break;
    }
    cap.release();
}

Manjaro ARM, OpenCV with FFMPEG. Manjaro ARM、OpenCV 与 FFMPEG。

First post, if anything is wrong, kindly write, thanks.第一次发帖,如有不妥,欢迎留言,谢谢。

You might also need to ensure you are using the hardware video encoding supported by your Pi rather than compressing on the CPU您可能还需要确保使用 Pi 支持的硬件视频编码,而不是在 CPU 上进行压缩

Thanks to Alan Birtles, hardware encoding on Pi is way faster than CPU encoding, for who needs, the code (changes are noted in the comment lines):感谢 Alan Birtles,Pi 上的硬件编码比 CPU 编码快得多,对于谁需要,代码(更改在注释行中注明):

#include <opencv4/opencv2/opencv.hpp>
using namespace cv;

int main() {
    Mat image;
    // Video format changed to '.mkv' and FourCC changed to X264
    VideoWriter video("outcpp.mkv", cv::VideoWriter::fourcc('X', '2', '6', '4'), 30, Size(640, 480));
    VideoCapture cap(0);
    int i = 0;
    // 'i' variable is only for recording 10 seconds, ignore it
    while (i < 300) {
        i++;
        cap >> image;
        imshow("main", image);
        video.write(image);
    }
    cap.release();
    video.release();
}```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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