⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subtitlesmicrodvd.cpp

📁 VC++视频开发实例集锦(包括“远程视频监控”"语音识别系统"等13个经典例子)
💻 CPP
字号:
/**************************************************************************************
 *                                                                                    *
 *                                                                                    *
 **************************************************************************************/

#include "SubtitlesMicroDVD.h"



MediaSubtitlerMicroDVD::MediaSubtitlerMicroDVD()
{
	this->inputFile   = new MediaInput();
	this->inputBuffer = new MediaBuffer();
}

MediaSubtitlerMicroDVD::~MediaSubtitlerMicroDVD()
{
	delete this->inputFile;
	delete this->inputBuffer;
}

media_type_t  MediaSubtitlerMicroDVD::GetType()
{
	return MEDIA_TYPE_SUBTITLER;
}

char         *MediaSubtitlerMicroDVD::GetName()
{
	return "MicroDVD Subtitle Reader";
}

MP_RESULT     MediaSubtitlerMicroDVD::Connect(MediaItem *item)
{


	return MP_RESULT_OK;
}

MP_RESULT     MediaSubtitlerMicroDVD::ReleaseConnections()
{
	return MP_RESULT_OK;
}

DWORD         MediaSubtitlerMicroDVD::GetCaps()
{
	return 0;
}

MP_RESULT     MediaSubtitlerMicroDVD::Configure(HINSTANCE hInstance, HWND hwnd)
{
	return MP_RESULT_ERROR;
}



MP_RESULT MediaSubtitlerMicroDVD::ParseSubtitle()
{
	char text[512];
	DWORD i, j, count;

	if( sscanf((char *) this->inputBuffer->GetData(), "{%d}{%d}", &this->firstFrame, &this->lastFrame) != 2)
		return MP_RESULT_ERROR;



	strcpy(text, strrchr((char *) this->inputBuffer->GetData(), '}') + 1);
	


	i     = 0;
	count = 0;

	for(j=0; j < strlen(text); j++) {

		if(text[j] == '|') {

			this->subtitles.subtitlesText[i][count] = '\0';
			i++;
			count = 0;
		}
		else {

			if(text[j] == '\n') {

				this->subtitles.subtitlesText[i][count] = '\0';
				break;
			}
			else {

				this->subtitles.subtitlesText[i][count] = text[j];
				count++;
			}
		}
	}

	this->subtitles.nbSubtitles = i + 1;

	return MP_RESULT_OK;
}



MP_RESULT MediaSubtitlerMicroDVD::SeekToFrame(DWORD frameNumber)
{
	if(frameNumber > this->lastFrame) {



		do {

			this->inputFile->GetLine(this->inputBuffer);

			this->previousLastFrame = this->lastFrame;

			if(sscanf((char *) this->inputBuffer->GetData(), "{%d}{%d}", &this->firstFrame, &this->lastFrame) != 2) {

				return MP_RESULT_ERROR;
			}
		
		}
		while(this->firstFrame < frameNumber);

		this->ParseSubtitle();
	}
	else {


		this->inputFile->Seek(0, INPUT_SEEK_SET);

		this->firstFrame = 0;
		this->lastFrame  = 0;

		this->previousLastFrame = 0;

		SeekToFrame(frameNumber);
	}

	return MP_RESULT_OK;
}




MP_RESULT    MediaSubtitlerMicroDVD::Open(char *lpFilename)
{
	if(lpFilename) {

		this->firstFrame         = 0;
		this->lastFrame          = 0;
		this->firstSubtitleFrame = 0;
		this->previousLastFrame  = 0;

		if(this->inputFile->Open(lpFilename, INPUT_OPEN_ASCII) == MP_RESULT_OK) {


			
			this->inputBuffer->Alloc(SUB_INPUT_BUFFER_SIZE);

			this->subtitles.subtitlesText[0] = (char *) new char[256];
			this->subtitles.subtitlesText[1] = (char *) new char[256];
			this->subtitles.subtitlesText[2] = (char *) new char[256];
			this->subtitles.subtitlesText[3] = (char *) new char[256];
			this->subtitles.nbSubtitles = 0;

			this->inputFile->GetLine(this->inputBuffer);

			if(this->ParseSubtitle() == MP_RESULT_OK) {

				this->firstSubtitleFrame = this->firstFrame;
				this->previousLastFrame  = 0;


				return MP_RESULT_OK;
			}

		}
	}

	return MP_RESULT_ERROR;
}

subtitles_t *MediaSubtitlerMicroDVD::GetSubtitles(DWORD frameNumber)
{
	if(frameNumber < this->firstSubtitleFrame) {
	
		return NULL;
	}

	if(frameNumber < this->firstFrame && frameNumber > this->previousLastFrame) {

		return NULL;
	}

	if(frameNumber >= this->firstFrame && frameNumber < this->lastFrame) {



		return &this->subtitles;
	}
	else {
	


		this->SeekToFrame(frameNumber);
		
		return NULL;
	}

	return NULL;
}

MP_RESULT    MediaSubtitlerMicroDVD::Close()
{
	if(this->inputFile) {
	
		this->inputFile->Close();
	}

	return MP_RESULT_ERROR;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -