Ejemplo n.º 1
0
static LPVOID AVIFILE_ReadFrame(IAVIEditStreamImpl* const This,
                                PAVISTREAM pstream, LONG pos)
{
  PGETFRAME pg;

  TRACE("(%p,%p,%d)\n",This,pstream,pos);

  if (pstream == NULL)
    return NULL;

  /* if stream changes make sure that only palette changes */
  if (This->pCurStream != pstream) {
    pg = AVIStreamGetFrameOpen(pstream, NULL);
    if (pg == NULL)
      return NULL;
    if (This->pg != NULL) {
      if (IGetFrame_SetFormat(pg, This->lpFrame, NULL, 0, 0, -1, -1) != S_OK) {
        AVIStreamGetFrameClose(pg);
        ERR(": IGetFrame_SetFormat failed\n");
        return NULL;
      }
      AVIStreamGetFrameClose(This->pg);
    }
    This->pg         = pg;
    This->pCurStream = pstream;
  }

  /* now get the decompressed frame */
  This->lpFrame = AVIStreamGetFrame(This->pg, pos);
  if (This->lpFrame != NULL)
    This->sInfo.dwSuggestedBufferSize = This->lpFrame->biSizeImage;

  return This->lpFrame;
}
Ejemplo n.º 2
0
bool CvCaptureAVI_VFW::open( const char* filename )
{
    close();
    icvInitCapture_VFW();

    if( !filename )
        return false;

    HRESULT hr = AVIFileOpen( &avifile, filename, OF_READ, NULL );
    if( SUCCEEDED(hr))
    {
        hr = AVIFileGetStream( avifile, &avistream, streamtypeVIDEO, 0 );
        if( SUCCEEDED(hr))
        {
            hr = AVIStreamInfo( avistream, &aviinfo, sizeof(aviinfo));
            if( SUCCEEDED(hr))
            {
                size.width = aviinfo.rcFrame.right - aviinfo.rcFrame.left;
                size.height = aviinfo.rcFrame.bottom - aviinfo.rcFrame.top;
                BITMAPINFOHEADER bmihdr = icvBitmapHeader( size.width, size.height, 24 );

                film_range.start_index = (int)aviinfo.dwStart;
                film_range.end_index = film_range.start_index + (int)aviinfo.dwLength;
                fps = (double)aviinfo.dwRate/aviinfo.dwScale;
                pos = film_range.start_index;
                getframe = AVIStreamGetFrameOpen( avistream, &bmihdr );
                if( getframe != 0 )
                    return true;
            }
        }
    }

    close();
    return false;
}
Ejemplo n.º 3
0
int AVIOBJ::OpenAVI(LPCSTR szFile)										// Opens An AVI File (szFile)
{

    AVIFileInit();												// Opens The AVIFile Library
    pgf=NULL;

    if (AVIStreamOpenFromFile(&pavi, szFile, streamtypeVIDEO, 0, OF_READ, NULL) !=0)
        return(0);

    AVIStreamInfo(pavi, &psi, sizeof(psi));						// Reads Information About The Stream Into psi
    width=psi.rcFrame.right-psi.rcFrame.left;					// Width Is Right Side Of Frame Minus Left
    height=psi.rcFrame.bottom-psi.rcFrame.top;					// Height Is Bottom Of Frame Minus Top

    lastframe=AVIStreamLength(pavi);							// The Last Frame Of The Stream

    mpf=AVIStreamSampleToTime(pavi,lastframe)/lastframe;		// Calculate Rough Milliseconds Per Frame

    bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
    bmih.biPlanes = 1;											// Bitplanes
    bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
    bmih.biWidth = width;											// Width We Want
    bmih.biHeight = height;										// Height We Want
    bmih.biCompression = BI_RGB;								// Requested Mode = RGB

    hBitmap = CreateDIBSection (hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, 0);
    SelectObject (hdc, hBitmap);								// Select hBitmap Into Our Device Context (hdc)

    pgf=AVIStreamGetFrameOpen(pavi, NULL);						// Create The PGETFRAME	Using Our Request Mode
    if (pgf==NULL) return(0);

    return(1);
}
Ejemplo n.º 4
0
bool AVI :: Load(std :: string fname,bool loopflag,Texture *tex)				// Opens An AVI File
{
	// copy over looping flag
	loop=loopflag;

	// do we have a texture manager?
	if(!tex)
		return false;
	// copy it over
	tman=tex;

	hdc=CreateCompatibleDC(0);									// Get a compatible DC
	hdd = DrawDibOpen();										// Grab A Device Context For Our Dib


	AVIFileInit();												// Opens The AVIFile Library

	// Opens The AVI Stream
	if (AVIStreamOpenFromFile(&pavi, fname.c_str(), streamtypeVIDEO, 0, OF_READ, NULL) !=0)
		return false;

	AVIStreamInfo(pavi, &psi, sizeof(psi));						// Reads Information About The Stream Into psi
	width=psi.rcFrame.right-psi.rcFrame.left;					// Width Is Right Side Of Frame Minus Left
	height=psi.rcFrame.bottom-psi.rcFrame.top;					// Height Is Bottom Of Frame Minus Top

	lastframe=AVIStreamLength(pavi);							// The Last Frame Of The Stream

	mpf=AVIStreamSampleToTime(pavi,lastframe)/lastframe;		// Calculate Rough Milliseconds Per Frame

	bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	bmih.biPlanes = 1;											// Bitplanes	
	bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
	bmih.biWidth = 256;											// Width We Want (256 Pixels)
	bmih.biHeight = 256;										// Height We Want (256 Pixels)
	bmih.biCompression = BI_RGB;								// Requested Mode = RGB

	hBitmap = CreateDIBSection (hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, NULL);
	SelectObject (hdc, hBitmap);								// Select hBitmap Into Our Device Context (hdc)

	pgf=AVIStreamGetFrameOpen(pavi, NULL);						// Create The PGETFRAME	Using Our Request Mode
	if (pgf==NULL)
		return false;

	// create the texture
	Image img;
	img.Create(256,256,false);									// set dimensions of texture
	img.SetImage(data);											// set the texture information
	texid=tman->Create(&img);									// create the texture

	// clear the time position 
	pos=0;

	// success
	return true;
}
		bool AviFrameGraber::_Open(void){
			//thread_handle_ !=NULL means it is already opened
			if (thread_handle_!=NULL)	return false;

			int res=AVIFileOpen(&avi_file_, file_path_.c_str(), OF_READ, NULL);
			if (res!=AVIERR_OK){
				woodychang0611::diagnostics::SendError(_T("AviFrameGraber Open File Fail"));
				_Close();
				return false;
			}
			res=AVIFileGetStream(avi_file_, &stream_, streamtypeVIDEO, 0/*first stream*/);
			if (res!=AVIERR_OK){
				woodychang0611::diagnostics::SendError(_T("AviFrameGraber Get Stream Fail"));
				_Close();
				return false;
			}
			if (AVIStreamStart(stream_)==-1 || AVIStreamLength(stream_)==-1){
				woodychang0611::diagnostics::SendError(_T("AviFrameGraber Stream Start or Length no correct"));
				_Close();
				return false;								
			}
			AVIFileInfo(avi_file_, &avi_info_, sizeof(AVIFILEINFO));
			BITMAPINFOHEADER bih;
			bih.biSize = sizeof(BITMAPINFOHEADER);
			bih.biWidth = avi_info_.dwWidth;
			bih.biHeight = avi_info_.dwHeight;
			bih.biPlanes = 1;
			bih.biBitCount = 24;
			bih.biCompression = BI_RGB;
			bih.biSizeImage = 0;
			bih.biXPelsPerMeter = 0;
			bih.biYPelsPerMeter = 0;
			bih.biClrUsed = 0;
			bih.biClrImportant = 0;
			frame_=AVIStreamGetFrameOpen(stream_, (LPBITMAPINFOHEADER) &bih);
			if (frame_ !=NULL){
				start_frame_ = AVIStreamStart(stream_);
				frame_length_ = AVIStreamLength(stream_);
				current_frame_ = start_frame_;

				//Set Frame info
				frame_info_.start_frame_=start_frame_;
				frame_info_.frame_length_ =frame_length_; 
				frame_info_.frame_per_second_=(FLOAT32)avi_info_.dwRate/avi_info_.dwScale;
				frame_info_.frame_width_=(UINT16) avi_info_.dwWidth;
				frame_info_.frame_height_=(UINT16)  avi_info_.dwHeight;
				_status = FRAME_SUBJECT_PAUSE;
				thread_handle_ =CreateThread(NULL ,0,this->_ThreadFunc,this,0,NULL);
				return true;
			}else{
				woodychang0611::diagnostics::SendError(_T("AviFrameGraber Get Frame Failed"));
			}
			return false;
		}
