Qt+OpenCV以时间命名视频名字

在多次保存视频的情况下,如果每次都手动修改视频名字,显得很麻烦,因此考虑通过时间戳来命名视频的名字,这样每次保存的视频都不会重复

首先添加头文件

#include <QDateTime>

然后在程序中添加代码如下:

/******************************
 ***********保存视频按钮************
 *****************************/
void MainWindow::on_TakePicBtn_clicked()
{
    QDateTime ctime = QDateTime::currentDateTime();
    QString sss = ctime.toString("MMddhhmm");
    int ss = sss.toInt();
    QString a = QString::number(ss);
    QString out0 = QString("D:\\0-%1.avi").arg(ss);
    QString out1 = QString("D:\\1-%1.avi").arg(ss);
    QByteArray location0 = out0.toLatin1();
    QByteArray location1 = out1.toLatin1();
    char* outFile0 = location0.data();
    char* outFile1 = location1.data();
    if(!(cam0.isOpened() && cam1.isOpened()))
    {
        cam0.open(0);
        cam1.open(1);
    }
    write0.open(outFile0,VideoWriter::fourcc('M', 'J', 'P', 'G'), 30.0, Size(640, 480), true);
    write1.open(outFile1,VideoWriter::fourcc('M', 'J', 'P', 'G'), 30.0, Size(640, 480), true);
    while(OPEN)
    {
        if(cam0.isOpened())
        {
            cam0 >> frame0;
            //if(!frame0) break;
            write0.write(frame0);
            namedWindow("VideoPlay0", WINDOW_NORMAL);
            imshow("VideoPlay0", frame0);
            waitKey(1000 / 30);
        }
        if(cam1.isOpened())
        {
            cam1 >> frame1;
            //if(!frame1) break;
            write1.write(frame1);
            namedWindow("VideoPlay1", WINDOW_NORMAL);
            imshow("VideoPlay1", frame1);
            waitKey(1000 / 30);
        }
    }
}

相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页