static void test_ash1_corruption(void) { COMMON_AVI_HEADERS cah; char filename[MAX_PATH]; PAVIFILE pFile; int res; PAVISTREAM pStream1; AVISTREAMINFOA asi1; GetTempPathA(MAX_PATH, filename); strcpy(filename+strlen(filename), testfilename); /* Corrupt the sample size in the audio stream header */ init_test_struct(&cah); cah.ash1.dwSampleSize = 0xdeadbeef; create_avi_file(&cah, filename); res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L); ok(res == 0, "Unable to open file: error=%u\n", res); res = AVIFileGetStream(pFile, &pStream1, 0, 1); ok(res == 0, "Unable to open audio stream: error=%u\n", res); res = AVIStreamInfoA(pStream1, &asi1, sizeof(asi1)); ok(res == 0, "Unable to read stream info: error=%u\n", res); /* The result will still be 2, because the value is dynamically replaced with the nBlockAlign value from the stream format header. The next test will prove this */ ok(asi1.dwSampleSize == 2, "got %u (expected 2)\n", asi1.dwSampleSize); AVIStreamRelease(pStream1); AVIFileRelease(pFile); ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename); }
static void test_ash1_corruption2(void) { COMMON_AVI_HEADERS cah; char filename[MAX_PATH]; PAVIFILE pFile; int res; PAVISTREAM pStream1; AVISTREAMINFOA asi1; GetTempPathA(MAX_PATH, filename); strcpy(filename+strlen(filename), testfilename); /* Corrupt the block alignment in the audio format header */ init_test_struct(&cah); cah.pcmwf.wf.nBlockAlign = 0xdead; create_avi_file(&cah, filename); res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L); ok(res == 0, "Unable to open file: error=%u\n", res); res = AVIFileGetStream(pFile, &pStream1, 0, 1); ok(res == 0, "Unable to open audio stream: error=%u\n", res); ok(AVIStreamInfoA(pStream1, &asi1, sizeof(asi1)) == 0, "Unable to read stream info\n"); /* The result will also be the corrupt value, as explained above. */ ok(asi1.dwSampleSize == 0xdead, "got 0x%x (expected 0xdead)\n", asi1.dwSampleSize); AVIStreamRelease(pStream1); AVIFileRelease(pFile); ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename); }
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; }
BOOL OpenSoundFile(HWND hWnd,PAVISTREAM *pavi) { #ifndef INTERIM_64_BIT // CCJ OPENFILENAME ofn; char filter[256]; AVIBuildFilter(filter,sizeof(filter),FALSE); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWnd; ofn.hInstance = NULL; ofn.lpstrTitle = GetResString(IDS_RB_OPENSOUND); ofn.lpstrFilter = filter; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 0; ofn.lpstrFile = fileName; ofn.nMaxFile = sizeof(fileName); ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = NULL; ofn.lCustData = 0; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; if (GetOpenFileNamePreview(&ofn)) { HRESULT hr; PAVIFILE pfile; PAVISTREAM pstream; BOOL res = TRUE; hr = AVIFileOpen(&pfile,fileName,OF_READ,NULL); if (hr) return FALSE; if (AVIFileGetStream( pfile,&pstream,streamtypeAUDIO,0) != AVIERR_OK) { res = FALSE; goto done; } *pavi = pstream; done: AVIFileRelease(pfile); return res; } else { return FALSE; } #else // INTERIM_64_BIT return FALSE; #endif // INTERIM_64_BIT }
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; }
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(); }
bool CCamAvi::Initialize (char* filename) { long hr; AVISTREAMINFO info; m_init=false; m_pos=0; AVIFileInit (); hr=AVIFileOpen (&m_paf, filename, OF_READ, NULL); if (hr!=0) return false; hr=AVIFileGetStream (m_paf, &m_pas, streamtypeVIDEO, 0); if (hr!=0) return false; hr= AVIStreamInfo (m_pas, &info, sizeof (info)); if (hr!=0) return false; hr=sizeof (m_bi); hr= AVIStreamReadFormat (m_pas, 0, &m_bi, &hr); if (hr!=0) return false; if (m_bi.bmiHeader.biCompression!=0) { // find decompressor m_hic=ICOpen (ICTYPE_VIDEO, info.fccHandler ,ICMODE_DECOMPRESS); if (m_hic==0) return false; } m_data=new unsigned char[m_bi.bmiHeader.biSizeImage]; AVISTREAMINFO a; AVIStreamInfo (m_pas, &a, sizeof (a)); m_length=a.dwLength; hr=AVIStreamBeginStreaming (m_pas, 0, 100, 1000); m_init=true; m_FrameRate = (double)a.dwRate / a.dwScale; m_pos=AVIStreamStart (m_pas); m_data=new BYTE[m_bi.bmiHeader.biSizeImage]; if (m_bi.bmiHeader.biCompression!=0) { hr=ICDecompressGetFormat (m_hic, &m_bi, &m_bi_out); } else m_bi_out=m_bi; m_frame.Create (m_bi_out.bmiHeader.biWidth, m_bi_out.bmiHeader.biHeight, m_bi_out.bmiHeader.biBitCount); return true; }
IAVIReadStream *AVIReadHandlerTunnelW32::GetStream(uint32 fccType, int lParam) { PAVISTREAM pas; HRESULT hr; if (IsMMXState()) throw MyInternalError("MMX state left on: %s:%d", __FILE__, __LINE__); hr = AVIFileGetStream(mpAVIFile, &pas, fccType, lParam); ClearMMXState(); if (hr) return nullptr; return new AVIReadTunnelStream(this, pas, mpAvisynthClipInfo); }
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; }
BOOL FMPlayerDShow::GetAVIInfo(const tchar* pFileName) { AVIFileInit(); PAVIFILE pfile; BOOL bOK = FALSE; if(AVIFileOpen(&pfile, pFileName, OF_SHARE_DENY_NONE, 0L) == 0) { AVIFILEINFO afi; memset(&afi, 0, sizeof(afi)); AVIFileInfo(pfile, &afi, sizeof(AVIFILEINFO)); CComPtr<IAVIStream> pavi; if(AVIFileGetStream(pfile, &pavi, streamtypeVIDEO, 0) == AVIERR_OK) { AVISTREAMINFO si; AVIStreamInfo(pavi, &si, sizeof(si)); m_FourCC = FormatFourCC(si.fccHandler); m_FrameRate = (double)si.dwRate / (double)si.dwScale; LONG lFormat; if (0 == AVIStreamFormatSize(pavi, 0, &lFormat)) { char* pBuf = new char[lFormat]; if (0 == AVIStreamReadFormat(pavi, 0, pBuf, &lFormat)) { BITMAPINFOHEADER* pHeader = (BITMAPINFOHEADER*)pBuf; m_StreamFormat = FormatFourCC(pHeader->biCompression); } delete[] pBuf; } bOK = TRUE; } AVIFileRelease(pfile); } AVIFileExit(); return bOK; }
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); }
static int avisynth_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVISynthContext *avs = s->priv_data; HRESULT res; AVIFILEINFO info; DWORD id; AVStream *st; AVISynthStream *stream; AVIFileInit(); res = AVIFileOpen(&avs->file, s->filename, OF_READ|OF_SHARE_DENY_WRITE, NULL); if (res != S_OK) { av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res); AVIFileExit(); return -1; } res = AVIFileInfo(avs->file, &info, sizeof(info)); if (res != S_OK) { av_log(s, AV_LOG_ERROR, "AVIFileInfo failed with error %ld", res); AVIFileExit(); return -1; } avs->streams = av_mallocz(info.dwStreams * sizeof(AVISynthStream)); for (id=0; id<info.dwStreams; id++) { stream = &avs->streams[id]; stream->read = 0; if (AVIFileGetStream(avs->file, &stream->handle, 0, id) == S_OK) { if (AVIStreamInfo(stream->handle, &stream->info, sizeof(stream->info)) == S_OK) { if (stream->info.fccType == streamtypeAUDIO) { WAVEFORMATEX wvfmt; LONG struct_size = sizeof(WAVEFORMATEX); if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK) continue; st = av_new_stream(s, id); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->block_align = wvfmt.nBlockAlign; st->codec->channels = wvfmt.nChannels; st->codec->sample_rate = wvfmt.nSamplesPerSec; st->codec->bit_rate = wvfmt.nAvgBytesPerSec * 8; st->codec->bits_per_sample = wvfmt.wBitsPerSample; stream->chunck_samples = wvfmt.nSamplesPerSec * (uint64_t)info.dwScale / (uint64_t)info.dwRate; stream->chunck_size = stream->chunck_samples * wvfmt.nChannels * wvfmt.wBitsPerSample / 8; st->codec->codec_tag = wvfmt.wFormatTag; st->codec->codec_id = wav_codec_get_id(wvfmt.wFormatTag, st->codec->bits_per_sample); } else if (stream->info.fccType == streamtypeVIDEO) { BITMAPINFO imgfmt; LONG struct_size = sizeof(BITMAPINFO); stream->chunck_size = stream->info.dwSampleSize; stream->chunck_samples = 1; if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK) continue; st = av_new_stream(s, id); st->codec->codec_type = CODEC_TYPE_VIDEO; st->r_frame_rate.num = stream->info.dwRate; st->r_frame_rate.den = stream->info.dwScale; st->codec->width = imgfmt.bmiHeader.biWidth; st->codec->height = imgfmt.bmiHeader.biHeight; st->codec->bits_per_sample = imgfmt.bmiHeader.biBitCount; st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale; st->codec->codec_tag = imgfmt.bmiHeader.biCompression; st->codec->codec_id = codec_get_id(codec_bmp_tags, imgfmt.bmiHeader.biCompression); st->duration = stream->info.dwLength; } else { AVIStreamRelease(stream->handle); continue; } avs->nb_streams++; st->codec->stream_codec_tag = stream->info.fccHandler; av_set_pts_info(st, 64, info.dwScale, info.dwRate); st->start_time = stream->info.dwStart; } } } return 0; }
// AVI_stream_open() will open the AVI file and prepare it for reading, but will not // store any of the frame data. // // returns: 0 ==> success // !0 ==> could not open the AVI stream // // The filename is expected to be an absolute pathname (or file in the current working directory) // int AVI_stream_open(char* filename) { if ( !AVI_stream_inited ) AVI_stream_init(); int hr; PAVIFILE pfile; PAVISTREAM pstream; AVISTREAMINFO avi_stream_info; Assert( !(AVI_stream.flags & AVI_STREAM_F_USED) ); // Open the AVI file hr = AVIFileOpen(&pfile, filename, OF_SHARE_DENY_WRITE, 0); if (hr != 0){ // nprintf(("Warning", "AVI ==> Unable to open %s", filename)); return -1; } strcpy(AVI_stream.filename, filename); // Get a handle to the video stream within the AVI file hr = AVIFileGetStream(pfile, &pstream, streamtypeVIDEO, 0); if (hr != 0){ //nprintf(("Warning", "AVI ==> Unable to open video stream in %s", filename)); return -1; } // Store the pointer to stream, since we'll need it later to read from disk AVI_stream.pstream = pstream; AVI_stream.pfile = pfile; // Get information on the stream hr = AVIStreamInfo( pstream, &avi_stream_info, sizeof(AVISTREAMINFO) ); if (hr != 0){ //nprintf(("Warning", "AVI ==> Unable to retreive stream info in %s", filename)); return -1; } int buffer_size; int start_sample = AVIStreamStart(pstream); Assert( start_sample == 0 ); int end_sample = AVIStreamEnd(pstream); Assert( end_sample >= start_sample ); // store the number of frames in the AVI_info[] structure AVI_stream.num_frames = end_sample; // start sample must be 0 Assert(AVI_stream.num_frames == AVIStreamLength(pstream) ); // Get information on the stream hr = AVIStreamInfo( pstream, &avi_stream_info, sizeof(AVISTREAMINFO) ); if (hr != 0){ //nprintf(("Warning", "AVI ==> Unable to retreive stream info in %s", filename)); return -1; } buffer_size = avi_stream_info.dwSuggestedBufferSize; Assert( buffer_size > 0 ); AVI_stream.min_compressed_buffer_size = buffer_size; // determine the format of the AVI image data ubyte* format_buffer; long format_buffer_size; BITMAPINFO* bitmap_info; hr = AVIStreamFormatSize(pstream, 0, &format_buffer_size); Assert( format_buffer_size > 0 ); format_buffer = (ubyte*) malloc(format_buffer_size); Assert(format_buffer != NULL); // format_buffer is free'ed when AVI is free'ed, since memory is used by b_info member in AVI_info[] structure hr = AVIStreamReadFormat(pstream, 0, format_buffer, &format_buffer_size); bitmap_info = (BITMAPINFO*)format_buffer; switch ( bitmap_info->bmiHeader.biCompression ) { case BI_RLE8: break; default: Assert(0); break; } AVI_stream.w = bitmap_info->bmiHeader.biWidth; AVI_stream.h = bitmap_info->bmiHeader.biHeight; AVI_stream.bpp = bitmap_info->bmiHeader.biBitCount; // create the palette translation look-up table // // Transparency: If the palette color is full green, then treat as transparent // RGBQUAD* pal; pal = (RGBQUAD*)(bitmap_info->bmiColors); // Store the palette in the AVI stream structure for ( int i = 0; i < 256; i++ ) { AVI_stream.palette[i*3] = pal[i].rgbRed; AVI_stream.palette[i*3+1] = pal[i].rgbGreen; AVI_stream.palette[i*3+2] = pal[i].rgbBlue; } // memcpy(AVI_stream.palette, pal, 256*3); /* int transparent_found = 0; for ( i = 0; i < 256; i++ ) { //nprintf(("AVI", "AVI ==> R: %d G: %d B: %d\n", pal[i].rgbRed, pal[i].rgbGreen, pal[i].rgbBlue)); if ( pal[i].rgbRed < 5 && pal[i].rgbGreen > 250 && pal[i].rgbBlue < 5 ) { avi_stream->pal_translation[i] = TRANSPARENT_INDEX; break; // found transparent, continue in j for loop, since don't need check any more } else avi_stream->pal_translation[i] = palette_find( pal[i].rgbRed, pal[i].rgbGreen, pal[i].rgbBlue ); } for ( j = i+1; j < 256; j++ ) { avi_stream->pal_translation[j] = palette_find( pal[j].rgbRed, pal[j].rgbGreen, pal[j].rgbBlue ); } */ free(format_buffer); // set the flag to used, so to make sure we only process one AVI stream at a time AVI_stream.flags |= AVI_STREAM_F_USED; return 0; }
int avisynth_read_header() { avs = (AVISynthContext *) av_mallocz(sizeof(AVISynthContext)); HRESULT res; AVIFILEINFO info; DWORD id; AVIFileInit(); res = AVIFileOpen(&avs->file, read_config_filepath(), OF_READ|OF_SHARE_DENY_WRITE, NULL); if (res != S_OK) { av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res); AVIFileExit(); return -1; } res = AVIFileInfo(avs->file, &info, sizeof(info)); if (res != S_OK) { av_log(s, AV_LOG_ERROR, "AVIFileInfo failed with error %ld", res); AVIFileExit(); return -1; } avs->streams = (AVISynthStream *) av_mallocz(info.dwStreams * sizeof(AVISynthStream)); assert(info.dwStreams == 1); for (id=0; id<info.dwStreams; id++) { stream = &avs->streams[id]; stream->read = 0; if (AVIFileGetStream(avs->file, &stream->handle, 0, id) == S_OK) { if (AVIStreamInfo(stream->handle, &stream->info, sizeof(stream->info)) == S_OK) { if (stream->info.fccType == streamtypeAUDIO) { assert(false); // don't do audio yet LONG struct_size = sizeof(WAVEFORMATEX); if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK) continue; /* audio: st = avformat_new_stream(s, NULL); st->id = id; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->block_align = wvfmt.nBlockAlign; st->codec->channels = wvfmt.nChannels; st->codec->sample_rate = wvfmt.nSamplesPerSec; st->codec->bit_rate = wvfmt.nAvgBytesPerSec * 8; st->codec->bits_per_coded_sample = wvfmt.wBitsPerSample; st->codec->codec_tag = wvfmt.wFormatTag; st->codec->codec_id = ff_wav_codec_get_id(wvfmt.wFormatTag, st->codec->bits_per_coded_sample); */ stream->chunck_samples = wvfmt.nSamplesPerSec * (__int64)info.dwScale / (__int64) info.dwRate; stream->chunck_size = stream->chunck_samples * wvfmt.nChannels * wvfmt.wBitsPerSample / 8; } else if (stream->info.fccType == streamtypeVIDEO) { LONG struct_size = sizeof(BITMAPINFO); stream->chunck_size = stream->info.dwSampleSize; stream->chunck_samples = 1; if (AVIStreamReadFormat(stream->handle, 0, &savedVideoFormat, &struct_size) != S_OK) continue; /* stream->info.dwRate is numerator stream->info.dwScale is denominator [?] savedVideoFormat.bmiHeader.biWidth */ /*st = avformat_new_stream(s, NULL); st->id = id; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->r_frame_rate.num = stream->info.dwRate; st->r_frame_rate.den = stream->info.dwScale; st->codec->width = savedVideoFormat.bmiHeader.biWidth; st->codec->height = savedVideoFormat.bmiHeader.biHeight; st->codec->bits_per_coded_sample = savedVideoFormat.bmiHeader.biBitCount; st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale; st->codec->codec_tag = savedVideoFormat.bmiHeader.biCompression; st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, savedVideoFormat.bmiHeader.biCompression); if (st->codec->codec_id == CODEC_ID_RAWVIDEO && savedVideoFormat.bmiHeader.biCompression== BI_RGB) { st->codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { st->codec->extradata_size = 9; memcpy(st->codec->extradata, "BottomUp", 9); } } st->duration = stream->info.dwLength; */ } else { AVIStreamRelease(stream->handle); continue; } avs->nb_streams++; // st->codec->stream_codec_tag = stream->info.fccHandler; //avpriv_set_pts_info(st, 64, info.dwScale, info.dwRate); //st->start_time = stream->info.dwStart; // wow what is the dshow equivalent? hmm... } } } return 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; }
AvisynthVideoProvider::AvisynthVideoProvider(agi::fs::path const& filename, std::string const& colormatrix) { agi::acs::CheckFileRead(filename); std::lock_guard<std::mutex> lock(avs.GetMutex()); #ifdef _WIN32 if (agi::fs::HasExtension(filename, "avi")) { // Try to read the keyframes before actually opening the file as trying // to open the file while it's already open can cause problems with // badly written VFW decoders AVIFileInit(); PAVIFILE pfile; long hr = AVIFileOpen(&pfile, filename.c_str(), OF_SHARE_DENY_WRITE, 0); if (hr) { warning = "Unable to open AVI file for reading keyframes:\n"; switch (hr) { case AVIERR_BADFORMAT: warning += "The file is corrupted, incomplete or has an otherwise bad format."; break; case AVIERR_MEMORY: warning += "The file could not be opened because of insufficient memory."; break; case AVIERR_FILEREAD: warning += "An error occurred reading the file. There might be a problem with the storage media."; break; case AVIERR_FILEOPEN: warning += "The file could not be opened. It might be in use by another application, or you do not have permission to access it."; break; case REGDB_E_CLASSNOTREG: warning += "There is no handler installed for the file extension. This might indicate a fundamental problem in your Video for Windows installation, and can be caused by extremely stripped Windows installations."; break; default: warning += "Unknown error."; break; } goto file_exit; } PAVISTREAM ppavi; if (hr = AVIFileGetStream(pfile, &ppavi, streamtypeVIDEO, 0)) { warning = "Unable to open AVI video stream for reading keyframes:\n"; switch (hr) { case AVIERR_NODATA: warning += "The file does not contain a usable video stream."; break; case AVIERR_MEMORY: warning += "Not enough memory."; break; default: warning += "Unknown error."; break; } goto file_release; } AVISTREAMINFO avis; if (FAILED(AVIStreamInfo(ppavi,&avis,sizeof(avis)))) { warning = "Unable to read keyframes from AVI file:\nCould not get stream information."; goto stream_release; } for (size_t i = 0; i < avis.dwLength; i++) { if (AVIStreamIsKeyFrame(ppavi, i)) keyframes.push_back(i); } // If every frame is a keyframe then just discard the keyframe data as it's useless if (keyframes.size() == (size_t)avis.dwLength) keyframes.clear(); // Clean up stream_release: AVIStreamRelease(ppavi); file_release: AVIFileRelease(pfile); file_exit: AVIFileExit(); } #endif try { auto script = Open(filename); // Check if video was loaded properly if (!script.IsClip() || !script.AsClip()->GetVideoInfo().HasVideo()) throw VideoNotSupported("No usable video found"); vi = script.AsClip()->GetVideoInfo(); if (!vi.IsRGB()) { /// @todo maybe read ColorMatrix hints for d2v files? AVSValue args[2] = { script, "Rec601" }; bool force_bt601 = OPT_GET("Video/Force BT.601")->GetBool() || colormatrix == "TV.601"; bool bt709 = vi.width > 1024 || vi.height >= 600; if (bt709 && (!force_bt601 || colormatrix == "TV.709")) { args[1] = "Rec709"; colorspace = "TV.709"; } else colorspace = "TV.601"; const char *argnames[2] = { 0, "matrix" }; script = avs.GetEnv()->Invoke("ConvertToRGB32", AVSValue(args, 2), argnames); } else colorspace = "None"; RGB32Video = avs.GetEnv()->Invoke("Cache", script).AsClip(); vi = RGB32Video->GetVideoInfo(); fps = (double)vi.fps_numerator / vi.fps_denominator; } catch (AvisynthError const& err) { throw VideoOpenError("Avisynth error: " + std::string(err.msg)); } }
PAVISTREAM GetAudioStream(TSTR name,TCHAR *dir) { HRESULT hr; PAVIFILE pfile; PAVISTREAM pstream = NULL; BOOL res = TRUE; #ifndef INTERIM_64_BIT // CCJ // RB 5/10/99: Reworked this a bit. Added the current scene dir as a possible search location. // Also now using SplitPathFile() instead of doing it by hand. hr = AVIFileOpen(&pfile,name,OF_READ,NULL); if (hr) { TSTR fileName, tryName; SplitPathFile(name, NULL, &fileName); // Try the given directory (which is the sound dir) tryName = TSTR(dir) + TSTR(_T("\\")) + fileName; hr = AVIFileOpen(&pfile,tryName,OF_READ,NULL); if (hr) { // Try the scene directory TSTR sceneName = GetCOREInterface()->GetCurFilePath(); TSTR scenePath; SplitPathFile(sceneName, &scenePath, NULL); tryName = scenePath + TSTR(_T("\\")) + fileName; hr = AVIFileOpen(&pfile,tryName,OF_READ,NULL); } #if 0 // Try the file in the given directory int i = name.Length()-1; while (i>0) { if (name[i]=='\\' || name[i]==':' || name[i]=='/') { i++; break; } i--; } if (name.Length()-i>0) { TSTR newname = TSTR(dir) + TSTR(_T("\\")) + name.Substr(i,name.Length()-i); hr = AVIFileOpen(&pfile,newname,OF_READ,NULL); } #endif } if (hr) return NULL; AVIFileGetStream(pfile,&pstream,streamtypeAUDIO,0); AVIFileRelease(pfile); if (!pstream) return NULL; // Verify it's PCM PCMWAVEFORMAT wf; LONG l = sizeof(wf); AVIStreamReadFormat(pstream,0,&wf,&l); if (!l) { AVIStreamRelease(pstream); return NULL; } if (wf.wf.wFormatTag != WAVE_FORMAT_PCM) { AVIStreamRelease(pstream); return NULL; } #endif // INTERIM_64_BIT return pstream; }
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); } } }
int imFileFormatAVI::Open(const char* file_name) { /* initializes avi file library, can be called many times */ AVIFileInit(); /* open existing file */ HRESULT hr = AVIFileOpen(&file, file_name, OF_READ, NULL); if (hr != 0) { AVIFileExit(); if (hr == AVIERR_FILEOPEN) return IM_ERR_OPEN; else if (hr == AVIERR_BADFORMAT || hr == REGDB_E_CLASSNOTREG) return IM_ERR_FORMAT; else return IM_ERR_ACCESS; } /* get the video stream */ hr = AVIFileGetStream(file, &stream, streamtypeVIDEO, 0); if (hr != 0) { AVIFileRelease(this->file); AVIFileExit(); if (hr == AVIERR_NODATA) return IM_ERR_DATA; else return IM_ERR_ACCESS; } /* get stream info */ AVISTREAMINFO streaminfo; AVIStreamInfo(stream, &streaminfo, sizeof(AVISTREAMINFO)); this->image_count = streaminfo.dwLength; this->fps = (float)streaminfo.dwRate / (float)streaminfo.dwScale; if (streaminfo.fccHandler == mmioFOURCC('D','I','B',' ')) strcpy(this->compression, "NONE"); else if (streaminfo.fccHandler == mmioFOURCC('M','R','L','E')) strcpy(this->compression, "RLE"); else if (streaminfo.fccHandler == mmioFOURCC('c','v','i','d')) strcpy(this->compression, "CINEPACK"); else { DWORD handler = streaminfo.fccHandler; this->compression[0] = (char)handler; this->compression[1] = (char)(handler >> 8); this->compression[2] = (char)(handler >> 16); this->compression[3] = (char)(handler >> 24); this->compression[4] = 0; } this->frame = 0; this->use_compressor = 0; this->dib = 0; this->current_frame = 0; return IM_ERR_NONE; }
static int avisynth_read_header(AVFormatContext *s) { AVISynthContext *avs = s->priv_data; HRESULT res; AVIFILEINFO info; DWORD id; AVStream *st; AVISynthStream *stream; wchar_t filename_wchar[1024] = { 0 }; char filename_char[1024] = { 0 }; AVIFileInit(); /* avisynth can't accept UTF-8 filename */ MultiByteToWideChar(CP_UTF8, 0, s->filename, -1, filename_wchar, 1024); WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wchar, -1, filename_char, 1024, NULL, NULL); res = AVIFileOpen(&avs->file, filename_char, OF_READ|OF_SHARE_DENY_WRITE, NULL); if (res != S_OK) { av_log(s, AV_LOG_ERROR, "AVIFileOpen failed with error %ld", res); AVIFileExit(); return -1; } res = AVIFileInfo(avs->file, &info, sizeof(info)); if (res != S_OK) { av_log(s, AV_LOG_ERROR, "AVIFileInfo failed with error %ld", res); AVIFileExit(); return -1; } avs->streams = av_mallocz(info.dwStreams * sizeof(AVISynthStream)); for (id=0; id<info.dwStreams; id++) { stream = &avs->streams[id]; stream->read = 0; if (AVIFileGetStream(avs->file, &stream->handle, 0, id) == S_OK) { if (AVIStreamInfo(stream->handle, &stream->info, sizeof(stream->info)) == S_OK) { if (stream->info.fccType == streamtypeAUDIO) { WAVEFORMATEX wvfmt; LONG struct_size = sizeof(WAVEFORMATEX); if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK) continue; st = avformat_new_stream(s, NULL); st->id = id; st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->block_align = wvfmt.nBlockAlign; st->codec->channels = wvfmt.nChannels; st->codec->sample_rate = wvfmt.nSamplesPerSec; st->codec->bit_rate = wvfmt.nAvgBytesPerSec * 8; st->codec->bits_per_coded_sample = wvfmt.wBitsPerSample; stream->chunck_samples = wvfmt.nSamplesPerSec * (uint64_t)info.dwScale / (uint64_t)info.dwRate; stream->chunck_size = stream->chunck_samples * wvfmt.nChannels * wvfmt.wBitsPerSample / 8; st->codec->codec_tag = wvfmt.wFormatTag; st->codec->codec_id = ff_wav_codec_get_id(wvfmt.wFormatTag, st->codec->bits_per_coded_sample); } else if (stream->info.fccType == streamtypeVIDEO) { BITMAPINFO imgfmt; LONG struct_size = sizeof(BITMAPINFO); stream->chunck_size = stream->info.dwSampleSize; stream->chunck_samples = 1; if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK) continue; st = avformat_new_stream(s, NULL); st->id = id; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->r_frame_rate.num = stream->info.dwRate; st->r_frame_rate.den = stream->info.dwScale; st->codec->width = imgfmt.bmiHeader.biWidth; st->codec->height = imgfmt.bmiHeader.biHeight; st->codec->bits_per_coded_sample = imgfmt.bmiHeader.biBitCount; st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale; st->codec->codec_tag = imgfmt.bmiHeader.biCompression; st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, imgfmt.bmiHeader.biCompression); if (st->codec->codec_id == CODEC_ID_RAWVIDEO && imgfmt.bmiHeader.biCompression== BI_RGB) { st->codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE); if (st->codec->extradata) { st->codec->extradata_size = 9; memcpy(st->codec->extradata, "BottomUp", 9); } } st->duration = stream->info.dwLength; } else { AVIStreamRelease(stream->handle); continue; } avs->nb_streams++; st->codec->stream_codec_tag = stream->info.fccHandler; avpriv_set_pts_info(st, 64, info.dwScale, info.dwRate); st->start_time = stream->info.dwStart; } } } return 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; }
static void test_default_data(void) { COMMON_AVI_HEADERS cah; char filename[MAX_PATH]; PAVIFILE pFile; int res; LONG lSize; PAVISTREAM pStream0; PAVISTREAM pStream1; AVISTREAMINFOA asi0, asi1; WAVEFORMATEX wfx; GetTempPathA(MAX_PATH, filename); strcpy(filename+strlen(filename), testfilename); init_test_struct(&cah); create_avi_file(&cah, filename); res = AVIFileOpenA(&pFile, filename, OF_SHARE_DENY_WRITE, 0L); ok(res != AVIERR_BADFORMAT, "Unable to open file: error1=%u\n", AVIERR_BADFORMAT); ok(res != AVIERR_MEMORY, "Unable to open file: error2=%u\n", AVIERR_MEMORY); ok(res != AVIERR_FILEREAD, "Unable to open file: error3=%u\n", AVIERR_FILEREAD); ok(res != AVIERR_FILEOPEN, "Unable to open file: error4=%u\n", AVIERR_FILEOPEN); ok(res != REGDB_E_CLASSNOTREG, "Unable to open file: error5=%u\n", REGDB_E_CLASSNOTREG); ok(res == 0, "Unable to open file: error=%u\n", res); res = AVIFileGetStream(pFile, &pStream0, 0, 0); ok(res == 0, "Unable to open video stream: error=%u\n", res); res = AVIFileGetStream(pFile, &pStream1, 0, 1); ok(res == 0, "Unable to open audio stream: error=%u\n", res); res = AVIStreamInfoA(pStream0, &asi0, sizeof(asi0)); ok(res == 0, "Unable to read stream info: error=%u\n", res); res = AVIStreamInfoA(pStream1, &asi1, sizeof(asi1)); ok(res == 0, "Unable to read stream info: error=%u\n", res); res = AVIStreamReadFormat(pStream0, AVIStreamStart(pStream1), NULL, &lSize); ok(res == 0, "Unable to read format size: error=%u\n", res); res = AVIStreamReadFormat(pStream1, AVIStreamStart(pStream1), &wfx, &lSize); ok(res == 0, "Unable to read format: error=%u\n", res); ok(asi0.fccType == streamtypeVIDEO, "got 0x%x (expected streamtypeVIDEO)\n", asi0.fccType); ok(asi0.fccHandler == 0x30323449, "got 0x%x (expected 0x30323449)\n", asi0.fccHandler); ok(asi0.dwFlags == 0, "got %u (expected 0)\n", asi0.dwFlags); ok(asi0.wPriority == 0, "got %u (expected 0)\n", asi0.wPriority); ok(asi0.wLanguage == 0, "got %u (expected 0)\n", asi0.wLanguage); ok(asi0.dwScale == 1001, "got %u (expected 1001)\n", asi0.dwScale); ok(asi0.dwRate == 30000, "got %u (expected 30000)\n", asi0.dwRate); ok(asi0.dwStart == 0, "got %u (expected 0)\n", asi0.dwStart); ok(asi0.dwLength == 1, "got %u (expected 1)\n", asi0.dwLength); ok(asi0.dwInitialFrames == 0, "got %u (expected 0)\n", asi0.dwInitialFrames); ok(asi0.dwSuggestedBufferSize == 0, "got %u (expected 0)\n", asi0.dwSuggestedBufferSize); ok(asi0.dwQuality == 0xffffffff, "got 0x%x (expected 0xffffffff)\n", asi0.dwQuality); ok(asi0.dwSampleSize == 0, "got %u (expected 0)\n", asi0.dwSampleSize); ok(asi0.rcFrame.left == 0, "got %u (expected 0)\n", asi0.rcFrame.left); ok(asi0.rcFrame.top == 0, "got %u (expected 0)\n", asi0.rcFrame.top); ok(asi0.rcFrame.right == 8, "got %u (expected 8)\n", asi0.rcFrame.right); /* these are based on the values in the mah and not */ ok(asi0.rcFrame.bottom == 6, "got %u (expected 6)\n", asi0.rcFrame.bottom);/* on the ones in the ash which are 0 here */ ok(asi0.dwEditCount == 0, "got %u (expected 0)\n", asi0.dwEditCount); ok(asi0.dwFormatChangeCount == 0, "got %u (expected 0)\n", asi0.dwFormatChangeCount); ok(asi1.fccType == streamtypeAUDIO, "got 0x%x (expected streamtypeVIDEO)\n", asi1.fccType); ok(asi1.fccHandler == 0x1, "got 0x%x (expected 0x1)\n", asi1.fccHandler); ok(asi1.dwFlags == 0, "got %u (expected 0)\n", asi1.dwFlags); ok(asi1.wPriority == 0, "got %u (expected 0)\n", asi1.wPriority); ok(asi1.wLanguage == 0, "got %u (expected 0)\n", asi1.wLanguage); ok(asi1.dwScale == 1, "got %u (expected 1)\n", asi1.dwScale); ok(asi1.dwRate == 11025, "got %u (expected 11025)\n", asi1.dwRate); ok(asi1.dwStart == 0, "got %u (expected 0)\n", asi1.dwStart); ok(asi1.dwLength == 1637, "got %u (expected 1637)\n", asi1.dwLength); ok(asi1.dwInitialFrames == 0, "got %u (expected 0)\n", asi1.dwInitialFrames); ok(asi1.dwSuggestedBufferSize == 0, "got %u (expected 0)\n", asi1.dwSuggestedBufferSize); ok(asi1.dwQuality == 0xffffffff, "got 0x%x (expected 0xffffffff)\n", asi1.dwQuality); ok(asi1.dwSampleSize == 2, "got %u (expected 2)\n", asi1.dwSampleSize); ok(asi1.rcFrame.left == 0, "got %u (expected 0)\n", asi1.rcFrame.left); ok(asi1.rcFrame.top == 0, "got %u (expected 0)\n", asi1.rcFrame.top); ok(asi1.rcFrame.right == 0, "got %u (expected 0)\n", asi1.rcFrame.right); ok(asi1.rcFrame.bottom == 0, "got %u (expected 0)\n", asi1.rcFrame.bottom); ok(asi1.dwEditCount == 0, "got %u (expected 0)\n", asi1.dwEditCount); ok(asi1.dwFormatChangeCount == 0, "got %u (expected 0)\n", asi1.dwFormatChangeCount); ok(wfx.wFormatTag == 1, "got %u (expected 1)\n",wfx.wFormatTag); ok(wfx.nChannels == 2, "got %u (expected 2)\n",wfx.nChannels); ok(wfx.wFormatTag == 1, "got %u (expected 1)\n",wfx.wFormatTag); ok(wfx.nSamplesPerSec == 11025, "got %u (expected 11025)\n",wfx.nSamplesPerSec); ok(wfx.nAvgBytesPerSec == 22050, "got %u (expected 22050)\n",wfx.nAvgBytesPerSec); ok(wfx.nBlockAlign == 2, "got %u (expected 2)\n",wfx.nBlockAlign); AVIStreamRelease(pStream0); AVIStreamRelease(pStream1); AVIFileRelease(pFile); ok(DeleteFileA(filename) !=0, "Deleting file %s failed\n", filename); }
///////////////////////////////////////////////////////// //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; }
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; }
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(); }
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; }
void CRotateAVIDlg::ProcessAVI(const TCHAR *source_filename, const TCHAR *dest_filename, eRotation rot) { TCHAR error_buf[1024]; PAVIFILE source_avi = 0; PAVIFILE dest_avi = 0; PAVISTREAM pSrcVidStream = 0; PAVISTREAM pSrcAudioStream = 0; PAVISTREAM pDestVidStream = 0; PAVISTREAM pDestAudioStream = 0; char *pSrcBuffer = 0; char *pJPGBuffer = 0; char *pDecompBuffer = 0; char *pRotateBuffer = 0; char *pDestBuffer = 0; AVIFileInit(); // source setup if (AVIFileOpen(&source_avi, source_filename, OF_READ, NULL) != AVIERR_OK) { _stprintf(error_buf, TEXT("Couldn't open file %s"), source_filename); MessageBox(error_buf); goto cleanup; } AVIFILEINFO src_avi_info; AVIFileInfo(source_avi, &src_avi_info, sizeof(AVIFILEINFO)); if (AVIFileGetStream(source_avi, &pSrcVidStream, streamtypeVIDEO, 0) != AVIERR_OK) { _stprintf(error_buf, TEXT("No video stream in %s"), source_filename); MessageBox(error_buf); goto cleanup; } BITMAPINFOHEADER srcBIH; long srcvidstreamsize; AVIStreamFormatSize(pSrcVidStream, 0, &srcvidstreamsize); if (srcvidstreamsize > sizeof(BITMAPINFOHEADER)) { _stprintf(error_buf, TEXT("Unable to handle video stream format in %s"), source_filename); MessageBox(error_buf); goto cleanup; } srcvidstreamsize = sizeof(BITMAPINFOHEADER); if (AVIStreamReadFormat(pSrcVidStream, 0, &srcBIH, &srcvidstreamsize) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error reading stream format in %s"), source_filename); MessageBox(error_buf); goto cleanup; } if (srcBIH.biCompression != MKFOURCC('M','J','P','G')) { _stprintf(error_buf, TEXT("%s is not motion JPEG format"), source_filename); MessageBox(error_buf); goto cleanup; } AVISTREAMINFO vidstream_info; if (AVIStreamInfo(pSrcVidStream, &vidstream_info, sizeof(AVISTREAMINFO)) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error reading stream info in %s"), source_filename); MessageBox(error_buf); goto cleanup; } int firstVidSrcFrame = AVIStreamStart(pSrcVidStream); if (firstVidSrcFrame == -1) { _stprintf(error_buf, TEXT("Video stream start error in %s"), source_filename); MessageBox(error_buf); goto cleanup; } int numVidSrcFrames = AVIStreamLength(pSrcVidStream); if (numVidSrcFrames == -1) { _stprintf(error_buf, TEXT("Video stream length error in %s"), source_filename); MessageBox(error_buf); goto cleanup; } AVIFileGetStream(source_avi, &pSrcAudioStream, streamtypeAUDIO, 0); int firstAudioSrcFrame = 0; int numAudioSrcFrames = 0; if (pSrcAudioStream) { firstAudioSrcFrame = AVIStreamStart(pSrcAudioStream); if (firstAudioSrcFrame == -1) { _stprintf(error_buf, TEXT("Audio stream start error in %s"), source_filename); MessageBox(error_buf); goto cleanup; } numAudioSrcFrames = AVIStreamLength(pSrcAudioStream); if (numAudioSrcFrames == -1) { _stprintf(error_buf, TEXT("Audio stream length error in %s"), source_filename); MessageBox(error_buf); goto cleanup; } } // dest setup BITMAPINFOHEADER destBIH; destBIH = srcBIH; if (rot != CW_180) { destBIH.biWidth = srcBIH.biHeight; destBIH.biHeight = srcBIH.biWidth; } if (AVIFileOpen(&dest_avi, dest_filename, OF_CREATE | OF_WRITE, NULL) != AVIERR_OK) { _stprintf(error_buf, TEXT("Couldn't open file %s"), dest_filename); MessageBox(error_buf); goto cleanup; } vidstream_info.rcFrame.left = vidstream_info.rcFrame.top = 0; vidstream_info.rcFrame.right = destBIH.biWidth; vidstream_info.rcFrame.bottom = destBIH.biHeight; if (AVIFileCreateStream(dest_avi, &pDestVidStream, &vidstream_info) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error creating video stream in %s"), dest_filename); MessageBox(error_buf); goto cleanup; } if (AVIStreamSetFormat(pDestVidStream, 0, &destBIH, sizeof(BITMAPINFOHEADER)) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error setting video stream format in %s"), dest_filename); MessageBox(error_buf); goto cleanup; } if (AVIStreamSetFormat(pDestVidStream, 0, &destBIH, sizeof(BITMAPINFOHEADER)) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error setting video stream format in %s"), dest_filename); MessageBox(error_buf); goto cleanup; } // video memory int img_rgb_size = srcBIH.biHeight * srcBIH.biWidth * 3; pSrcBuffer = new char[img_rgb_size]; pJPGBuffer = new char[img_rgb_size]; pDecompBuffer = new char[img_rgb_size]; pRotateBuffer = new char[img_rgb_size]; pDestBuffer = new char[img_rgb_size]; long bytes_read; long bytes_written; for (int i = firstVidSrcFrame; i < numVidSrcFrames; ++i) { if (AVIStreamRead(pSrcVidStream, i, 1, pSrcBuffer, img_rgb_size, &bytes_read, 0) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error reading video stream from %s"), source_filename); MessageBox(error_buf); goto cleanup; } // well-form the jpg int jpglen = ConstructWellFormedJPEG(pSrcBuffer, pJPGBuffer, bytes_read); // decompress JPEGHandler jpgh_decomp(pJPGBuffer, jpglen); jpgh_decomp.DecompressToRGB(pDecompBuffer, img_rgb_size); // rotate int destx, desty; char *pRotSrc; char *pRotDest; switch (rot) { case CW_90: for (int srcy = 0; srcy < srcBIH.biHeight; ++srcy) { for (int srcx = 0; srcx < srcBIH.biWidth; ++srcx) { destx = srcBIH.biHeight-1-srcy; desty = srcx; pRotSrc = &pDecompBuffer[(srcy * srcBIH.biWidth + srcx) * 3]; pRotDest = &pRotateBuffer[(desty * srcBIH.biHeight + destx) * 3]; *pRotDest++ = *pRotSrc++; *pRotDest++ = *pRotSrc++; *pRotDest++ = *pRotSrc++; } } break; case CW_180: for (int srcy = 0; srcy < srcBIH.biHeight; ++srcy) { for (int srcx = 0; srcx < srcBIH.biWidth; ++srcx) { destx = srcBIH.biWidth-1-srcx; desty = srcBIH.biHeight-1-srcy; pRotSrc = &pDecompBuffer[(srcy * srcBIH.biWidth + srcx) * 3]; pRotDest = &pRotateBuffer[(desty * srcBIH.biWidth + destx) * 3]; *pRotDest++ = *pRotSrc++; *pRotDest++ = *pRotSrc++; *pRotDest++ = *pRotSrc++; } } break; case ACW_90: for (int srcy = 0; srcy < srcBIH.biHeight; ++srcy) { for (int srcx = 0; srcx < srcBIH.biWidth; ++srcx) { destx = srcy; desty = srcBIH.biWidth-1-srcx; pRotSrc = &pDecompBuffer[(srcy * srcBIH.biWidth + srcx) * 3]; pRotDest = &pRotateBuffer[(desty * srcBIH.biHeight + destx) * 3]; *pRotDest++ = *pRotSrc++; *pRotDest++ = *pRotSrc++; *pRotDest++ = *pRotSrc++; } } break; } // compress JPEGHandler jpgh_comp(pRotateBuffer, img_rgb_size); if (rot != CW_180) destBIH.biSizeImage = jpgh_comp.CompressFromRGB(pDestBuffer, img_rgb_size, srcBIH.biHeight, srcBIH.biWidth); else destBIH.biSizeImage = jpgh_comp.CompressFromRGB(pDestBuffer, img_rgb_size, srcBIH.biWidth, srcBIH.biHeight); if (AVIStreamWrite(pDestVidStream, i, 1, pDestBuffer, destBIH.biSizeImage, AVIIF_KEYFRAME, NULL, &bytes_written) != AVIERR_OK) { _stprintf(error_buf, TEXT("Error writing video stream to %s"), dest_filename); MessageBox(error_buf); goto cleanup; } } cleanup: delete[] pSrcBuffer; delete[] pDestBuffer; delete[] pJPGBuffer; delete[] pDecompBuffer; delete[] pRotateBuffer; if (pDestAudioStream) AVIStreamRelease(pDestAudioStream); if (pDestVidStream) AVIStreamRelease(pDestVidStream); if (pSrcAudioStream) AVIStreamRelease(pSrcAudioStream); if (pSrcVidStream) AVIStreamRelease(pSrcVidStream); if (dest_avi) AVIFileRelease(dest_avi); if (source_avi) AVIFileRelease(source_avi); AVIFileExit(); }