Ejemplo n.º 6
0
bool AVIDump::Start(HWND hWnd, int w, int h)
{
	s_emu_wnd = hWnd;
	s_file_count = 0;

	s_width = w;
	s_height = h;

	s_last_frame = CoreTiming::GetTicks();

	if (SConfig::GetInstance().m_SYSCONF->GetData<u8>("IPL.E60"))
		s_frame_rate = 60; // always 60, for either pal60 or ntsc
	else
		s_frame_rate = VideoInterface::TargetRefreshRate; // 50 or 60, depending on region

	// clear CFR frame cache on start, not on file create (which is also segment switch)
	SetBitmapFormat();
	StoreFrame(nullptr);

	//Dragonbane: Setup file reading if last side
	bool lastSide = false;

	if (Movie::cmp_isRunning)
	{
		if (Movie::cmp_leftFinished || Movie::cmp_rightFinished)
			lastSide = true;

		if (lastSide)
		{
			tempFileCount = 0;
			s_stopTempFile = false;
			std::string movie_file_name = GetCurrDumpFile(tempFileCount, true);

			if (File::Exists(movie_file_name) && Movie::cmp_startTimerFrame > Movie::cmp_curentBranchFrame) //Dragonbane: Open temp file for reading
			{
				HRESULT h2 = AVIFileOpenA(&s_file_temp, movie_file_name.c_str(), OF_READ, nullptr);
				HRESULT h3 = AVIFileGetStream(s_file_temp, &s_stream_temp, streamtypeVIDEO, 0);

				s_last_key_temp = 1; //Skip first key frame as its always black

				s_getFrame_temp = AVIStreamGetFrameOpen(s_stream_temp, &s_bitmap);

				if (!s_getFrame_temp)
				{
					PanicAlertT("Your chosen compression codec can not be decompressed again! Can't create video comparison!");
					Movie::CancelComparison();
				}
			}
		}
	}

	return CreateFile();
}
Ejemplo n.º 7
0
/*
---------------------------------------------------------------------------------------
- Opens An AVI File (szFile)
---------------------------------------------------------------------------------------
*/
bool AviVideoRenderer::OpenAVI(const char * szFile)
{
	// Opens The AVI Stream
	if (AVIStreamOpenFromFileA(&_AVR_pavi, szFile, streamtypeVIDEO, 0, OF_READ, NULL) !=0)
		return false;

	AVIStreamInfo(_AVR_pavi, &_AVR_psi, sizeof(_AVR_psi));						// Reads Information About The Stream Into psi
	_video_width=_AVR_psi.rcFrame.right-_AVR_psi.rcFrame.left;					// Width Is Right Side Of Frame Minus Left
	_video_height=_AVR_psi.rcFrame.bottom-_AVR_psi.rcFrame.top;					// Height Is Bottom Of Frame Minus Top

	_endFrame=AVIStreamLength(_AVR_pavi);							// The Last Frame Of The Stream

	_timeperframe=AVIStreamSampleToTime(_AVR_pavi,_endFrame)/_endFrame;		// Calculate Rough Milliseconds Per Frame


	int sizet = 1024;
	if((_video_width < 128) && (_video_height < 128))
		sizet = 128;
	else if((_video_width < 256) && (_video_height < 256))
		sizet = 256;
	else if((_video_width < 512) && (_video_height < 512))
		sizet = 512;

	_widths.push_back(sizet);
	_heights.push_back(sizet);

	// initialize the host texture
	InitializeTexture();


	_AVR_bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	_AVR_bmih.biPlanes = 1;											// Bitplanes
	_AVR_bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
	_AVR_bmih.biWidth = _widths[0];									// Width We Want
	_AVR_bmih.biHeight = _heights[0];								// Height We Want
	_AVR_bmih.biCompression = BI_RGB;								// Requested Mode = RGB

	_AVR_hBitmap = CreateDIBSection (_AVR_hdc, (BITMAPINFO*)(&_AVR_bmih), DIB_RGB_COLORS, (void**)(&_img_data), NULL, NULL);
	SelectObject (_AVR_hdc, _AVR_hBitmap);							// Select hBitmap Into Our Device Context (hdc)

	_AVR_pgf=AVIStreamGetFrameOpen(_AVR_pavi, NULL);				// Create The PGETFRAME	Using Our Request Mode


	_avi_opened = true;

	return(_AVR_pgf!=NULL);
}
/***********************************************************************
 *      AVIStreamGetFrameOpen   (AVIFILE.112)
 */
