Commit be8dcf19 authored by Thiago Santini's avatar Thiago Santini

Experimenting with new container and codec

Since OpenCV seems able to handle other containers now, we are moving away
from .avi (and it's small size limitation).

I experimented with 3 codecs for static and dynamic scenes and had mixed
results when comparing MPEG4 and H264; based on the Surface results (least
powerfull test device), I'm going with MPEG4 to begin with.
This choice is also better from the usability side since the user no
longer has to download the Cisco dlls.

MJPEG is faster, but the video size becomes huge too fast. In the future,
we make this parametrizable for the user similar to Pupil Labs.

On an additional note, the generated .mp4 videos are playable with Pupil Player
v0913.
parent 4b13ff89
......@@ -77,9 +77,6 @@ void DataRecorder::newData(DataTuple dataTuple)
if (dataStream == NULL)
return;
if (!gRecording)
return;
if (dataStream->status() == QTextStream::Ok) {
*dataStream << dataTuple.toQString();
*dataStream << gDataNewline;
......@@ -98,14 +95,32 @@ bool DataRecorder::splitVideoFile()
template <class T>
void DataRecorder::storeData(T &data)
{
if (firstFrame || splitVideoFile()) {
if (firstFrame) {
firstFrame = false;
QString fileName = id + "-P" + QString::number(videoIdx) + ".avi";
int codec = videoWriter->fourcc('D', 'I', 'V', 'X');
if (gHasOpenH264)
codec = videoWriter->fourcc('x', '2', '6', '4');
// TODO: Make the container and codecs parametrizable
// Alternative containers are .mkv and .mov, for which ffmpeg seems to use
// fourcc codes
/* OpenCV seems capable of using other containers now :D
*
* ffmpeg seems to use its own codes for tags instead of regular fourcc codes
* when mp4 container is selected; for most fourcc codes end up being invalid
* and it falls back to a default tag.
*
* From the ffmpeg source (libavformat/isom.c)
*
* { AV_CODEC_ID_MPEG4 , 0x20 },
* { AV_CODEC_ID_H264 , 0x21 },
* { AV_CODEC_ID_MJPEG , 0x6C }, // 10918-1
*
*
* MPEG4 and H264 are compressed.
* MJPEG is uncompressed (and therefore gives huge files!)
*
*/
QString fileName = id + ".mp4";
int codec = 0x20;
if (videoWriter->isOpened())
videoWriter->release();
......@@ -118,9 +133,6 @@ void DataRecorder::storeData(T &data)
videoIdx++;
}
if (!gRecording)
return;
if ( gPerformanceMonitor.shouldDrop(pmIdx, gTimer.elapsed() - data.timestamp, 1000) )
return;
......
......@@ -132,8 +132,6 @@ MainWindow::MainWindow(QWidget *parent) :
journal, SIGNAL(startRecording()) );
connect(this, SIGNAL(stopRecording()),
journal, SIGNAL(stopRecording()) );
checkForOpenH264();
}
MainWindow::~MainWindow()
......@@ -354,7 +352,6 @@ void MainWindow::on_recordingToggle_clicked()
QTimer::singleShot(500, this, SLOT(effectiveRecordingStart())); // TODO: right now we wait a predefined amount of time; ideally, we should wait for an ack from everyone involved
ui->recordingToggle->setEnabled(false);
} else {
gRecording = false;
qInfo() << "Record stopped (Subject:" << ui->subject->text() << ")";
emit stopRecording();
disconnect(gazeEstimationWidget, SIGNAL(outDataTuple(DataTuple)),
......@@ -373,7 +370,6 @@ void MainWindow::effectiveRecordingStart()
{
elapsedTime.restart();
elapsedTimeUpdateTimer = startTimer(500);
gRecording = true;
ui->recordingToggle->setEnabled(true);
qInfo() << "Record started.";
}
......@@ -534,53 +530,3 @@ void MainWindow::showAboutDialog()
msg.append("Copyright &copy; 2017 University of Tübingen");
QMessageBox::about(this, "About", msg);
}
void MainWindow::checkForOpenH264()
{
QString openh264 = "unknown-platform-for-openh264";
#ifdef _WIN64
openh264 = "openh264-1.6.0-win64msvc.dll";
#elif _WIN32
openh264 = "openh264-1.4.0-win32msvc.dll";
#endif
#if __x86_64__ || __ppc64__
#if __linux__
openh264 = "openh264-1.4.0-linux64.so";
#elif __APPLE__
openh264 = "openh264-1.4.0-osx64.dylib";
#endif
#else
#if __linux__
openh264 = "openh264-1.4.0-linux32.so";
#elif __APPLE__
openh264 = "openh264-1.4.0-osx32.dylib";
#endif
#endif
QString downloadURL = QString("http://ciscobinary.openh264.org/%1.bz2").arg(openh264);
gHasOpenH264 = QFileInfo(gExeDir + "/" + openh264).exists();
if (!gHasOpenH264 && cfg.showOpenH264Info) {
int ret = QMessageBox::information(this, "EyeRecToo Video Encoding Info",
QString("EyeRecToo favors using OpenH264 for video encoding.<br>")
+ QString("However, the user must download the library himself<br>")
+ QString("(why? <a href=\"%1\">%1</a>)<br><br>").arg("http://www.openh264.org/BINARY_LICENSE.txt")
+ QString("You can download it from<br><a href=\"%1\">%1</a><br> and unzip it at<br>%2<br>before continuing.<br>").arg(downloadURL).arg(gExeDir)
+ QString("Otherwise, defaulting to DivX.<br><br>")
+ QString("To disable OpenH264, simply delete<br>%1/%2").arg(gExeDir).arg(openh264)
+ QString("<br><br><br>%1").arg("OpenH264 Video Codec provided by Cisco Systems, Inc.<br><br><br>")
+ QString("Ok (always display this message) / Discard (never display this message)"),
QMessageBox::Ok,
QMessageBox::Discard);
if (ret == QMessageBox::Discard)
cfg.showOpenH264Info = false;
gHasOpenH264 = QFileInfo(gExeDir + "/" + openh264).exists();
}
qInfo() << "Video encoder:" << (gHasOpenH264 ? "OpenH264" : "DivX");
}
......@@ -17,8 +17,6 @@ char gDataNewline = '\n';
QMutex gLogMutex;
QFile gLogFile;
QTextStream gLogStream;
std::atomic<bool> gRecording(false);
bool gHasOpenH264 = false;
LogWidget *gLogWidget = NULL;
std::vector<QString> gLogBuffer;
......
......@@ -40,8 +40,6 @@ extern QString gExeDir;
extern QString gCfgDir;
extern char gDataSeparator;
extern char gDataNewline;
extern std::atomic<bool> gRecording;
extern bool gHasOpenH264;
extern QList<QPair<QString, QString> > gReferenceList;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment