dev-logs

동영상을 일정시간으로 분할하기 본문

공부/OpenCV

동영상을 일정시간으로 분할하기

두룹두두 2017. 12. 4. 17:23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <opencv\cv.h>
#include <opencv\highgui.h>

using namespace std;
using namespace cv;

int main()
{
    const string inPath = " "; //파일명 포함한 입력파일 경로
    string outPath; 
    string folderPath = " ";//저장할 폴더경로
    int fileCnt = 1;
    int frameCnt = 0;

    VideoCapture vc(inPath);
    if (!vc.isOpened()){
        cout << "can't open File" << endl;
        return 0;
    }
    double fps = vc.get(CV_CAP_PROP_FPS);
    int width = (int)vc.get(CV_CAP_PROP_FRAME_WIDTH);
    int height = (int)vc.get(CV_CAP_PROP_FRAME_HEIGHT);
    outPath = folderPath + "/*파일이름*/" +to_string(fileCnt) + ".avi";
    cout << "outputPath" << outPath << endl;
    VideoWriter vw;
    vw = VideoWriter(outPath, CV_FOURCC('X''V''I''D'), fps, Size(width, height));
    while (1)
    {
        Mat frame;
        vc >> frame;
        if (frame.empty()){
            vw.release();
            cout << "done" << endl;
            return 0;
        }
        if (frameCnt == 1800){ //fps 30기준으로 프레임갯수가 1800개이면 1분!
            vw.release();
            fileCnt++;
            frameCnt = 0;
            outPath = folderPath + "/*파일이름*/" + to_string(fileCnt) + ".avi";
            cout << "outputPath" << outPath << endl;
            vw = VideoWriter(outPath, CV_FOURCC('X''V''I''D'), fps, Size(width, height));
        }
        vw << frame;
        frameCnt++;
        
    }
}
cs


동영상 파일을 입력받고 fps 를 이용해서 영상을 원하는 시간만큼 분할한다.



'공부 > OpenCV' 카테고리의 다른 글

Mat 비교해서 동영상 프레임 보정하기  (0) 2018.06.14
mat 사용방법  (0) 2017.12.05
Comments