PGETFRAME WINAPI AVIStreamGetFrameOpen16(PAVISTREAM pstream, LPBITMAPINFOHEADER lpbiWanted)
{
    struct frame_wrapper16 *wrapper;
    PGETFRAME pg;

    pg = AVIStreamGetFrameOpen(pstream, lpbiWanted);
    if (!pg) return NULL;

    wrapper = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wrapper));
    if (!wrapper)
    {
        AVIStreamGetFrameClose(pg);
        return NULL;
    }

    wrapper->pg = pg;
    return (PGETFRAME)wrapper;
}
Ejemplo n.º 9
0
bool CAviLoader::open( const char* filename )
{
    close();
    icvInitCapture_VFW();

    if( !filename )
        return false;

    HRESULT hr = AVIFileOpen( &avifile, filename, OF_READ, NULL );
    if( SUCCEEDED(hr))
    {
        hr = AVIFileGetStream( avifile, &avistream, streamtypeVIDEO, 0 );
        if( SUCCEEDED(hr))
        {
            hr = AVIStreamInfo( avistream, &aviinfo, sizeof(aviinfo));
            if( SUCCEEDED(hr))
            {
                //int fcc = aviinfo.fccHandler;
                data_offset = 0;
                size.width = aviinfo.rcFrame.right - aviinfo.rcFrame.left;
                size.height = aviinfo.rcFrame.bottom - aviinfo.rcFrame.top;
                BITMAPINFOHEADER bmih = icvBitmapHeader( size.width, size.height, 24 );

				if(frame)
					delete []frame;
				frame = new unsigned char[size.width*size.height*3];
                
                film_range.start_index = (int)aviinfo.dwStart;
                film_range.end_index = film_range.start_index + (int)aviinfo.dwLength;
                fps = (double)aviinfo.dwRate/aviinfo.dwScale;
                pos = film_range.start_index;
                getframe = AVIStreamGetFrameOpen( avistream, &bmih );
                if( getframe != 0 )
                    return true;
            }
        }
    }

    close();
    return false;
}
Ejemplo n.º 10
0
Archivo: AVI.cpp Proyecto: DCubix/1.4.0
bool CAvi::OpenAVI( LPCWSTR szFile )
{
	AVISTREAMINFO psi;
	AVIFileInit();
	if( AVIStreamOpenFromFile( &m_pavi, szFile, streamtypeVIDEO, 0, OF_READ, NULL) !=0)
	{
		MessageBox( NULL, _T("Couldnt open the CAvi stream."), _T("VandaEngine Error"), MB_OK | MB_ICONERROR );
		return 0;
	}
	AVIStreamInfo(m_pavi, &psi, sizeof(psi));				// Reads Information About The Stream Into psi
	m_width=psi.rcFrame.right-psi.rcFrame.left;			// Width Is Right Side Of Frame Minus Left
	m_height=psi.rcFrame.bottom-psi.rcFrame.top;			// Height Is Bottom Of Frame Minus Top
	m_lastFrame = AVIStreamLength(m_pavi);	
	m_mpf=AVIStreamSampleToTime(m_pavi,m_lastFrame)/m_lastFrame;		// Calculate Rough Milliseconds Per Frame
	if( m_mpf == 0 )
	{
		MessageBox( NULL, _T("MPF is 0"), _T("VandaEngine Error"), MB_OK | MB_ICONINFORMATION );
		return 0;
	}

    BITMAPINFOHEADER bmih;
	bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	bmih.biPlanes = 1;											// Bitplanes	
	bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
	bmih.biWidth = 1024;											// Width We Want (512 Pixels)
	bmih.biHeight = 512;										// Height We Want (256 Pixels)
	bmih.biCompression = BI_RGB;								// Requested Mode = RGB

	m_hBitmap = CreateDIBSection (m_hDC, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&m_data), NULL, NULL);
	SelectObject (m_hDC, m_hBitmap);		// Select m_hBitmap Into Our Device Context (hdc)

	m_pgf=AVIStreamGetFrameOpen(m_pavi, NULL);	// Create The PGETFRAME	Using Our Request Mode
	if (m_pgf==NULL)
	{
		//An Error Occurred Opening The Frame
		MessageBox( NULL, _T("Couldn't open the CAvi frame."), _T("VandaEngine Error"), MB_OK | MB_ICONINFORMATION );
		return 0;
	}
	return 1;
}
Ejemplo n.º 11
0
bool CAviToBmp::Open(LPCTSTR Path)
{
	Close();
	if (FAILED(m_hr = AVIFileOpen(&m_pFile, Path, OF_READ, NULL)))
		return(FALSE);
	if (FAILED(m_hr = AVIFileGetStream(m_pFile, &m_pStream, streamtypeVIDEO, 0)))
		return(FALSE);
	m_FrameCount = AVIStreamLength(m_pStream);
	long	Start = AVIStreamStart(m_pStream);
	if (Start < 0)
		return(FALSE);
	long	FmtSize;
 	if (FAILED(m_hr = AVIStreamReadFormat(m_pStream, Start, NULL, &FmtSize)))
		return(FALSE);
	m_pBmpInfo = (LPBITMAPINFO)new BYTE[FmtSize];
	if (FAILED(m_hr = AVIStreamReadFormat(m_pStream, Start, m_pBmpInfo, &FmtSize)))
		return(FALSE);
	m_pGetFrame = AVIStreamGetFrameOpen(m_pStream, (LPBITMAPINFOHEADER)AVIGETFRAMEF_BESTDISPLAYFMT);
	if (m_pGetFrame == NULL)
		return(FALSE);
	return(TRUE);
}
Ejemplo n.º 12
0
bool Movie::reload(const io::stringc &Filename, const s32 Resolution)
{
    if (DataPointer_)
        close();
    
    /* Information message */
    io::Log::message("Load movie: \"" + Filename + "\"");
    io::Log::upperTab();
    
    /* General settings */
    SMovieSequencePacket* MovieData = new SMovieSequencePacket;
    
    DataPointer_                = MovieData;
    
    MovieData->Next             = MovieData->Frame      = 0;
    MovieData->State            = MOVIESTATE_STOPED;
    MovieData->Time             = MovieData->LastTime   = 0;
    MovieData->RawData          = 0;
    MovieData->Resolution       = Resolution;
    
    MovieData->hDeviceContext   = CreateCompatibleDC(0);
    MovieData->hDrawDIB         = DrawDibOpen();
    
    AVIFileInit();
    
    /* Open video stream */
    if (AVIStreamOpenFromFile(&MovieData->pVideoStream, Filename.c_str(), streamtypeVIDEO, 0, OF_READ, 0) != 0)
        return exitWithError("Could not open video stream");
    if (AVIStreamInfo(MovieData->pVideoStream, &MovieData->VideoStreamInfo, sizeof(MovieData->VideoStreamInfo)) != 0)
        return exitWithError("Video stream information process failed");
    
    MovieData->VideoLastFrame = AVIStreamLength(MovieData->pVideoStream);
    
    if (MovieData->VideoLastFrame == -1)
        return exitWithError("Video stream length is invalid");
    
    MovieData->VideoMPF = AVIStreamSampleToTime(MovieData->pVideoStream, MovieData->VideoLastFrame) / MovieData->VideoLastFrame;
    
    if (MovieData->VideoMPF == -1)
        return exitWithError("Video stream sample is invalid");
    
    #if 0
    
    /* Open audio stream */
    if (AVIStreamOpenFromFile(&MovieData->pAudioStream, Filename.c_str(), streamtypeAUDIO, 0, OF_READ, 0))
        return exitWithError("Could not open audio stream");
    if (AVIStreamInfo(MovieData->pAudioStream, &MovieData->AudioStreamInfo, sizeof(MovieData->AudioStreamInfo)))
        return exitWithError("Audio stream information process failed");
    
    MovieData->AudioLastFrame = AVIStreamLength(MovieData->pAudioStream);
    
    if (MovieData->AudioLastFrame == -1)
        return exitWithError("Audio stream length is invalid");
    
    MovieData->AudioMPF = AVIStreamSampleToTime(MovieData->pAudioStream, MovieData->AudioLastFrame) / MovieData->AudioLastFrame;
    
    if (MovieData->AudioMPF == -1)
        return exitWithError("Audio stream sample is invalid");
    
    #endif
    
    /* Start configuration process */
    MovieData->Size.Width   = MovieData->VideoStreamInfo.rcFrame.right  - MovieData->VideoStreamInfo.rcFrame.left;
    MovieData->Size.Height  = MovieData->VideoStreamInfo.rcFrame.bottom - MovieData->VideoStreamInfo.rcFrame.top;
    
    MovieData->BitmapInfoHeader.biSize          = sizeof(BITMAPINFOHEADER);
    MovieData->BitmapInfoHeader.biPlanes        = 1;
    MovieData->BitmapInfoHeader.biBitCount      = 24;
    MovieData->BitmapInfoHeader.biWidth         = MovieData->Resolution;
    MovieData->BitmapInfoHeader.biHeight        = MovieData->Resolution;
    MovieData->BitmapInfoHeader.biCompression   = BI_RGB;
    
    /* Create the movie bitmap context */
    MovieData->hBitmap = CreateDIBSection(
        MovieData->hDeviceContext,
        (BITMAPINFO*)(&MovieData->BitmapInfoHeader),
        DIB_RGB_COLORS,
        (void**)(&MovieData->RawData),
        0, 0
    );

    if (!MovieData->hBitmap)
        return exitWithError("Could not create device independent bitmap (DIB) for video stream");
    
    SelectObject(MovieData->hDeviceContext, MovieData->hBitmap);
    
    MovieData->BitmapInfoHeader.biWidth         = MovieData->Size.Width;
    MovieData->BitmapInfoHeader.biHeight        = MovieData->Size.Height;
    MovieData->BitmapInfoHeader.biSizeImage     = 0;
    MovieData->BitmapInfoHeader.biClrUsed       = 0;
    MovieData->BitmapInfoHeader.biClrImportant  = 0;
    
    /* Get first video frame */
    MovieData->pGetFrame = AVIStreamGetFrameOpen(MovieData->pVideoStream, &MovieData->BitmapInfoHeader);
    
    if (!MovieData->pGetFrame)
        return exitWithError("Could not open first video stream");
    
    io::Log::lowerTab();
    
    return true;
}
Ejemplo n.º 13
0
static FIMULTIBITMAP* ReadFromAvi(const char* filename) {
	int err=0;
	AVIFileInit();
	
	PAVISTREAM pavi; // Handle To An Open Stream
	if( AVIStreamOpenFromFile(&pavi, filename, streamtypeVIDEO, 0, OF_READ, NULL) != 0) {
		AVIFileExit();
		return NULL;
	}



	AVISTREAMINFO		psi;				// Pointer To A Structure Containing Stream Info
	AVIStreamInfo(pavi, &psi, sizeof(psi));				// Reads Information About The Stream Into psi
	int width  = psi.rcFrame.right-psi.rcFrame.left;			// Width Is Right Side Of Frame Minus Left
	int height = psi.rcFrame.bottom-psi.rcFrame.top;			// Height Is Bottom Of Frame Minus Top
	int frameCount = AVIStreamLength(pavi);							// The Last Frame Of The Stream

	double mpf = AVIStreamSampleToTime(pavi, frameCount) / (double)frameCount;		// Calculate Rough Milliseconds Per Frame

	PGETFRAME pgf = AVIStreamGetFrameOpen(pavi, NULL);				// Create The PGETFRAME Using Our Request Mode
	if (pgf==NULL)
	{
		// An Error Occurred Opening The Frame
		error("Failed To Open frame from AVI");
	}

	//HDC hdc = GetDC(0);

	HDRAWDIB hdd = DrawDibOpen();													// Handle For Our Dib

	BITMAPINFOHEADER bmih;										// Header Information For DrawDibDraw Decoding
	bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	bmih.biPlanes = 1;											// Bitplanes	
	bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
	bmih.biWidth = width;										// Width We Want (256 Pixels)
	bmih.biHeight = height;										// Height We Want (256 Pixels)
	bmih.biCompression = BI_RGB;								// Requested Mode = RGB

	char		*data;						// Pointer To Texture Data
	HBITMAP hBitmap = CreateDIBSection(hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, NULL);
	SelectObject(hdc, hBitmap);								// Select hBitmap Into Our Device Context (hdc)

	// create a new freeimage anim
	someError=false;
	FIMULTIBITMAP* ret = FreeImage_OpenMultiBitmap(FIF_TIFF, "temp.tiff", TRUE, FALSE);
	if (!ret || someError) {
		error("Couldnt create multibitmap");
	}

	for (int frame=0; frame<frameCount; frame++) {
		fprintf(stderr, "Loading frame %i\n", frame);
		// Grab Data From The AVI Stream
		LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);	
		// Pointer To Data Returned By AVIStreamGetFrame
		// (Skip The Header Info To Get To The Data)
		char* pdata = (char *)lpbi + lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD);	
		
		// Convert Data To Requested Bitmap Format
		DrawDibDraw(hdd, hdc, 0, 0, width, height, lpbi, pdata, 0, 0, width, height, 0);

		// copy into the freeimage thing
		FIBITMAP* fiBitmap = FreeImage_ConvertFromRawBits((BYTE*)data, width, height, width*3, 24, 0xFF0000, 0x00FF00, 0x0000FF);
