video frame width and height

video frame width and height

Postby Romeo » Thu Dec 15, 2022 9:12 am

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
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: video frame width and height

Postby Antonio Linares » Thu Dec 15, 2022 10:38 am

Dear Romeo,

I just asked the IA https://beta.openai.com/playground to write the function:
Code: Select all  Expand view  RUN
#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();
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: video frame width and height

Postby Jimmy » Thu Dec 15, 2022 1:24 pm

hi,
Romeo wrote:How can i have the video width and height of a file video ?

you need to "load" Video to get Size e.g. using WMP (Windows Media Player)
Code: Select all  Expand view  RUN
METHOD Getwidth() CLASS TWMP
RETURN ::oWMP:currentMedia:imageSourceWidth

METHOD Getheight() CLASS TWMP
RETURN ::oWMP:currentMedia:imageSourceHeight


---

this CLASS is for HMG but should no Problem to use it with Fivewin
Code: Select all  Expand view  RUN
#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

Code: Select all  Expand view  RUN

////////////////////////////////////////////////////////////////////////////////
//
// 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


Code: Select all  Expand view  RUN
        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
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: video frame width and height

Postby Antonio Linares » Thu Dec 15, 2022 3:08 pm

Dear Jimmy,

many thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: video frame width and height

Postby Romeo » Fri Dec 16, 2022 9:56 am

I am not "a great sw developer"...

I hoped a simple prg, almost ready

I try to do it

Grazie anyhow
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: video frame width and height

Postby Jimmy » Fri Dec 16, 2022 3:33 pm

hi,

what do you want to do with Video :?:

if you want to "play" it you do not need "Size" while Video will use "given Size" to make a "Overlay" where it "play" it
but to "play" Video you need CODE which use OOP and not Function as it work with different Interface of ActiveX

so tell us hole Story what you want to do with Video File
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: video frame width and height

Postby Romeo » Fri Dec 16, 2022 11:30 pm

I downloaded from telegram thousands
Of video files about workout/fitness

There are many different resolution of them and some of them are not
good to show on TV/monitor

I wanna separate them by resolution....

And other works
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: video frame width and height

Postby Jimmy » Sat Dec 17, 2022 1:13 am

hi,

Ok, i understand ... hm

perhaps you can use a "Converter" to get
a.) Information about Source Video
b.) "upscale" to new TV-Format
look at "Handbrake" which use much CPU Power

---

when you have so much Video what do you use as "Player" and how does it connect to TV (Input) :?:

i do use WMP or VLC ActiveX in my App to "play" Video Files
a.) via HDMI of Grafic Card
b.) as "Media"-Server (http in local Network)

both "Player" also can use Internet-Stream (IP-TV) as Source

VLC also have "Record"*** Button and can "convert" Video so you can "save" Internet-Stream on local Drive
***not available in ActiveX

Tip : when Website "detect" a Smartphone it will show Video in other Format as PC which will better "fit" to TV (16:9)
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: video frame width and height

Postby Romeo » Sat Dec 17, 2022 10:42 am

Grazie for info

I simply copy all the video files onto a USB key and insert it into the back of the TV, then run it from the TV remote

It is for a client who has a bodybuilding gym
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)

Re: video frame width and height

Postby Jimmy » Sun Dec 18, 2022 1:07 pm

hi,

open Windows Explorer and navigate into Folder where your Video Files are
right-click at End on Header to open Popup-Menu for Property

now search for "Size" and "bitrate" Property an SET Checkbox
Image

p.s. will not show Property of every Video Type like FLV
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: video frame width and height

Postby Jimmy » Sun Dec 18, 2022 3:12 pm

hi,

for Programmer : File Metadata
https://github.com/Dijji/FileMeta

there is NO *.EXE so App must be build using MSVC
have to figure out how CODE can be used with harbour ...
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1733
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: video frame width and height

Postby Romeo » Sun Dec 18, 2022 10:56 pm

Grazie
Romeo
 
Posts: 340
Joined: Thu Jan 25, 2007 3:53 pm
Location: Milan (Italy)


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests