00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QVVideoRecorder>
00026
00027 QVVideoRecorder::~QVVideoRecorder()
00028 {
00029 videoFile.close();
00030 }
00031
00032 bool QVVideoRecorder::linkProperty(QString sourcePropertyName, QVPropertyContainer *destinyContainer, QString destinyPropertyName, LinkType linkType)
00033 { return false; }
00034
00035 QVVideoRecorder::QVVideoRecorder(QString name, const QString fileName, const int fps): QVWorker(name), initiated(false), rgbMode(true)
00036 {
00037 addProperty< QVImage<uChar,3> >("Input image", inputFlag);
00038 addProperty< QVImage<uChar,1> >("Input image Y", inputFlag);
00039 addProperty< QVImage<uChar,1> >("Input image U", inputFlag);
00040 addProperty< QVImage<uChar,1> >("Input image V", inputFlag);
00041
00042 addProperty< QString >("Record file name", inputFlag, fileName);
00043 addProperty< int >("FPS", inputFlag, fps);
00044 }
00045
00046 bool QVVideoRecorder::linkProperty(QVWorker &worker, const QString rgbImageName)
00047 {
00048 worker.linkProperty(rgbImageName, this, "Input image", SynchronousLink);
00049 rgbMode = true;
00050 }
00051
00052 bool QVVideoRecorder::linkProperty(QVWorker &worker, const QString yImageName, const QString uImageName, const QString vImageName)
00053 {
00054 worker.linkProperty(yImageName, this, "Input image Y", SynchronousLink);
00055 worker.linkProperty(uImageName, this, "Input image U", SynchronousLink);
00056 worker.linkProperty(vImageName, this, "Input image V", SynchronousLink);
00057 rgbMode = false;
00058 }
00059
00060 void QVVideoRecorder::iterate()
00061 {
00062 if (!initiated)
00063 {
00064 int cols, rows;
00065
00066 if (rgbMode)
00067 {
00068 const QVImage<uChar, 3> imageRGB = getPropertyValue< QVImage<uChar, 3> >("Input image");
00069 cols = imageRGB.getCols();
00070 rows = imageRGB.getRows();
00071 }
00072 else {
00073 const QVImage<uChar, 1> imageY = getPropertyValue< QVImage<uChar, 1> >("Input image Y");
00074 cols = imageY.getCols();
00075 rows = imageY.getRows();
00076 }
00077 if (cols > 1 && rows > 1)
00078 {
00079 videoFile.setFileName(getPropertyValue<QString>("Record file name"));
00080 videoFile.open(QIODevice::WriteOnly|QIODevice::Truncate);
00081 writeYUV4MPEG2Header(videoFile, cols, rows, getPropertyValue<int>("FPS"));
00082 initiated = true;
00083 }
00084 }
00085 if (rgbMode)
00086 {
00087 const QVImage<uChar, 3> imageRGB = getPropertyValue< QVImage<uChar, 3> >("Input image");
00088 writeYUV4MPEG2Frame(videoFile, imageRGB);
00089 }
00090 else {
00091 const QVImage<uChar, 1> imageY = getPropertyValue< QVImage<uChar, 1> >("Input image Y");
00092 const QVImage<uChar, 1> imageU = getPropertyValue< QVImage<uChar, 1> >("Input image U");
00093 const QVImage<uChar, 1> imageV = getPropertyValue< QVImage<uChar, 1> >("Input image V");
00094 writeYUV4MPEG2Frame(videoFile, imageY, imageU, imageV);
00095 }
00096 }