Ciao
How can i have the video width and height of a file video ?
Example:
I have a file test.mp4 and i want to know the width and height of frames (600 x 1024,...)
Grazie
#include "hbapi.h"
#include "hbapiitm.h"
#include <mfapi.h>
#include <mfreadwrite.h>
#include <mferror.h>
HB_FUNC( GETMP4VIDEODIMENSIONS )
{
HRESULT hr = CoInitializeEx( nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE );
if( FAILED( hr ) )
{
printf( "Failed to initialize COM library. Error code = %x\n", hr );
hb_ret();
}
IMFSourceReader *pReader = nullptr;
hr = MFCreateSourceReaderFromURL( hb_parcx( 1 ), nullptr, &pReader );
if( FAILED( hr ) )
{
printf( "Failed to create source reader. Error code = %x\n", hr );
CoUninitialize();
hb_ret();
}
IMFMediaType *pType = nullptr;
hr = pReader->GetCurrentMediaType( MF_SOURCE_READER_FIRST_VIDEO_STREAM, &pType );
if( FAILED( hr ) )
{
printf( "Failed to get media type. Error code = %x\n", hr );
pReader->Release();
CoUninitialize();
hb_ret();
}
UINT32 u32Width = 0;
UINT32 u32Height = 0;
GUID subType;
hr = pType->GetGUID( MF_MT_SUBTYPE, &subType );
if( FAILED( hr ) )
{
printf( "Failed to get subtype. Error code = %x\n", hr );
pType->Release();
pReader->Release();
CoUninitialize();
hb_ret();
}
if( subType == MFVideoFormat_RGB24 )
{
hr = MFGetAttributeSize( pType, MF_MT_FRAME_SIZE, &u32Width, &u32Height );
if( FAILED( hr ) )
{
printf( "Failed to get frame size. Error code = %x\n", hr );
pType->Release();
pReader->Release();
CoUninitialize();
hb_ret();
}
}
pType->Release();
hb_reta( 2 );
hb_storvni( u32Width, -1, 1 );
hb_storvni( u32Height, -1, 2 );
pReader->Release();
CoUninitialize();
}
Romeo wrote:How can i have the video width and height of a file video ?
METHOD Getwidth() CLASS TWMP
RETURN ::oWMP:currentMedia:imageSourceWidth
METHOD Getheight() CLASS TWMP
RETURN ::oWMP:currentMedia:imageSourceHeight
#include "HMG.ch"
#include "hbclass.ch"
#include "WMP.CH"
MEMVAR _HMG_SYSDATA
*+--------------------------------------------------------------------
*+
*+ Class TWMP
*+
*+--------------------------------------------------------------------
*+
CLASS TWMP
HIDDEN:
DATA oWMP
DATA nVolume INIT 50
EXPORTED:
DATA cFileName
METHOD New( oActiveX ) CONSTRUCTOR
METHOD Destroy()
METHOD URL( cFile )
METHOD stretchToFit( lOnOff )
METHOD enableContextMenu( lOnOff )
METHOD windowlessVideo( lOnOff )
METHOD uiMode( cMode )
METHOD PlayState()
METHOD IsPlaying()
METHOD fullScreen( lOnOff )
METHOD Play()
METHOD CurrentPosition( nPosition )
METHOD Pause()
METHOD Stop()
METHOD Getcurrentitem()
METHOD Mute( lMute )
METHOD MoveVolume( nDirection )
METHOD Volume( nVolume )
METHOD AutoStart( lOnOff )
METHOD Duration()
METHOD Getfps()
METHOD Getwidth()
METHOD Getheight()
METHOD GetVersion()
ENDCLASS
METHOD New( oActiveX ) CLASS TWMP
LOCAL oRet := NIL
LOCAL bOldError, oError, cText
IF HB_ISOBJECT( oActiveX )
bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
BEGIN SEQUENCE
::oWMP := oActiveX
// test if we can accese it
cText := ::oWMP:versionInfo
IF EMPTY( cText )
BREAK
ENDIF
::oWMP:enableContextMenu := .F. // don't show right menu
::oWMP:windowlessVideo := .T. // prevent double-click fullscreen on XP
// ::oWMP:uiMode := "full" // with all Controls
// ::oWMP:uiMode := "mini" // with some Controls
::oWMP:uiMode := "none" // with none Controls
::volume( 50 )
oRet := self
RECOVER USING oError
ERRORBLOCK( bOldError )
SP_laxError( .T. )
MsgInfo( "Problem WMP Engine" + CRLF + CRLF + oError:description + " : " + oError:operation, "Error VLC ActiveX " + LTRIM( HB_VALTOSTR( oError:osCode ) ) )
::Destroy()
RETURN NIL
END SEQUENCE
ERRORBLOCK( bOldError )
DO EVENTS
ENDIF
RETURN oRet
METHOD Destroy() CLASS TWMP
::oWMP := NIL
RETURN Self
METHOD URL( cFile ) CLASS TWMP
::oWMP:URL := cFile
RETURN Self
METHOD stretchToFit( lOnOff ) CLASS TWMP
::oWMP:stretchToFit := lOnOff
RETURN Self
METHOD enableContextMenu( lOnOff ) CLASS TWMP
::oWMP:enableContextMenu := lOnOff
RETURN Self
METHOD windowlessVideo( lOnOff ) CLASS TWMP
::oWMP:windowlessVideo := lOnOff
RETURN Self
METHOD uiMode( cMode ) CLASS TWMP
::oWMP:uiMode := cMode
RETURN Self
METHOD PlayState() CLASS TWMP
LOCAL nRet := wmppsUndefined
LOCAL bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
BEGIN SEQUENCE
nRet := ::oWMP:PlayState
END SEQUENCE
ERRORBLOCK( bOldError )
DO EVENTS
RETURN nRet
METHOD IsPlaying() CLASS TWMP
LOCAL lRet := .F.
LOCAL bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
BEGIN SEQUENCE
IF ::oWMP:PlayState() = wmppsPlaying
lRet := .T.
ELSE
lRet := .F.
ENDIF
END SEQUENCE
ERRORBLOCK( bOldError )
DO EVENTS
RETURN lRet
METHOD fullScreen( lOnOff ) CLASS TWMP
LOCAL lRet := .F.
LOCAL bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
BEGIN SEQUENCE
IF PCOUNT() > 0
IF ::IsPlaying()
::oWMP:fullScreen := lOnOff
ENDIF
ENDIF
lRet := ::oWMP:fullScreen
END SEQUENCE
ERRORBLOCK( bOldError )
DO EVENTS
RETURN lRet
// ************************ ::oControls *************************
METHOD Play() CLASS TWMP
::oWMP:controls:Play()
ShowRadio( "VREDPLAY" )
RETURN Self
METHOD CurrentPosition( nPosition ) CLASS TWMP
IF PCOUNT() > 0
::oWMP:controls:CurrentPosition := nPosition
ENDIF
RETURN ::oWMP:controls:CurrentPosition
METHOD Pause() CLASS TWMP
::oWMP:controls:Pause()
ShowRadio( "VREDPAUSE" )
RETURN Self
METHOD Stop() CLASS TWMP
::oWMP:controls:Stop()
ShowRadio( "VREDSTOP" )
RETURN Self
METHOD Getcurrentitem() CLASS TWMP
RETURN ::oWMP:controls:currentitem()
// ************************ ::oSettings *************************
METHOD Mute( lMute ) CLASS TWMP
IF PCOUNT() > 0
::oWMP:Settings:mute := lMute
ENDIF
RETURN ::oWMP:Settings:mute
METHOD MoveVolume( nDirection ) CLASS TWMP
LOCAL nVol := ::oWMP:Settings:volume
IF !EMPTY( nDirection )
IF nDirection > 0
nVol ++
IF nVol >= 100
nVol := 100
ENDIF
ELSE
nVol --
IF nVol < 0
nVol := 0
ENDIF
ENDIF
::oWMP:Settings:volume := nVol
ENDIF
RETURN nVol
METHOD Volume( nVolume ) CLASS TWMP
IF PCOUNT() > 0
::oWMP:Settings:volume := nVolume
ENDIF
RETURN ::oWMP:Settings:volume
METHOD AutoStart( lOnOff ) CLASS TWMP
IF PCOUNT() > 0
::oWMP:Settings:autoStart := lOnOff
ENDIF
RETURN ::oWMP:Settings:autoStart
// ************************ ::oCurrentMedia *************************
METHOD Duration() CLASS TWMP
RETURN ::oWMP:currentMedia:Duration
METHOD Getfps() CLASS TWMP
LOCAL nFrameRate := ::oWMP:currentMedia:getItemInfoByType( "FrameRate", "", 0 )
RETURN nFrameRate / 1000
METHOD Getwidth() CLASS TWMP
RETURN ::oWMP:currentMedia:imageSourceWidth
METHOD Getheight() CLASS TWMP
RETURN ::oWMP:currentMedia:imageSourceHeight
METHOD GetVersion()
LOCAL cRet := ""
LOCAL bOldError := ERRORBLOCK( { | e | BREAK( e ) } )
BEGIN SEQUENCE
cRet := ::oWMP:versionInfo
END SEQUENCE
ERRORBLOCK( bOldError )
RETURN cRet
*+ EOF: TWMP.PRG
////////////////////////////////////////////////////////////////////////////////
//
// Automatically generated Header File
//
// Program ID: WMPLAYER.OCX.7
//
// Creation Date: 16.05.05
//
// Creation Tool: TLB2CH.EXE
//
// Copyright (c) Alaska Software. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////
#ifndef WMPLAYER_OCX_7_HAEDER_DAEMON
// Enumeration WMPPlaylistChangeEventType
//WMP Playlist Change Event Type
#DEFINE wmplcUnknown 0
#DEFINE wmplcClear 1
#DEFINE wmplcInfoChange 2
#DEFINE wmplcMove 3
#DEFINE wmplcDelete 4
#DEFINE wmplcInsert 5
#DEFINE wmplcAppend 6
#DEFINE wmplcPrivate 7
#DEFINE wmplcNameChange 8
#DEFINE wmplcMorph 9
#DEFINE wmplcSort 10
#DEFINE wmplcLast 11
// Enumeration WMPOpenState
//State of opening process
#DEFINE wmposUndefined 0
#DEFINE wmposPlaylistChanging 1
#DEFINE wmposPlaylistLocating 2
#DEFINE wmposPlaylistConnecting 3
#DEFINE wmposPlaylistLoading 4
#DEFINE wmposPlaylistOpening 5
#DEFINE wmposPlaylistOpenNoMedia 6
#DEFINE wmposPlaylistChanged 7
#DEFINE wmposMediaChanging 8
#DEFINE wmposMediaLocating 9
#DEFINE wmposMediaConnecting 10
#DEFINE wmposMediaLoading 11
#DEFINE wmposMediaOpening 12
#DEFINE wmposMediaOpen 13
#DEFINE wmposBeginCodecAcquisition 14
#DEFINE wmposEndCodecAcquisition 15
#DEFINE wmposBeginLicenseAcquisition 16
#DEFINE wmposEndLicenseAcquisition 17
#DEFINE wmposBeginIndividualization 18
#DEFINE wmposEndIndividualization 19
#DEFINE wmposMediaWaiting 20
#DEFINE wmposOpeningUnknownURL 21
// Enumeration WMPPlayState
//State of playback
#DEFINE wmppsUndefined 0
#DEFINE wmppsStopped 1
#DEFINE wmppsPaused 2
#DEFINE wmppsPlaying 3
#DEFINE wmppsScanForward 4
#DEFINE wmppsScanReverse 5
#DEFINE wmppsBuffering 6
#DEFINE wmppsWaiting 7
#DEFINE wmppsMediaEnded 8
#DEFINE wmppsTransitioning 9
#DEFINE wmppsReady 10
#DEFINE wmppsReconnecting 11
#DEFINE wmppsLast 12
// Enumeration WMPSubscriptionDownloadState
//State of a download
#DEFINE wmpsdlsDownloading 0
#DEFINE wmpsdlsPaused 1
#DEFINE wmpsdlsProcessing 2
#DEFINE wmpsdlsCompleted 3
#DEFINE wmpsdlsCancelled 4
// Enumeration WMP_WRITENAMESEX_TYPE
#DEFINE WMP_WRITENAMES_TYPE_CD_BY_TOC 0
#DEFINE WMP_WRITENAMES_TYPE_CD_BY_CONTENT_ID 1
#DEFINE WMP_WRITENAMES_TYPE_CD_BY_MDQCD 2
#DEFINE WMP_WRITENAMES_TYPE_DVD_BY_DVDID 3
#define WMPLAYER_OCX_7_HAEDER_DAEMON
#endif //WMPLAYER_OCX_7_HAEDER_DAEMON
DEFINE ACTIVEX oxWMP
PARENT Form_1
ROW 0
COL 0
WIDTH MaxDeskWidth( aSize[ 1 ] )
HEIGHT MaxDeskHeight( aSize[ 2 ] - nTitlebar - nMenusize - nPBheight - nSliderheight - ( nFrame * 6 ) - nSbarheight )
PROGID "WMPlayer.OCX.7"
TOOLTIP "right-click Mouse Menu"
END ACTIVEX
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 93 guests