Source

bias / src / gui / video_writer_avi.cpp

#include "video_writer_avi.hpp"
#include "basic_types.hpp"
#include "exception.hpp"
#include <QFileInfo>
#include <QDir>
#include <iostream>

namespace bias
{ 
    // ----------------------------------------------------------
    // Temporary ... need to estimate this before starting video
    const double DEFAULT_AVI_FPS = 30.0; 
    // ----------------------------------------------------------

    const unsigned int VideoWriter_avi::DEFAULT_FRAME_SKIP = 5;

    VideoWriter_avi::VideoWriter_avi() : VideoWriter() 
    {
        isFirst_ = true;
        setFrameSkip(DEFAULT_FRAME_SKIP);
    }

    VideoWriter_avi::VideoWriter_avi(QString fileName) : VideoWriter(fileName)
    {
        isFirst_ = true;
        setFrameSkip(DEFAULT_FRAME_SKIP);
    }

    VideoWriter_avi::~VideoWriter_avi() {};

    void VideoWriter_avi::addFrame(StampedImage stampedImg)
    {
        if (isFirst_)
        {
            initialize(stampedImg);
            isFirst_ = false;
        }
        if (frameCount_%frameSkip_==0)
        {
            videoWriter_ << stampedImg.image;
        }
        frameCount_++;
    }

    void VideoWriter_avi::initialize(StampedImage stampedImg)
    {
        QString incrFileName = getUniqueFileName();

        try
        {
            videoWriter_.open(
                    incrFileName.toStdString(), 
                    CV_FOURCC('D','I','V', 'X'), 
                    DEFAULT_AVI_FPS, 
                    stampedImg.image.size(), 
                    false 
                    );
        }
        catch (cv::Exception &e)
        {
            unsigned int errorId = ERROR_VIDEO_WRITER_INITIALIZE;
            std::string errorMsg("video writer unable to open file:\n\n"); 
            errorMsg += e.what();
            throw RuntimeError(errorId, errorMsg); 
        }

        if (!videoWriter_.isOpened())
        {
            unsigned int errorId = ERROR_VIDEO_WRITER_INITIALIZE;
            std::string errorMsg("video writer unable to open file:\n\n"); 
            errorMsg += "no exception thrown, but file not opened??";
            throw RuntimeError(errorId, errorMsg); 
        }
        setSize(stampedImg.image.size());
    }

} // namespace bias
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.