added support for DivX (6.x and possibly 5.x) and x264 2-pass stats file to keyframe reader.

patch by Harukalover, see bugtracker issue #736.

Originally committed to SVN as r2244.
This commit is contained in:
Karl Blomster 2008-07-09 16:48:19 +00:00
parent 25ece3ab55
commit 46a6924531
3 changed files with 52 additions and 4 deletions

View file

@ -795,7 +795,7 @@ void FrameMain::OnCloseVFR(wxCommandEvent &event) {
void FrameMain::OnOpenKeyframes (wxCommandEvent &event) {
// Pick file
wxString path = Options.AsText(_T("Last open keyframes path"));
wxString filename = wxFileSelector(_T("Select the keyframes file to open"),path,_T(""),_T(".txt"),_T("All supported formats (*.txt, *.pass)|*.txt;*.pass|All files (*.*)|*.*"),wxFD_FILE_MUST_EXIST | wxFD_OPEN);
wxString filename = wxFileSelector(_T("Select the keyframes file to open"),path,_T(""),_T(".txt"),_T("All supported formats (*.txt, *.pass, *.log)|*.txt;*.pass;*.log|All files (*.*)|*.*"),wxFD_FILE_MUST_EXIST | wxFD_OPEN);
if (filename.IsEmpty()) return;
Options.SetText(_T("Last open keyframes path"),filename);
Options.Save();

View file

@ -55,10 +55,12 @@ void KeyFrameFile::Load(wxString filename) {
TextFileReader file(filename,_T("ASCII"));
wxString cur = file.ReadLineFromFile();
// Detect type
// Detect type (Only Xvid, DivX, x264 and Aegisub's keyframe files are currently supported)
if (cur == _T("# keyframe format v1")) { OpenAegiKeyFrames(file, keyFrames); }
else if (cur.StartsWith(_T("# XviD 2pass stat file"))) { OpenXviDKeyFrames(file, keyFrames); }
else { throw(_T("Invalid keyframes file.")); }
else if (cur.StartsWith(_T("##map version"))) { OpenDivXKeyFrames(file, keyFrames); }
else if (cur.StartsWith(_T("#options:"))) { Openx264KeyFrames(file, keyFrames); }
else { throw(_T("Invalid or unsupported keyframes file.")); }
// Set keyframes
VideoContext::Get()->SetOverKeyFrames(keyFrames);
@ -136,7 +138,7 @@ void KeyFrameFile::OpenAegiKeyFrames(TextFileReader& file, wxArrayInt& keyFrames
void KeyFrameFile::OpenXviDKeyFrames(TextFileReader& file, wxArrayInt& keyFrames)
{
wxString cur = file.ReadLineFromFile();
int count = 0;
unsigned int count = 0;
// Read lines
while (file.HasMoreLines()) {
@ -150,3 +152,47 @@ void KeyFrameFile::OpenXviDKeyFrames(TextFileReader& file, wxArrayInt& keyFrames
cur = file.ReadLineFromFile();
}
}
///////////////////
// DivX stats file
void KeyFrameFile::OpenDivXKeyFrames(TextFileReader& file, wxArrayInt& keyFrames)
{
wxString cur = file.ReadLineFromFile();
unsigned int count = 0;
// Read lines
while (file.HasMoreLines())
{
if (cur.Contains(_T("I"))) {
keyFrames.Add(count);
count++;
}
else if (cur.Contains(_T("P")) || cur.Contains(_T("B"))) {
count++;
}
cur = file.ReadLineFromFile();
}
}
///////////////////
// x264 stats file
void KeyFrameFile::Openx264KeyFrames(TextFileReader& file, wxArrayInt& keyFrames)
{
wxString cur = file.ReadLineFromFile();
unsigned int count = 0;
size_t pos;
// Read lines
while (file.HasMoreLines())
{
pos = cur.Find(_T("type:"));
if (cur.Mid(pos,6).Right(1).Lower() == (_T("i"))) {
keyFrames.Add(count);
count++;
}
else if (cur.Mid(pos,6).Right(1).Lower() == (_T("p")) || cur.Mid(pos,6).Right(1).Lower() == (_T("b"))) {
count++;
}
cur = file.ReadLineFromFile();
}
}

View file

@ -49,4 +49,6 @@ public:
private:
static void OpenAegiKeyFrames(TextFileReader& file, wxArrayInt& keyFrames);
static void OpenXviDKeyFrames(TextFileReader& file, wxArrayInt& keyFrames);
static void OpenDivXKeyFrames(TextFileReader& file, wxArrayInt& keyFrames);
static void Openx264KeyFrames(TextFileReader& file, wxArrayInt& keyFrames);
};