void VLCWrapperImpl::Snapshot() { unsigned width = 0, height = 0; libvlc_video_get_size(pMediaPlayer_, 0, &width, &height); SYSTEMTIME curTime = { 0 }; GetLocalTime(&curTime); std::ostringstream filename; filename << "snapshot_" << std::setfill('0') << std::setw(4) << curTime.wYear << std::setw(2) << curTime.wMonth << std::setw(2) << curTime.wDay << '_' << std::setw(2) << curTime.wHour << std::setw(2) << curTime.wMinute << std::setw(2) << curTime.wSecond << '_' << std::setw(3) << curTime.wMilliseconds << ".png"; libvlc_video_take_snapshot(pMediaPlayer_, 0, filename.str().data(), width, height); //static bool bFullScreen = false; //HWND hWnd = (HWND)libvlc_media_player_get_hwnd(pMediaPlayer_); //if (hWnd) //{ // bFullScreen = !bFullScreen; // //::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); // ShowWindow(hWnd, bFullScreen?SW_SHOWMAXIMIZED:SW_SHOWNORMAL); //} //libvlc_video_set_scale(pMediaPlayer_, 2.5); //libvlc_media_player_t *mp = pMediaPlayer_; //bool fs = libvlc_get_fullscreen(mp); //libvlc_set_fullscreen(mp, true); //assert(libvlc_get_fullscreen(mp)); //libvlc_set_fullscreen(mp, false); //assert(!libvlc_get_fullscreen(mp)); //libvlc_toggle_fullscreen(mp); //assert(libvlc_get_fullscreen(mp)); //libvlc_toggle_fullscreen(mp); //assert(!libvlc_get_fullscreen(mp)); //libvlc_set_fullscreen(mp, fs); //assert(libvlc_get_fullscreen(mp) == fs); //assert(libvlc_video_get_scale(mp) == 0.); /* default */ //libvlc_video_set_scale(mp, 0.); /* no-op */ //libvlc_video_set_scale(mp, 2.5); //assert(libvlc_video_get_scale(mp) == 2.5); //libvlc_video_set_scale(mp, 0.); //libvlc_video_set_scale(mp, 0.); /* no-op */ //assert(libvlc_video_get_scale(mp) == 0.); }
bool VlcVideo::takeSnapshot(const QString &path) const { bool success = false; if (_vlcMediaPlayer && libvlc_media_player_has_vout(_vlcMediaPlayer)) { success = libvlc_video_take_snapshot(_vlcMediaPlayer, 0, path.toUtf8().data(), 0, 0) + 1; VlcError::errmsg(); } return success; }
static void snapshot(libvlc_media_player_t *mp, int width, char *out_with_ext) { libvlc_event_manager_t *em = libvlc_media_player_event_manager(mp); assert(em); libvlc_event_attach(em, libvlc_MediaPlayerSnapshotTaken, callback, NULL); done = false; libvlc_video_take_snapshot(mp, 0, out_with_ext, width, 0); event_wait("Snapshot has not been written"); libvlc_event_detach(em, libvlc_MediaPlayerSnapshotTaken, callback, NULL); }
BOOL CReportCameraWorker::MakeCapturePhoto() { TRACE(_T("CReportCameraWorker::MakeCapturePhoto\n")); if (m_inst == NULL) { return FALSE; } USES_CONVERSION; CString strOutputFileName; strOutputFileName = GetCaptureFileName(_T("jpg"), TRUE); /* retrieve width of video */ int width = libvlc_video_get_width (m_mp); /* retrieve height of video */ int height = libvlc_video_get_height (m_mp); int iRet = libvlc_video_take_snapshot(m_mp, 0, T2A(strOutputFileName), width, height); TRACE(_T("CReportCameraWorker::MakeCapturePhoto iRet=%d\n"), iRet); if (iRet == 0) { LogCaptureFile(_T("jpg")); return TRUE; } return FALSE; }
STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture) { if( NULL == picture ) return E_POINTER; libvlc_media_player_t *p_md; HRESULT hr = getMD(&p_md); if( SUCCEEDED(hr) ) { static int uniqueId = 0; TCHAR path[MAX_PATH+1]; int pathlen = GetTempPath(MAX_PATH-24, path); if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) ) return E_FAIL; /* check temp directory path by openning it */ { HANDLE dirHandle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if( INVALID_HANDLE_VALUE == dirHandle ) { Instance()->setErrorInfo(IID_IVLCVideo, "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars."); return E_FAIL; } else { BY_HANDLE_FILE_INFORMATION bhfi; BOOL res = GetFileInformationByHandle(dirHandle, &bhfi); CloseHandle(dirHandle); if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) { Instance()->setErrorInfo(IID_IVLCVideo, "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars."); return E_FAIL; } } } TCHAR filepath[MAX_PATH+1]; _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"), path, GetCurrentProcessId(), ++uniqueId); #ifdef _UNICODE /* reuse path storage for UTF8 string */ char *psz_filepath = (char *)path; WCHAR* wpath = filepath; #else char *psz_filepath = path; /* first convert to unicode using current code page */ WCHAR wpath[MAX_PATH+1]; if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) ) return E_FAIL; #endif /* convert to UTF8 */ pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL); // fail if path is 0 or too short (i.e pathlen is the same as // storage size) if( (0 == pathlen) || (sizeof(path) == pathlen) ) return E_FAIL; /* take snapshot into file */ if( libvlc_video_take_snapshot(p_md, 0, psz_filepath, 0, 0) == 0 ) { /* open snapshot file */ HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE); if( snapPic ) { PICTDESC snapDesc; snapDesc.cbSizeofstruct = sizeof(PICTDESC); snapDesc.picType = PICTYPE_BITMAP; snapDesc.bmp.hbitmap = (HBITMAP)snapPic; snapDesc.bmp.hpal = NULL; hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture); if( FAILED(hr) ) { *picture = NULL; DeleteObject(snapPic); } } DeleteFile(filepath); } } return hr; };