/*		BYTE* src = (BYTE*)data;
		for (int y=0; y<height; y++) {
			BYTE* dst = FreeImage_GetScanLine(fiBitmap, y);
			for (int x=0; x<width; x++) {
				//src++;
				*dst++ = *src++;
				*dst++ = *src++;
				*dst++ = *src++;
			}
		}
*/
		FIBITMAP* grayBitmap = FreeImage_ConvertToGreyscale(fiBitmap);
		FreeImage_Unload(fiBitmap);

		FreeImage_AppendPage(ret, grayBitmap);
	}
	FreeImage_CloseMultiBitmap(ret);
	ret = FreeImage_OpenMultiBitmap(FIF_TIFF, "temp.tiff", FALSE, TRUE);

	DeleteObject(hBitmap);										// Delete The Device Dependant Bitmap Object
	DrawDibClose(hdd);											// Closes The DrawDib Device Context
	AVIStreamGetFrameClose(pgf);								// Deallocates The GetFrame Resources
	AVIStreamRelease(pavi);										// Release The Stream
	AVIFileExit();												// Release The File

	return ret;
}
Ejemplo n.º 14
0
  int load_avi_file()
  {
    bitm.valid=false;
    const char *avifilename = filename->get().c_str();
    HRESULT res = AVIFileOpen(&m_aviFile, avifilename, OF_READ, NULL);
    if (res!=AVIERR_OK)
    {
      printf("Couldn't open avi file %s\n",filename->get().c_str());
      return 0;
    }

    res = AVIFileGetStream(m_aviFile, &streamVid, streamtypeVIDEO, 0);
    if (res!=AVIERR_OK)
    {
      AVIFileRelease(m_aviFile);
      m_aviFile = NULL;
      streamVid = NULL;
      printf("Couldn't get stream");
      return 0;
    }

    LONG format_length = 0;

    AVIStreamReadFormat(streamVid,0,NULL,&format_length);

    //if format_data is not a reasonable size, fail
    if (format_length>128)
    {
      printf("Format data too big");
      return 0;
    }
    //make room for at least 128 bytes, sizeof(int) aligned
    int format_data[(128/sizeof(int)) + 1];

    AVIStreamReadFormat(streamVid,0,format_data,&format_length);
        
    BITMAPINFOHEADER *bi = (BITMAPINFOHEADER *)format_data;

    //only 24 bit output is supported
    if (bi->biBitCount!=24)
    {
      printf("Bitcount %d not supported",bi->biBitCount);
      return 0;
    }
    
    // Create the PGETFRAME
    getFrame = AVIStreamGetFrameOpen(streamVid,NULL);
	
    //unable to decode the .avi?
    if (getFrame==NULL)
    {
      printf("AVIStreamGetFrameOpen returned NULL");
      return 0;
    }
        
    // Define the length of the video (necessary for loop reading)
		// and its size.
		num_frames = AVIStreamLength(streamVid);
      
    if (num_frames<1)
    {
      printf("Zero frames");
      return 0;
    }
    
    AVISTREAMINFO psi;
    AVIStreamInfo(streamVid, &psi, sizeof(AVISTREAMINFO));

    width  = psi.rcFrame.right - psi.rcFrame.left;
		height = psi.rcFrame.bottom - psi.rcFrame.top;

    dwRate = psi.dwRate;
    dwScale = psi.dwScale;

    bitm.bpp=(int)(bi->biBitCount/8);
    bitm.bformat=GL_BGR;
    bitm.size_x=width;
    bitm.size_y=height;
    bitm.valid=true;

    return 1;
  }
Ejemplo n.º 15
0
void AVIDump::StoreFrame(const void* data)
{
	if (s_bitmap.biSizeImage > s_stored_frame_size)
	{
		void* temp_stored_frame = realloc(s_stored_frame, s_bitmap.biSizeImage);
		if (temp_stored_frame)
		{
			s_stored_frame = temp_stored_frame;
		}
		else
		{
			free(s_stored_frame);
			PanicAlertT("Something has gone seriously wrong.\n"
			            "Stopping video recording.\n"
			            "Your video will likely be broken.");
			Stop();
		}
		s_stored_frame_size = s_bitmap.biSizeImage;
		memset(s_stored_frame, 0, s_bitmap.biSizeImage);
	}
	if (s_stored_frame)
	{
		//PanicAlertT("Width: %i, Height: %i, Bit Count: %i", s_bitmap.biWidth, s_bitmap.biHeight, s_bitmap.biBitCount);

		if (data && (s_file_count || !Movie::cmp_isRunning || s_frame_count > 0))
		{
			bool lastSide = false, readOnly = false;

			if (Movie::cmp_isRunning && (Movie::cmp_leftFinished || Movie::cmp_rightFinished))
				lastSide = true;

			if (lastSide && Movie::cmp_startTimerFrame > Movie::cmp_curentBranchFrame) //Dragonbane: Combine frames
				readOnly = true;
			else
				readOnly = false;


			if (readOnly && s_getFrame_temp)
			{
				size_t totalBytes = s_bitmap.biSizeImage / 2;
				size_t rowSize = (s_bitmap.biWidth * (s_bitmap.biBitCount / 8)) / 2;
				size_t currentByte = 0;

				if (s_last_key_temp < 2)
				{
					BOOL result = AVIStreamIsKeyFrame(s_stream_temp, s_last_key_temp);

					if (!result)
						s_last_key_temp = AVIStreamNextKeyFrame(s_stream_temp, s_last_key_temp);
				}

				u64 samplePos = AVIStreamFindSample(s_stream_temp, s_last_key_temp, FIND_ANY);

				u64 s_last_key_old = s_last_key_temp;

				s_last_key_temp = AVIStreamNextKeyFrame(s_stream_temp, s_last_key_temp);

				void* s_uncompressed_frame = AVIStreamGetFrame(s_getFrame_temp, samplePos);
				std::string movie_file_name;

				if (!s_uncompressed_frame || s_stopTempFile)
				{
					//Close current file
					if (s_getFrame_temp)
					{
						AVIStreamGetFrameClose(s_getFrame_temp);
						s_getFrame_temp = nullptr;
					}

					if (s_stream_temp)
					{
						AVIStreamClose(s_stream_temp);
						s_stream_temp = nullptr;
					}

					if (s_file_temp)
					{
						AVIFileRelease(s_file_temp);
						s_file_temp = nullptr;

						movie_file_name = GetCurrDumpFile(tempFileCount, true);

						if (File::Exists(movie_file_name))
							File::Delete(movie_file_name);
					}

					//Check if we have another temp file
					tempFileCount++;
					s_stopTempFile = false;

					movie_file_name = GetCurrDumpFile(tempFileCount, true);

					if (File::Exists(movie_file_name)) //Dragonbane: Open temp file for reading
					{
						HRESULT h2 = AVIFileOpenA(&s_file_temp, movie_file_name.c_str(), OF_READ, nullptr);
						HRESULT h3 = AVIFileGetStream(s_file_temp, &s_stream_temp, streamtypeVIDEO, 0);

						s_last_key_temp = 0; //Not the first file anymore, so start from keyframe 0

						s_getFrame_temp = AVIStreamGetFrameOpen(s_stream_temp, &s_bitmap);

						if (!s_getFrame_temp)
						{
							PanicAlertT("Your chosen compression codec can not be decompressed again! Can't continue video comparison!");
							Movie::CancelComparison();
							return;
						}

						BOOL result = AVIStreamIsKeyFrame(s_stream_temp, s_last_key_temp);

						if (!result)
							s_last_key_temp = AVIStreamNextKeyFrame(s_stream_temp, s_last_key_temp);

						samplePos = AVIStreamFindSample(s_stream_temp, s_last_key_temp, FIND_ANY);

						s_last_key_old = s_last_key_temp;

						s_last_key_temp = AVIStreamNextKeyFrame(s_stream_temp, s_last_key_temp);

						s_uncompressed_frame = AVIStreamGetFrame(s_getFrame_temp, samplePos);

						if (!s_uncompressed_frame)
						{
							//PanicAlertT("Last frame stored. Start timer now!");
							Movie::cmp_startTimerFrame = Movie::cmp_curentBranchFrame;
							memcpy(s_stored_frame, data, s_bitmap.biSizeImage);
							return;
						}
					}
					else
					{
						//PanicAlertT("Last frame stored. Start timer now!");
						Movie::cmp_startTimerFrame = Movie::cmp_curentBranchFrame;
						memcpy(s_stored_frame, data, s_bitmap.biSizeImage);
						return;
					}
				}

				//Stop temp file on next frame if last frame is processed
				if (s_last_key_old == s_last_key_temp || AVIStreamFindSample(s_stream_temp, s_last_key_temp, FIND_ANY) == samplePos)
					s_stopTempFile = true;


				void* memptr1 = s_uncompressed_frame;
				memptr1 = static_cast<u8*>(memptr1) + sizeof(BITMAPINFOHEADER);

				if (Movie::cmp_leftFinished)
				{
					memcpy(s_stored_frame, memptr1, s_bitmap.biSizeImage);

					for (u64 currentRow = 0; currentRow < s_bitmap.biHeight; currentRow++)
					{
						currentByte += rowSize;

						void* memptr = s_stored_frame;
						const void* memptr2 = data;

						memptr = static_cast<u8*>(memptr) + currentByte;
						memptr2 = static_cast<const u8*>(memptr2) + currentByte;

						memcpy(memptr, memptr2, rowSize);

						currentByte += rowSize;
					}
				}
				else if (Movie::cmp_rightFinished)
				{
					memcpy(s_stored_frame, memptr1, s_bitmap.biSizeImage);

					//BITMAPINFOHEADER test;
					//memset(&test, 0, sizeof(BITMAPINFOHEADER));
					//memcpy(&test, s_uncompressed_frame, sizeof(BITMAPINFOHEADER));

					for (u64 currentRow = 0; currentRow < s_bitmap.biHeight; currentRow++)
					{
						void* memptr = s_stored_frame;
						const void* memptr2 = data;

						memptr = static_cast<u8*>(memptr) + currentByte;
						memptr2 = static_cast<const u8*>(memptr2) + currentByte;

						memcpy(memptr, memptr2, rowSize);

						currentByte += rowSize * 2;
					}
				}
				else
				{
					memcpy(s_stored_frame, data, s_bitmap.biSizeImage);
				}
			}
			else
			{
				memcpy(s_stored_frame, data, s_bitmap.biSizeImage);
			}
		}
		else // pitch black frame
		{
			memset(s_stored_frame, 0, s_bitmap.biSizeImage);
		}
	}
}
Ejemplo n.º 16
0
static HRESULT AVIFILE_OpenGetFrame(IAVIStreamImpl *This)
{
  LPBITMAPINFOHEADER lpbi;
  DWORD              size;

  /* pre-conditions */
  assert(This != NULL);
  assert(This->pStream != NULL);
  assert(This->pg == NULL);

  This->pg = AVIStreamGetFrameOpen(This->pStream, NULL);
  if (This->pg == NULL)
    return AVIERR_ERROR;

  /* When we only decompress this is enough */
  if (This->sInfo.fccHandler == comptypeDIB)
    return AVIERR_OK;

  assert(This->hic != NULL);
  assert(This->lpbiOutput == NULL);

  /* get input format */
  lpbi = AVIStreamGetFrame(This->pg, This->sInfo.dwStart);
  if (lpbi == NULL)
    return AVIERR_MEMORY;

  /* get memory for output format */
  size = ICCompressGetFormatSize(This->hic, lpbi);
  if ((LONG)size < (LONG)sizeof(BITMAPINFOHEADER))
    return AVIERR_COMPRESSOR;
  This->lpbiOutput = HeapAlloc(GetProcessHeap(), 0, size);
  if (This->lpbiOutput == NULL)
    return AVIERR_MEMORY;
  This->cbOutput = size;

  if (ICCompressGetFormat(This->hic, lpbi, This->lpbiOutput) < S_OK)
    return AVIERR_BADFORMAT;

  /* update AVISTREAMINFO structure */
  This->sInfo.rcFrame.right  =
    This->sInfo.rcFrame.left + This->lpbiOutput->biWidth;
  This->sInfo.rcFrame.bottom =
    This->sInfo.rcFrame.top  + This->lpbiOutput->biHeight;
  This->sInfo.dwSuggestedBufferSize =
    ICCompressGetSize(This->hic, lpbi, This->lpbiOutput);

  /* prepare codec for compression */
  if (ICCompressBegin(This->hic, lpbi, This->lpbiOutput) != S_OK)
    return AVIERR_COMPRESSOR;

  /* allocate memory for current frame */
  size += This->sInfo.dwSuggestedBufferSize;
  This->lpbiCur = HeapAlloc(GetProcessHeap(), 0, size);
  if (This->lpbiCur == NULL)
    return AVIERR_MEMORY;
  memcpy(This->lpbiCur, This->lpbiOutput, This->cbOutput);
  This->lpCur = DIBPTR(This->lpbiCur);

  /* allocate memory for last frame if needed */
  if (This->lKeyFrameEvery != 1 &&
      (This->dwICMFlags & VIDCF_FASTTEMPORALC) == 0) {
    size = ICDecompressGetFormatSize(This->hic, This->lpbiOutput);
    This->lpbiPrev = HeapAlloc(GetProcessHeap(), 0, size);
    if (This->lpbiPrev == NULL)
      return AVIERR_MEMORY;
    if (ICDecompressGetFormat(This->hic, This->lpbiOutput, This->lpbiPrev) < S_OK)
      return AVIERR_COMPRESSOR;

    if (This->lpbiPrev->biSizeImage == 0) {
      This->lpbiPrev->biSizeImage =
	DIBWIDTHBYTES(*This->lpbiPrev) * This->lpbiPrev->biHeight;
    }

    /* get memory for format and picture */
    size += This->lpbiPrev->biSizeImage;
    This->lpbiPrev = HeapReAlloc(GetProcessHeap(), 0, This->lpbiPrev, size );
    if (This->lpbiPrev == NULL)
      return AVIERR_MEMORY;
    This->lpPrev = DIBPTR(This->lpbiPrev);

    /* prepare codec also for decompression */
    if (ICDecompressBegin(This->hic,This->lpbiOutput,This->lpbiPrev) != S_OK)
      return AVIERR_COMPRESSOR;
  }

  return AVIERR_OK;
}
Ejemplo n.º 17
0
bool VideoComponent::openAvi(const std::string& filename)
{
	// Stop any currently loaded avi
	closeAvi();

	AVIFileInit();							// Opens The AVIFile Library
	// Opens The AVI Stream
	if (AVIStreamOpenFromFile(&m_pavi, filename.c_str(), streamtypeVIDEO, 0, OF_READ, NULL) !=0)
	{
		GameLog::errorMessage("Error opening avi: %s", filename.c_str());
		// An Error Occurred Opening The Stream
		AVIFileExit();								// Release The File
		return false;
	}
	AVIStreamInfo(m_pavi, &m_psi, sizeof(m_psi));						// Reads Information About The Stream Into psi
	m_width = m_psi.rcFrame.right-m_psi.rcFrame.left;					// Width Is Right Side Of Frame Minus Left
	m_height = m_psi.rcFrame.bottom-m_psi.rcFrame.top;					// Height Is Bottom Of Frame Minus Top
	if (!m_resize)
	{
		// Size should be kept
		m_resizeWidth = m_width;
		m_resizeHeight = m_height;
	}
	m_lastframe = AVIStreamLength(m_pavi);								// The Last Frame Of The Stream
	m_timePerFrame = ((float)AVIStreamSampleToTime(m_pavi, m_lastframe) / (float) m_lastframe) / 1000.0f;	// Calculate Rough Seconds Per Frame
	m_bmih.biSize		= sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	m_bmih.biPlanes		= 1;					// Bitplanes
	m_bmih.biBitCount	= 24;					// Bits Format We Want 24 / 8  = 3 bytes
	m_bmih.biWidth		= m_resizeWidth;		// Width We Want
	m_bmih.biHeight		= m_resizeHeight;		// Height We Want
	m_bmih.biCompression= BI_RGB;				// Requested Mode = RGB
	m_hBitmap = CreateDIBSection (m_hdc, (BITMAPINFO*)(&m_bmih), DIB_RGB_COLORS, (void**)(&m_data), NULL, NULL);	
	SelectObject (m_hdc, m_hBitmap);					// Select hBitmap Into Our Device Context (hdc)
	// Bitmapinfo header for decoding (needed for xvid)
	m_bmiavih.biSize = sizeof(BITMAPINFOHEADER);
	m_bmiavih.biPlanes			= 1;					// Bitplanes
	m_bmiavih.biBitCount		= 24;					// Bits Format We Want 24 / 8  = 3 bytes
	m_bmiavih.biWidth			= m_width;				// Width We Want
	m_bmiavih.biHeight			= m_height;				// Height We Want
	m_bmiavih.biCompression		= BI_RGB;				// Requested Mode = RGB
	// And some more infos
	m_bmiavih.biClrImportant	= 0;
	m_bmiavih.biClrUsed			= 0;
	m_bmiavih.biXPelsPerMeter	= 0;
	m_bmiavih.biYPelsPerMeter	= 0;
	m_bmiavih.biSizeImage = (((m_bmiavih.biWidth * 3) + 3) & 0xFFFC) * m_bmiavih.biHeight;
	m_pgf=AVIStreamGetFrameOpen(m_pavi, &m_bmiavih);// Create The PGETFRAME Using Our Request Mode
	if (m_pgf==0x0)
	{
		GameLog::errorMessage("Error opening first frame of avi: %s", filename.c_str());
		// An Error Occurred Opening The Frame
		DeleteObject(m_hBitmap);					// Delete The Device Dependant Bitmap Object
		AVIStreamRelease(m_pavi);					// Release The Stream
		AVIFileExit();								// Release The File
		return false;
	}
	m_fileName = filename;

	// Create buffer for converted data
	// width*height = count pixel; each pixel has 4 channels for rgba with each one byte
	int dataSize = 4*m_resizeWidth*m_resizeHeight;
	m_bgraData = new unsigned char[dataSize];
	// Initialize with 255 (black screen with full alpha)
	memset(m_bgraData, 255, dataSize);

	// Prepare horde texture stream named like the video file name, to get a unique name
	m_videoTexture = h3dCreateTexture(filename.c_str(), m_resizeWidth, m_resizeHeight, H3DFormats::TEX_BGRA8, H3DResFlags::NoTexMipmaps);
	if (m_videoTexture == 0)
	{
		GameLog::errorMessage("Error creating texture for playing avi: %s", filename.c_str());
		// Failure creating the dynamic texture
		closeAvi();
		return false;
	}

	// Find the sampler index within the material
	m_samplerIndex = h3dFindResElem(m_material, H3DMatRes::SamplerElem, H3DMatRes::SampNameStr, "albedoMap");	
	if (m_samplerIndex == -1)
	{
		GameLog::errorMessage("Error preparing material with resID %d for playing avi: %s", m_material, filename.c_str());
		// No sampler found in material
		closeAvi();
		return false;
	}

	// Store old sampler
	m_originalSampler = h3dGetResParamI(m_material, H3DMatRes::SamplerElem, m_samplerIndex, H3DMatRes::SampTexResI);

	
	// Now open the audio stream
	PAVISTREAM audioStream;
	if (AVIStreamOpenFromFile(&audioStream, filename.c_str(), streamtypeAUDIO, 0, OF_READ, NULL) == 0)
	{
		// Audio stream found
		// Get format info
		PCMWAVEFORMAT audioFormat;
		long formatSize = sizeof(audioFormat);
		int start = AVIStreamStart(audioStream);
		// TODO get channelsmask and use it
		AVIStreamReadFormat(audioStream, start, &audioFormat, &formatSize);
		long numSamples = AVIStreamLength(audioStream);
		int bitsPerSample = (audioFormat.wf.nAvgBytesPerSec * 8) / (audioFormat.wf.nSamplesPerSec * audioFormat.wf.nChannels);
		/*if (audioFormat.wf.wFormatTag == WAVE_FORMAT_MPEGLAYER3)
		{
			// TODO
			MPEGLAYER3WAVEFORMAT mp3Format;
			formatSize = sizeof(mp3Format);
			AVIStreamReadFormat(audioStream, start, &mp3Format, &formatSize);
		}*/

		// Create buffer with appropriate size
		long bufferSize = (bitsPerSample * numSamples) / 8;
		char* buffer = new char[bufferSize];
		// Read the audio data
		long bytesWritten = 0;
		AVIStreamRead(audioStream, start, numSamples, buffer, bufferSize, &bytesWritten, 0x0);

		if (bytesWritten > 0)
		{
			// Send the audio data to the sound component
			SoundResourceData eventData(buffer, bytesWritten, audioFormat.wf.nSamplesPerSec, bitsPerSample, audioFormat.wf.nChannels);
			GameEvent event(GameEvent::E_SET_SOUND_WITH_USER_DATA, &eventData, this);
			m_owner->executeEvent(&event);
			m_hasAudio = true;
		}

		// Delete the buffer data
		delete[] buffer;
	}

	if (m_autoStart)
		// Play video directly
		playAvi();

	return true;
}
Ejemplo n.º 18
0
HRESULT CAviBitmap::Init()
{
	HRESULT hr = E_FAIL;
	
	do 
	{
		//Open file
		hr = AVIFileOpen(&m_pAviFile, m_szFileName, OF_READ, NULL);
		if(hr != S_OK)
		{
			m_szLastErrorMsg.Format(_T("Unable to Open the Movie File"));
			break;
		}

		//Get video stream
		hr = AVIFileGetStream(m_pAviFile, &m_pAviStream, streamtypeVIDEO /*video stream*/, 0 /*first stream*/);
		if(hr != S_OK)
		{
			m_szLastErrorMsg.Format(_T("Unable to Get the video stream"));
			break;
		}

		hr = AVIStreamInfo(m_pAviStream, &m_aviInfo, sizeof(AVISTREAMINFO));
		if(hr != S_OK)
		{
			m_szLastErrorMsg.Format(_T("Unable to Get the video stream info"));
			break;
		}
		CString szFourCC;
		FourCC2Str(m_aviInfo.fccHandler, szFourCC);
		AfxTrace(_T("fccHandler=%s, 0x%08X\n"), szFourCC, m_aviInfo.fccHandler);

		ZeroMemory(&m_biWanted, sizeof(m_biWanted));
		LONG lFormat = sizeof(m_biWanted);

		hr = AVIStreamReadFormat(m_pAviStream, 0, &m_biWanted, &lFormat);
		if(hr != S_OK)
		{
			m_szLastErrorMsg.Format(_T("Unable to Get the foramt of the 1st frame"));
			break;
		}
		m_biWanted.biCompression = BI_RGB;
		m_biWanted.biBitCount = 32;
		m_biWanted.biSizeImage = m_biWanted.biWidth * 4 * m_biWanted.biHeight;

		//Set the result to Fail
		hr = E_FAIL;

		//Get the GETFRAME handle
		m_pGetFrame = AVIStreamGetFrameOpen(m_pAviStream, &m_biWanted);
		if(m_pGetFrame == NULL)
		{
			m_szLastErrorMsg.Format(_T("Unable to Get the GETFRAME handle"));
			break;
		}

		//Get the 1st sample
		m_lFirstSample = AVIStreamStart(m_pAviStream);
		if(m_lFirstSample == -1)
		{
			m_szLastErrorMsg.Format(_T("Unable to Get the first sample"));
			break;
		}

		//Get the total sample count
		m_lSampleCount = AVIStreamLength(m_pAviStream);
		if(m_lSampleCount == -1)
		{
			m_szLastErrorMsg.Format(_T("Unable to Get the sample count"));
			break;
		}

		//Done
		hr = S_OK;

	} while (FALSE);
	
	if(hr != S_OK)
	{
		ReleaseMemory();
	}

	return hr;
}
Ejemplo n.º 19
0
	/////////////////////////////////////////////////////////
	//open avi file. preapre avi streams
	/////////////////////////////////////////////////////////
	CAviMan::OpenAviFile(LPTSTR szFileName)
	{
		LONG hr;

	    hr = AVIFileOpen(&m_aviFile, szFileName, 0, 0L);			//open AVI file

		if(hr!=0)
		{
			return 1;
		}

		PAVISTREAM	aviStream;

		//
		// Get all the streams from the new file
		//
		for (DWORD i = 0; i <= MAX_AVI_STREAM; i++)
		{
			if (AVIFileGetStream(m_aviFile, &aviStream, 0L, i) != AVIERR_OK)
			break;

			if (i == MAX_AVI_STREAM) {
				AVIStreamRelease(aviStream);
				break;
			}

			m_aviStream[i] = aviStream;				//save all streams
		}


		m_dwNumStreams = i;					//save real number of streams

		//
		// Couldn't get any streams out of this file
		//
		if (i == 0 && i != MAX_AVI_STREAM)
		{
	   //   ErrMsg(TEXT("Unable to open %s"), lpszFile);
			if (m_aviFile)
				AVIFileRelease(m_aviFile);
			return 1;
		}



		AVISTREAMINFO     aviStreamInfo;


		m_aviVideoStream = NULL;

		//
		// Walk through and init all streams loaded
		//
		for (i = 0; i < m_dwNumStreams; i++)
		{

			AVIStreamInfo(m_aviStream[i], &aviStreamInfo, sizeof(aviStreamInfo));

			//
			// Initialize video streams for getting decompressed frames to display
			//
			if (aviStreamInfo.fccType == streamtypeVIDEO) 
			{

		
				if (m_aviVideoStream == NULL) 
				{

					m_dwScale=aviStreamInfo.dwScale;
					m_dwRate =aviStreamInfo.dwRate;

					//
					// Remember the first video stream --- treat it specially
					//
					m_aviVideoStream = m_aviStream[i];

					m_aviGetFrame = AVIStreamGetFrameOpen(m_aviStream[i], NULL);

				}

			}//if aviStreamInfo==streamVideo 

		}//for i=0..dwNumStreams


		m_dwCurrentFrame = 0;
		m_dwStartFrame = 0;
		m_dwTotalFrame  = 0;

		return 0;

	}
