forked from mia/Aegisub
add a progress dialog to the ffmpegsource video provider's indexing process
Originally committed to SVN as r2318.
This commit is contained in:
parent
7fb0d975bd
commit
1655f97a59
2 changed files with 44 additions and 9 deletions
|
@ -39,9 +39,8 @@
|
||||||
// Headers
|
// Headers
|
||||||
#include "video_provider_ffmpegsource.h"
|
#include "video_provider_ffmpegsource.h"
|
||||||
#include <ffms.h>
|
#include <ffms.h>
|
||||||
#include "vfr.h"
|
|
||||||
#include "video_context.h"
|
#include "video_context.h"
|
||||||
#include "options.h" // for later use
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
@ -81,15 +80,25 @@ void FFmpegSourceVideoProvider::LoadVideo(Aegisub::String filename, double fps)
|
||||||
wxString CacheName(filename.c_str());
|
wxString CacheName(filename.c_str());
|
||||||
CacheName.append(_T(".ffindex"));
|
CacheName.append(_T(".ffindex"));
|
||||||
|
|
||||||
// initialize index object
|
FrameIndex *Index;
|
||||||
FrameIndex *Index = FFMS_CreateFrameIndex();
|
|
||||||
// try to read index (these index functions all return 0 on success)
|
// try to read index
|
||||||
if (FFMS_ReadIndex(CacheName.char_str(), Index, FFMSErrorMessage, MessageSize)) {
|
Index = FFMS_ReadIndex(CacheName.char_str(), FFMSErrorMessage, MessageSize);
|
||||||
|
if (Index == NULL) {
|
||||||
// reading failed, create index
|
// reading failed, create index
|
||||||
if (FFMS_MakeIndex(FileNameWX.char_str(), Index, 0, NULL, NULL, FFMSErrorMessage, MessageSize)) {
|
// prepare stuff for callback
|
||||||
|
IndexingProgressDialog Progress;
|
||||||
|
Progress.IndexingCanceled = false;
|
||||||
|
Progress.ProgressDialog = new DialogProgress(NULL, _("Indexing"), &Progress.IndexingCanceled, _("Reading keyframes and timecodes from video"), 0, 1);
|
||||||
|
Progress.ProgressDialog->Show();
|
||||||
|
Progress.ProgressDialog->SetProgress(0,1);
|
||||||
|
|
||||||
|
Index = FFMS_MakeIndex(FileNameWX.char_str(), 0, "", FFmpegSourceVideoProvider::UpdateIndexingProgress, &Progress, FFMSErrorMessage, MessageSize);
|
||||||
|
if (Index == NULL) {
|
||||||
ErrorMsg.Printf(_T("FFmpegSource video provider: %s"), FFMSErrorMessage);
|
ErrorMsg.Printf(_T("FFmpegSource video provider: %s"), FFMSErrorMessage);
|
||||||
throw ErrorMsg;
|
throw ErrorMsg;
|
||||||
}
|
}
|
||||||
|
Progress.ProgressDialog->Destroy();
|
||||||
// write it to disk
|
// write it to disk
|
||||||
if (FFMS_WriteIndex(CacheName.char_str(), Index, FFMSErrorMessage, MessageSize)) {
|
if (FFMS_WriteIndex(CacheName.char_str(), Index, FFMSErrorMessage, MessageSize)) {
|
||||||
ErrorMsg.Printf(_T("FFmpegSource video provider: %s"), FFMSErrorMessage);
|
ErrorMsg.Printf(_T("FFmpegSource video provider: %s"), FFMSErrorMessage);
|
||||||
|
@ -194,6 +203,20 @@ void FFmpegSourceVideoProvider::Close() {
|
||||||
FrameNumber = -1;
|
FrameNumber = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
// Update indexing progress
|
||||||
|
int __stdcall FFmpegSourceVideoProvider::UpdateIndexingProgress(int State, int64_t Current, int64_t Total, void *Private) {
|
||||||
|
IndexingProgressDialog *Progress = (IndexingProgressDialog *)Private;
|
||||||
|
Progress->ProgressDialog->SetProgress(int(Current), int(Total));
|
||||||
|
|
||||||
|
if (Progress->IndexingCanceled) {
|
||||||
|
// Close();
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Get frame
|
// Get frame
|
||||||
const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType) {
|
const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int _n, int FormatType) {
|
||||||
|
@ -289,4 +312,6 @@ double FFmpegSourceVideoProvider::GetFPS() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* WITH_FFMPEGSOURCE */
|
|
||||||
|
|
||||||
|
#endif /* WITH_FFMPEGSOURCE */
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
#include "include/aegisub/video_provider.h"
|
#include "include/aegisub/video_provider.h"
|
||||||
#include "include/aegisub/aegisub.h"
|
#include "include/aegisub/aegisub.h"
|
||||||
|
#include "dialog_progress.h"
|
||||||
|
#include "vfr.h"
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
#include <libavcodec/avcodec.h>
|
#include <libavcodec/avcodec.h>
|
||||||
|
@ -75,9 +77,16 @@ private:
|
||||||
unsigned MessageSize;
|
unsigned MessageSize;
|
||||||
wxString ErrorMsg;
|
wxString ErrorMsg;
|
||||||
|
|
||||||
|
struct IndexingProgressDialog {
|
||||||
|
volatile bool IndexingCanceled;
|
||||||
|
DialogProgress *ProgressDialog;
|
||||||
|
};
|
||||||
|
|
||||||
void LoadVideo(Aegisub::String filename, double fps);
|
void LoadVideo(Aegisub::String filename, double fps);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
|
static int __stdcall FFmpegSourceVideoProvider::UpdateIndexingProgress(int State, int64_t Current, int64_t Total, void *Private);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -108,4 +117,5 @@ public:
|
||||||
VideoProvider *CreateProvider(Aegisub::String video,double fps=0.0) { return new FFmpegSourceVideoProvider(video,fps); }
|
VideoProvider *CreateProvider(Aegisub::String video,double fps=0.0) { return new FFmpegSourceVideoProvider(video,fps); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WITH_FFMPEGSOURCE */
|
|
||||||
|
#endif /* WITH_FFMPEGSOURCE */
|
||||||
|
|
Loading…
Reference in a new issue