Work around for mkv2vfr files
Originally committed to SVN as r223.
This commit is contained in:
parent
bb037fc271
commit
ef779fb6db
1 changed files with 28 additions and 52 deletions
78
core/vfr.cpp
78
core/vfr.cpp
|
@ -36,11 +36,11 @@
|
||||||
|
|
||||||
///////////
|
///////////
|
||||||
// Headers
|
// Headers
|
||||||
|
#include <wx/filename.h>
|
||||||
#include "vfr.h"
|
#include "vfr.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include <wx/filename.h>
|
#include "text_file_reader.h"
|
||||||
#include <fstream>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// V2 Clear function
|
// V2 Clear function
|
||||||
|
@ -94,39 +94,32 @@ void FrameRate::Load(wxString filename) {
|
||||||
if (!filetest.FileExists()) throw _T("File not found.");
|
if (!filetest.FileExists()) throw _T("File not found.");
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
ifstream file;
|
TextFileReader file(filename);
|
||||||
file.open(filename.mb_str(wxConvLocal));
|
|
||||||
if (!file.is_open()) throw _T("Could not open file.");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Read header
|
// Read header
|
||||||
char buffer[65536];
|
wxString curLine;
|
||||||
file.getline(buffer,65536);
|
curLine = file.ReadLineFromFile();
|
||||||
wxString header(buffer,wxConvUTF8);
|
wxString header = curLine;
|
||||||
|
|
||||||
// V1, code converted from avcvfr9
|
// V1, code converted from avcvfr9
|
||||||
if (header == _T("# timecode format v1")) {
|
if (header == _T("# timecode format v1") || header.Left(7).Lower() == _T("assume ")) {
|
||||||
//locate the default fps line
|
// Locate the default fps line
|
||||||
|
do {
|
||||||
|
// Skip empty lines and comments
|
||||||
|
if (curLine == _T("") || curLine.Left(1) == _T("#")) continue;
|
||||||
|
|
||||||
while (!file.eof()) {
|
else if (curLine.Left(7).Lower() != _T("assume ")) throw _T("Encountered data before 'Assume <fps>' line");
|
||||||
file.getline(buffer,65536);
|
|
||||||
wxString curLine(buffer,wxConvUTF8);
|
|
||||||
|
|
||||||
//skip empty lines and comments
|
|
||||||
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
|
||||||
continue;
|
|
||||||
//fix me? should be case insensitive comparison
|
|
||||||
else if (curLine.Left(7) != _T("Assume "))
|
|
||||||
throw _T("Encountered data before 'Assume <fps>' line");
|
|
||||||
else {
|
else {
|
||||||
if (!curLine.Mid(6).ToDouble(&AverageFrameRate) || AverageFrameRate <= 0)
|
if (!curLine.Mid(6).ToDouble(&AverageFrameRate) || AverageFrameRate <= 0) throw _T("Invalid 'Assume <fps>' line");
|
||||||
throw _T("Invalid 'Assume <fps>' line");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//read and expand all timecodes to v2
|
// Get next line
|
||||||
|
curLine = file.ReadLineFromFile();
|
||||||
|
} while (file.HasMoreLines());
|
||||||
|
|
||||||
|
// Read and expand all timecodes to v2
|
||||||
wxString curline;
|
wxString curline;
|
||||||
|
|
||||||
double currenttime = 0;
|
double currenttime = 0;
|
||||||
|
@ -136,11 +129,10 @@ void FrameRate::Load(wxString filename) {
|
||||||
long lend;
|
long lend;
|
||||||
double lfps;
|
double lfps;
|
||||||
|
|
||||||
while (!file.eof()) {
|
while (file.HasMoreLines()) {
|
||||||
file.getline(buffer,65536);
|
curLine = file.ReadLineFromFile();
|
||||||
wxString curLine(buffer,wxConvUTF8);
|
|
||||||
|
|
||||||
//skip empty lines and comments
|
// Skip empty lines and comments
|
||||||
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -183,9 +175,8 @@ void FrameRate::Load(wxString filename) {
|
||||||
last_frame = 0;
|
last_frame = 0;
|
||||||
|
|
||||||
// Reads body
|
// Reads body
|
||||||
while (!file.eof()) {
|
while (file.HasMoreLines()) {
|
||||||
file.getline (buffer,65536);
|
curLine = file.ReadLineFromFile();
|
||||||
wxString curLine(buffer,wxConvUTF8);
|
|
||||||
|
|
||||||
//skip empty lines and comments
|
//skip empty lines and comments
|
||||||
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
if (curLine == _T("") || curLine.Left(1) == _T("#"))
|
||||||
|
@ -209,32 +200,17 @@ void FrameRate::Load(wxString filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown
|
// Unknown
|
||||||
else
|
else {
|
||||||
throw _T("Unknown file format.");
|
throw _T("Unknown file format.");
|
||||||
|
}
|
||||||
|
|
||||||
// Run test
|
|
||||||
/*bool doTest = false;
|
|
||||||
if (doTest) {
|
|
||||||
int fail = 0;
|
|
||||||
int res;
|
|
||||||
for (int i=0;i<1000;i++) {
|
|
||||||
res = GetFrameAtTime(GetTimeAtFrame(i));
|
|
||||||
if (res != i) {
|
|
||||||
wxLogMessage(wxString::Format(_T("Expected %i but got %i (%i)"),i,res,GetTimeAtFrame(i)));
|
|
||||||
fail++;
|
|
||||||
}
|
}
|
||||||
}
|
catch (...) {
|
||||||
if (fail) wxLogMessage(wxString::Format(_T("Failed %i times"),fail));
|
|
||||||
else wxLogMessage(_T("VFR passes test"));
|
|
||||||
}*/
|
|
||||||
} catch (wchar_t *) {
|
|
||||||
file.close();
|
|
||||||
Unload();
|
Unload();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close file
|
// Close file
|
||||||
file.close();
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
vfrFile = filename;
|
vfrFile = filename;
|
||||||
FrameRateType = VFR;
|
FrameRateType = VFR;
|
||||||
|
|
Loading…
Reference in a new issue