Ejemplo n.º 20
0
static int startavi(struct anim *anim)
{

	AviError avierror;
#if defined(_WIN32) && !defined(FREE_WINDOWS)
	HRESULT hr;
	int i, firstvideo = -1;
	int streamcount;
	BYTE abFormat[1024];
	LONG l;
	LPBITMAPINFOHEADER lpbi;
	AVISTREAMINFO avis;

	streamcount = anim->streamindex;
#endif

	anim->avi = MEM_callocN(sizeof(AviMovie), "animavi");

	if (anim->avi == NULL) {
		printf("Can't open avi: %s\n", anim->name);
		return -1;
	}

	avierror = AVI_open_movie(anim->name, anim->avi);

#if defined(_WIN32) && !defined(FREE_WINDOWS)
	if (avierror == AVI_ERROR_COMPRESSION) {
		AVIFileInit();
		hr = AVIFileOpen(&anim->pfile, anim->name, OF_READ, 0L);
		if (hr == 0) {
			anim->pfileopen = 1;
			for (i = 0; i < MAXNUMSTREAMS; i++) {
				if (AVIFileGetStream(anim->pfile, &anim->pavi[i], 0L, i) != AVIERR_OK) {
					break;
				}
				
				AVIStreamInfo(anim->pavi[i], &avis, sizeof(avis));
				if ((avis.fccType == streamtypeVIDEO) && (firstvideo == -1)) {
					if (streamcount > 0) {
						streamcount--;
						continue;
					}
					anim->pgf = AVIStreamGetFrameOpen(anim->pavi[i], NULL);
					if (anim->pgf) {
						firstvideo = i;

						/* get stream length */
						anim->avi->header->TotalFrames = AVIStreamLength(anim->pavi[i]);

						/* get information about images inside the stream */
						l = sizeof(abFormat);
						AVIStreamReadFormat(anim->pavi[i], 0, &abFormat, &l);
						lpbi = (LPBITMAPINFOHEADER)abFormat;
						anim->avi->header->Height = lpbi->biHeight;
						anim->avi->header->Width = lpbi->biWidth;
					}
					else {
						FIXCC(avis.fccHandler);
						FIXCC(avis.fccType);
						printf("Can't find AVI decoder for type : %4.4hs/%4.4hs\n",
						       (LPSTR)&avis.fccType,
						       (LPSTR)&avis.fccHandler);
					}
				}
			}

			/* register number of opened avistreams */
			anim->avistreams = i;

			/*
			 * Couldn't get any video streams out of this file
			 */
			if ((anim->avistreams == 0) || (firstvideo == -1)) {
				avierror = AVI_ERROR_FORMAT;
			}
			else {
				avierror = AVI_ERROR_NONE;
				anim->firstvideo = firstvideo;
			}
		}
		else {
			AVIFileExit();
		}
	}
#endif

	if (avierror != AVI_ERROR_NONE) {
		AVI_print_error(avierror);
		printf("Error loading avi: %s\n", anim->name);
		free_anim_avi(anim);
		return -1;
	}
	
	anim->duration = anim->avi->header->TotalFrames;
	anim->params = NULL;

	anim->x = anim->avi->header->Width;
	anim->y = anim->avi->header->Height;
	anim->interlacing = 0;
	anim->orientation = 0;
	anim->framesize = anim->x * anim->y * 4;

	anim->curposition = 0;
	anim->preseek = 0;

	/*  printf("x:%d y:%d size:%d interl:%d dur:%d\n", anim->x, anim->y, anim->framesize, anim->interlacing, anim->duration);*/

	return 0;
}
Ejemplo n.º 21
0
int imFileFormatAVI::ReadImageInfo(int index)
{
  this->current_frame = index;

  if (this->frame)       // frame reading already prepared
    return IM_ERR_NONE;

  /* get stream format */
  LONG formsize;
  AVIStreamReadFormat(stream, 0, NULL, &formsize);
  BITMAPINFO *bmpinfo = (BITMAPINFO*)malloc(formsize);
  HRESULT hr = AVIStreamReadFormat(stream, 0, bmpinfo, &formsize);
  if (hr != 0)
  {
    free(bmpinfo);
    return IM_ERR_ACCESS;
  }

  int top_down = 0;
  if (bmpinfo->bmiHeader.biHeight < 0)
    top_down = 1;

  this->width = bmpinfo->bmiHeader.biWidth;
  this->height = top_down? -bmpinfo->bmiHeader.biHeight: bmpinfo->bmiHeader.biHeight;

  int bpp = bmpinfo->bmiHeader.biBitCount;

  imAttribTable* attrib_table = AttribTable();
  attrib_table->Set("FPS", IM_FLOAT, 1, &fps);

  this->file_data_type = IM_BYTE;

  if (bpp > 8)
  {
    this->file_color_mode = IM_RGB;
    this->file_color_mode |= IM_PACKED;
  }
  else
  {
    this->palette_count = 1 << bpp;
    this->file_color_mode = IM_MAP;
  }

  if (bpp < 8)
    this->convert_bpp = bpp;

  if (bpp == 32)
    this->file_color_mode |= IM_ALPHA;

  if (top_down)
    this->file_color_mode |= IM_TOPDOWN;

  if (bpp <= 8)
  {
    /* updates the palette_count based on the number of colors used */
    if (bmpinfo->bmiHeader.biClrUsed != 0 && 
        (int)bmpinfo->bmiHeader.biClrUsed < this->palette_count)
      this->palette_count = bmpinfo->bmiHeader.biClrUsed;

    ReadPalette((unsigned char*)bmpinfo->bmiColors);
  }

  free(bmpinfo);

  this->line_buffer_extra = 4; // room enough for padding

  /* prepares to read data from the stream */
  if (bpp == 32 || bpp == 16)
  {
    BITMAPINFOHEADER info;
    memset(&info, 0, sizeof(BITMAPINFOHEADER));
    info.biSize = sizeof(BITMAPINFOHEADER);
    info.biWidth = width;
    info.biHeight = height;
    info.biPlanes = 1;
    info.biBitCount = (WORD)bpp;
    frame = AVIStreamGetFrameOpen(stream, &info);
  }
  else
    frame = AVIStreamGetFrameOpen(stream, NULL);

  if (!frame)
    return IM_ERR_ACCESS;

  return IM_ERR_NONE;
}
Ejemplo n.º 22
0
void CAviHelper::AVItoBmp(const wstring& strAVIFileName, const wstring& strBmpDir)
{
	AVIFileInit();
	PAVIFILE avi;
	int res = AVIFileOpen(&avi, WS2S(strAVIFileName).c_str(), OF_READ, NULL);
	int n = GetLastError();
	if (res!=AVIERR_OK)
	{
		//an error occures
		if (avi!=NULL)
			AVIFileRelease(avi);
		return ;
	}
	
	AVIFILEINFO avi_info;
	AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO));
	PAVISTREAM pStream;
	res=AVIFileGetStream(avi, &pStream, streamtypeVIDEO /*video stream*/, 0 /*first stream*/);
	if (res!=AVIERR_OK)
	{
		if (pStream!=NULL)
			AVIStreamRelease(pStream);
		AVIFileExit();
		return ;
	}
	
	//do some task with the stream
	int iNumFrames;
	int iFirstFrame;
	iFirstFrame = AVIStreamStart(pStream);
	if (iFirstFrame==-1)
	{
		//Error getteing the frame inside the stream
		if (pStream!=NULL)
			AVIStreamRelease(pStream);
		AVIFileExit();
		return ;
	}
	
	iNumFrames = AVIStreamLength(pStream);
	if (iNumFrames==-1)
	{
		//Error getteing the number of frames inside the stream
		if (pStream!=NULL)
			AVIStreamRelease(pStream);
		AVIFileExit();
		return ;
	}
	
	//getting bitmap from frame
	BITMAPINFOHEADER bih;
	ZeroMemory(&bih, sizeof(BITMAPINFOHEADER));
	bih.biBitCount=24; //24 bit per pixel
	bih.biClrImportant=0;
	bih.biClrUsed = 0;
	bih.biCompression = BI_RGB;
	bih.biPlanes = 1;
	bih.biSize = 40;
	bih.biXPelsPerMeter = 0;
	bih.biYPelsPerMeter = 0;
	
	//calculate total size of RGBQUAD scanlines (DWORD aligned)
	bih.biSizeImage = (((bih.biWidth * 3) + 3) & 0xFFFC) * bih.biHeight ;
	PGETFRAME pFrame;
	pFrame=AVIStreamGetFrameOpen(pStream, NULL );
	AVISTREAMINFO streaminfo;
	AVIStreamInfo(pStream,&streaminfo,sizeof(AVISTREAMINFO));
	
	//Get the first frame
	BITMAPINFOHEADER bih2;
	long lsize = sizeof(bih2);
	int index= 0;
	for (int i = iFirstFrame; i < iNumFrames; i++)
	{
		index= i-iFirstFrame;
		BYTE* pDIB = (BYTE*) AVIStreamGetFrame(pFrame, index); //
		AVIStreamReadFormat(pStream,index,&bih2,&lsize);
		BITMAPFILEHEADER stFileHdr;
		BYTE* Bits=new BYTE[bih2.biSizeImage];
		AVIStreamRead(pStream,index,1,Bits,bih2.biSizeImage,NULL,NULL);
		//RtlMoveMemory(Bits, pDIB + sizeof(BITMAPINFOHEADER), bih2.biSizeImage);
		bih2.biClrUsed =0;
		stFileHdr.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
		stFileHdr.bfSize=sizeof(BITMAPFILEHEADER);
		stFileHdr.bfType=0x4d42; 
		CString FileName;
		FileName.Format(_T("Frame-%05d.bmp"), index);
		CString strtemp;
		strtemp.Format(_T("%s\\%s"), strBmpDir.c_str(), FileName);
		FILE* fp=_tfopen(strtemp ,_T("wb"));
		fwrite(&stFileHdr,1,sizeof(BITMAPFILEHEADER),fp);
		fwrite(&bih2,1,sizeof(BITMAPINFOHEADER),fp);
		int ff = fwrite(Bits,1,bih2.biSizeImage,fp);
		int e = GetLastError();
		fclose(fp);
		/////
		delete Bits;
		//CreateFromPackedDIBPointer(pDIB, index);
	}
	
	AVIStreamGetFrameClose(pFrame);
	//close the stream after finishing the task
	if (pStream!=NULL)
		AVIStreamRelease(pStream);
	AVIFileExit();
}
Ejemplo n.º 23
0
BOOL ExtractAVIFrames(CString szFileName)
{
	AVIFileInit();

	PAVIFILE avi;
	int res = AVIFileOpen(&avi, szFileName, OF_READ, NULL);

	if (res != AVIERR_OK)
	{
		//an error occures
		if (avi != NULL)
			AVIFileRelease(avi);

		return FALSE;
	}

	AVIFILEINFO avi_info;
	AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO));

	CString szFileInfo;
	szFileInfo.Format("Dimention: %dx%d\n"
		"Length: %d frames\n"
		"Max bytes per second: %d\n"
		"Samples per second: %d\n"
		"Streams: %d\n"
		"File Type: %d", avi_info.dwWidth,
		avi_info.dwHeight,
		avi_info.dwLength,
		avi_info.dwMaxBytesPerSec,
		(DWORD)(avi_info.dwRate / avi_info.dwScale),
		avi_info.dwStreams,
		avi_info.szFileType);

	AfxMessageBox(szFileInfo, MB_ICONINFORMATION | MB_OK);

	PAVISTREAM pStream;
	res = AVIFileGetStream(avi, &pStream, streamtypeVIDEO /*video stream*/,
		0 /*first stream*/);

	if (res != AVIERR_OK)
	{
		if (pStream != NULL)
			AVIStreamRelease(pStream);

		AVIFileExit();
		return FALSE;
	}

	//do some task with the stream
	int iNumFrames;
	int iFirstFrame;

	iFirstFrame = AVIStreamStart(pStream);
	if (iFirstFrame == -1)
	{
		//Error getteing the frame inside the stream

		if (pStream != NULL)
			AVIStreamRelease(pStream);

		AVIFileExit();
		return FALSE;
	}

	iNumFrames = AVIStreamLength(pStream);
	if (iNumFrames == -1)
	{
		//Error getteing the number of frames inside the stream

		if (pStream != NULL)
			AVIStreamRelease(pStream);

		AVIFileExit();
		return FALSE;
	}

	//getting bitmap from frame
	BITMAPINFOHEADER bih;
	ZeroMemory(&bih, sizeof(BITMAPINFOHEADER));

	bih.biBitCount = 24;    //24 bit per pixel
	bih.biClrImportant = 0;
	bih.biClrUsed = 0;
	bih.biCompression = BI_RGB;
	bih.biPlanes = 1;
	bih.biSize = 40;
	bih.biXPelsPerMeter = 0;
	bih.biYPelsPerMeter = 0;
	//calculate total size of RGBQUAD scanlines (DWORD aligned)
	bih.biSizeImage = (((bih.biWidth * 3) + 3) & 0xFFFC) * bih.biHeight;

	PGETFRAME pFrame;
	pFrame = AVIStreamGetFrameOpen(pStream,
		NULL/*(BITMAPINFOHEADER*) AVIGETFRAMEF_BESTDISPLAYFMT*/ /*&bih*/);

	//Get the first frame
	int index = 0;
	for (int i = iFirstFrame; i<iNumFrames; i++)
	{
		index = i - iFirstFrame;

		BYTE* pDIB = (BYTE*)AVIStreamGetFrame(pFrame, index);

		CreateFromPackedDIBPointer(pDIB, index);
	}

	AVIStreamGetFrameClose(pFrame);

	//close the stream after finishing the task
	if (pStream != NULL)
		AVIStreamRelease(pStream);

	AVIFileExit();

	return TRUE;
}
Ejemplo n.º 24
0
bool CLoaderAVI::loadFromFile(const CString& fileName)
{
    CApplication::getApp()->log(CString::fromUTF8("Chargement de la vidéo %1").arg(fileName));

#ifdef T_SYSTEM_WINDOWS
    AVIStreamGetFrameClose(m_pgf);

    // Suppression des flux
    if (m_video)
        AVIStreamRelease(m_video);

    if (m_audio)
    {
        //AVIStreamRelease(m_audio);
        Game::soundEngine->removeMusic(m_audio);
        delete m_audio;
        m_audio = nullptr;
    }

    Game::textureManager->deleteTexture(m_texture);
    AVIFileExit();
#endif

    m_time = 0;
    m_play = false;

    // Suppression de la précédente texture
    if (m_texture)
    {
        Game::textureManager->deleteTexture(m_texture);
    }

#ifdef T_SYSTEM_WINDOWS

    AVIFileInit();

    // Ouverture du flux vidéo
    if (AVIStreamOpenFromFile(&m_video, fileName.toCharArray(), streamtypeVIDEO, 0, OF_READ, nullptr))
    {
        CApplication::getApp()->log(CString::fromUTF8("AVIStreamOpenFromFile : impossible de lire le flux video."), ILogger::Error);
        return false;
    }

    // Infos sur le stream video
    AVISTREAMINFO psi;

    if (AVIStreamInfo(m_video, &psi, sizeof(psi)))
    {
        CApplication::getApp()->log("AVIStreamInfo donne une erreur", ILogger::Error);
        return false;
    }

    // Dimensions de la vidéo
    m_width = psi.rcFrame.right - psi.rcFrame.left;
    m_height = psi.rcFrame.bottom - psi.rcFrame.top;

    m_fileName = fileName;

    m_pixels.resize(4 * m_width * m_height);

    for (int i = 0; i < m_width * m_height; ++i)
    {
        m_pixels[4 * i + 0] = 0x00;
        m_pixels[4 * i + 1] = 0x00;
        m_pixels[4 * i + 2] = 0x00;
        m_pixels[4 * i + 3] = 0xFF;
    }

    // Création de la texture
    CImage img(m_width, m_height, reinterpret_cast<CColor *>(&m_pixels[0]));

    m_texture = Game::textureManager->loadTexture(m_fileName, img, CTextureManager::FilterNone);


    m_lastFrame = AVIStreamLength(m_video);

    if (m_lastFrame == 0)
    {
        return false;
    }

    m_frameTime = AVIStreamSampleToTime(m_video, m_lastFrame) / m_lastFrame;
    m_pgf = AVIStreamGetFrameOpen(m_video, nullptr);

    // On ne peut pas récupérer les frames
    if (m_pgf == nullptr)
    {
        CApplication::getApp()->log("AVIStreamGetFrameOpen retourne un pointeur nul", ILogger::Error);
        return false;
    }

    // Ouverture du flux audio
    m_audio = new CMusic();
    m_audio->loadFromVideo(m_fileName);

    if (m_loop)
    {
        m_audio->setLoop();
    }

    m_audio->play();
    Game::soundEngine->addMusic(m_audio);

#endif

    //m_play = true;
    return true;
}