opencv支持H264视频编码
生活随笔
收集整理的這篇文章主要介紹了
opencv支持H264视频编码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 原始會報錯
- 解決方式
原始會報錯
Mat src;// use default camera as video sourceVideoCapture cap(0);// check if we succeededif (!cap.isOpened()) {cerr << "ERROR! Unable to open camera\n";return;}// get one frame from camera to know frame size and typecap >> src;// check if we succeededif (src.empty()) {cerr << "ERROR! blank frame grabbed\n";return;}bool isColor = (src.type() == CV_8UC3);//--- INITIALIZE VIDEOWRITERVideoWriter writer;int codec = VideoWriter::fourcc('H', '2', '6', '4'/*'P','I','M','1'*//*'M', 'J', 'P', 'G'*/); // select desired codec (must be available at runtime)double fps = 30.0; // framerate of the created video streamstring filename = "./h264.avi"; // name of the output video filewriter.open(filename, codec, fps, src.size(), isColor);// check if we succeededif (!writer.isOpened()) {cerr << "Could not open the output video file for write\n";return;}//--- GRAB AND WRITE LOOPcout << "Writing videofile: " << filename << endl<< "Press any key to terminate" << endl;int frame_cnt = 0;for (;;){// check if we succeededif (!cap.read(src) || frame_cnt > 60) {cerr << "ERROR! blank frame grabbed\n";break;}// encode the frame into the videofile streamwriter.write(src);frame_cnt += 1;// show live and wait for a key with timeout long enough to show imagesimshow("Live", src);if (waitKey(5) >= 0)break;}- 報錯內容
解決方式
根據提示的錯誤內容去https://github.com/cisco/openh264/releases網站去下載對應的openh264-1.8.0-win64.dll文件放在當前項目文件夾下,再次執行即可解決
總結
以上是生活随笔為你收集整理的opencv支持H264视频编码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用css pie.htc解决IE8 不支
- 下一篇: 计世网:人类最迫切需要的10项技术