欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > C++ 起始帧数、结束帧数、剪辑视频

C++ 起始帧数、结束帧数、剪辑视频

2024/10/24 20:14:14 来源:https://blog.csdn.net/qq_42102546/article/details/142339066  浏览:    关键词:C++ 起始帧数、结束帧数、剪辑视频

C++ 指定起始帧数、结束帧数、
剪辑视频

C++ 无法直接用H264,只能用avi编码格式

#include <iostream>
#include <opencv2/opencv.hpp>int main() {// 读取视频:创建了一个VideoCapture对象,参数为摄像头编号std::string path = "E:/zyk_lab/pai/";std::string mp4_name = "04010003569000000.mp4";std::string inputVideoPath = path + mp4_name;std::string outputVideoPath = path + "img/" + "ce.avi";cv::VideoCapture inputVideo(inputVideoPath);if (!inputVideo.isOpened()) {std::cerr << "Error opening input video." << std::endl;return -1;}cv::Size frameSize(static_cast<int>(inputVideo.get(cv::CAP_PROP_FRAME_WIDTH)),static_cast<int>(inputVideo.get(cv::CAP_PROP_FRAME_HEIGHT)));double fps = inputVideo.get(cv::CAP_PROP_FPS);cv::VideoWriter outputVideo(outputVideoPath, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), fps, frameSize);int currentFrame = 0;cv::Mat frame;double startFrame = ((60 * 48) + 22) * fps;  // 开始帧double endFrame = ((60 * 48) + 55) * fps;    // 结束帧while (inputVideo.read(frame)) {if (currentFrame >= (int)startFrame && currentFrame <= (int)endFrame) {outputVideo.write(frame);}currentFrame++;std::cout << std::to_string(currentFrame) << std::endl;if (currentFrame > (int)endFrame) {break;}}inputVideo.release();outputVideo.release();std::cout << "结束" << std::endl;return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com