How to deal with video files

<< Click to Display Table of Contents >>

Navigation:  Image Manager > CVB Technology >

How to deal with video files

 

Introduction

 

This driver realized via the CVBAvi.dll enables access to DirectShow compatible video files via the IGrabber interface of Common Vision Blox.

If the file extension is unknown to the Image Manager function LoadImageFile it automatically loads the CVBAvi driver, the driver then loads the video if it recognizes and supports the video file format.

 

Supported Video files

Supported Interfaces

How to open a video file

Settings and Control of a video file

Control via the Digital IO Interface

Control of a Videofile via the IDeviceControl Interface

Driver Specific Function: Access via GetModule

Access to Metadata via INotify Interface

Videofile parameters in the registry

 

 

Supported Video files

 

The default supported video container formats are *.avi and *.mpg files.

But especially the *.avi container format can have different types of video streams (e.g. DivX, Xvid).

If these video streams are supported depends on the codecs installed on your system.

For example after installing the DivX codec on your machine, this driver is also able to playback DivX encoded video streams.

 

Additional video decoders

For other video streams Windows 7 and newer use the Microsoft DTV-DVD Decoder which is part of the Windows  installation. This decoder is incompatible with CVB.

Because of this other video streams like H.264 are not supported with CVB on Windows by default. The Microsoft DTV-DVD Decoder has to be disabled and another decoder like the LAV Filters or ffdshow filter has to be installed to support other video streams like H.264.

To disable to Microsoft DTV-DVD Decoder search with your favorite search engine in the internet "How to Disable Microsoft Windows 7 built-in Microsoft DTV-DVD Decoder".

 

 

How to open a Video file

 

A Video file ( eg. AVI or MPEG) could be opened via every LoadImage-functionality in CVB.

 

In this case it is opened via a Dialog box :

FiledriverVideo

Methods and functions for loading images

Image Control- LoadImage method

Image Control- LoadImageByDialog method

Image Control- LoadImageByUserDialog method

Image Library- LoadImageFile function

 

 

Supported Interfaces
 

The CVB driver interfaces are implemented by the Driver DLL  with
 

 

IGrab2

 

Image acquisition

 

IImage

Image handling and acquisition (grab and snap)

 

 

IGrabber

Image acquisition

 

 

IBasicDigIO

Controlling the videofile for Playback, goto a dedicated framenumber and more

 

 

IDeviceControl

Controlling the videofile for Playback, goto a dedicated framenumber and more

 

 

INotify

Registration of user defined callbacks for asynchronous driver events. In this case access to Metadata.

 

 

 

and as a number of CVB ActiveX Controls such as the

 

CV Image Control,

CV Grabber Control,

CV Dig IO Control.

 

The documentation for all possible configurations can be found in the Common Vision Blox Manual in the Image Manager chapter.

 

 

Settings and Control of a Videofile

 

The interfaces and the registry entries allow to deal with Videofiles.

With this it is possible to create a simple Videoplayer by your own like it is shown in the following screenshot:

 

The player could:

open a Videofile ( Load Movie),

playback the complete file,

skip to the beginning or end or to the next image frame or previous frame ( +1 -1).

 

The details how this could be handled are explained in the following chapters.

 

Videofile_player

 

 

 

Control of a Videofile via the Digital IO Interface

 

For control tasks that can not be handled with the built-in Grabber Interface of CVB, the DigIO interface of the CVBavi driver has been used.

The functionality could be implemented via the DigIO functions of the Driver Dll or the via the CV DigIO Control.

 

The driver has 32 inputs and 128 outputs that are mainly addressed as dwords. The following tables describe the meaning and use of those portgroups and bits:

 

Digital INPUTS of the CVBavi driver

Portgroup

Bit

Use

Notes

0

1..32

Gives the number of frames in the video file

-

 

Digital OUTPUTS of the CVBavi driver

Portgroup

Bit

Use

Notes

0

1

2

3

4

5

6

7

8

9

10..32

Advance 1 Frame

Rewind 1 Frame

Advance 10 Frames

Rewind 10 Frames

Advance 100 Frames

Rewind 100 Frames

Stop Playback

Start Playback

Rewind to first frame

Unused

Portgroup 0 can only be addressed via the function SetOutBit. SetOutDWord on port group 0 is ignored.

1

1..32

Current Image Number

Can be used to set or retrieve the current frame number. May only be addressed via the function SetOutDWord - SetOutBit is ignored (whereas GetOutBit is working).

2

1..32

Volume

Can be used to set or retrieve the current volume. May only be addressed via the function SetOutDWord - SetOutBit is ignored (whereas GetOutBit is working). Allowable values for the volume are according to DirectShow conventions between -10000 (mute) and 0 (maximum).

3

1..32

Balance

Can be used to set or retrieve the current balance. May only be addressed via the function SetOutDWord - SetOutBit is ignored (whereas GetOutBit is working). Allowable values for the volume are according to DirectShow conventions between -10000 (left) and 10000 (right).

 

Typical statements under Visual C++ would thus look like this:

 

//mute sound

long lVolume = -10000;

SetOutDWORD(0, (DWORD)lVolume, 0);

// or to jump to a desired frame at position

m_cvControl.SetOutDWORD(1, nFrameNumber, 0);

m_cvImg.Snap();

m_cvDisp.Refresh();

 

Note: The 'Mask' parameter of the function SetOutDWORD is ignored by CVBavi).

Addressing the single bits of port group 1 to 3 does not make sense and therefore is ignored by the driver.

Default parameters for volume and balance can be supplied in the registry (see below).

 

Although it is in principle possible to access the same virtual image acquisition device from several images, we do not support this, it is completely impossible when using Live-Replay .

In Single-Frame mode it works, but when n instances of a driver access the same virtual image acquisition device simultaneously, each instance only gets every n-th frame of the video stream.

Before switching to a different virtual board we strongly recommend stopping any background replay by calling a single Snap on the images in question.

 

When using the Single-Frame mode please keep in mind that some codecs support the IMediaSeeking Interface but do not deliver still images, instead they always give back the last key frame (DivX 4 is an example of this behavior). In those cases, working in Single-Frame mode may be dissatisfying.

 

 

Control of a Videofile via the IDeviceControl Interface

 

There are some more features available than with the Digital IO Interface using the IDeviceControl Interface via the IDeviceControl functions of the Driver Dll or the CV Grabber Control.

The features are :

 

DC_VOLUME = 0x00000100, // not supported when there is no audio stream in the AVI

DC_BALANCE =0x00000101, // not supported when there is no audio stream in the AVI

DC_FRAMENUMBER = 0x00000102,

DC_TOTALFRAMENUMBER = 0x00000103,

DC_REPLAYRATE = 0x00000104,

DC_POSITION = 0x00000105,

DC_TOTALTIME = 0x00000106,

DC_JUMPRELATIVE_FRM = 0x00000107,

DC_JUMPSTART = 0x00000108,

DC_FRAMETIME = 0x00000109,

DC_JUMPRELATIVE_TIM = 0x0000010A

 

see header file for Visual C the IDC_AVI.h in the CVB\Lib\C directory.

 

Example code in Visual Basic for retrieving the total framenumber of an AVI-File looks like this:

 CVgrabber1.SendStringCommandEx &H103, DC_GET, " "

 

For sure it is also possible to get the information interactively via the CV Grabber Control like here the Framenumber of the current frame is retrieved ( DC_FRAMENUMBER = 0x00000102)

 

IDeviceControl_Get_Framenumber

 

 

Driver Specific Function: Access via GetModule

 

The function GetModule from CVCDriver.DLL returns the following parameters when used on CVBavi:

 

pGraphBuilder        Handle for the IGraphBuilder Interface

pMediaControl        Handle for the IMediaControl Interface

pBasicAudio                Handle for the IBasicAudio Interface

 

In the GetModule call, AddRef is called on all the returned handles (except if the returned handle is NULL).

Therefore you should - as normally when programming COM - call Release on them whenever you no longer require the resource.

 

The function GetModule is used as follows:
 

Microsoft Visual Basic:

Dim pGraphBuilder as

Long Dim pMediaControl as Long Dim pBasicAudio as Long GetModule(cvImg.Image,pGraphBuilder, pMediaControl, pBasicAudio)

 

Microsoft Visual C++:

IGraphBuilder

*pGraphBuilder; IMediaControl *pMediaControl; IBasicAudio *pBasicAudio; GetModule((IMG)m_cvImg.GetImage(),

1(void**)&pGraphBuilder, (void**)&pMediaControl, (void**)&pBasicAudio);

 

 

Access to Metadata via INotify Interface

 

Meta data are (ANSI-) strings with up to 64k characters, one per image being recorded.

Meta data can be written with the CVB Movie2 Tool. For example, the MetaData can be used to save the corresponding timestamp as a string for every recorded frame within the AVI container.

To read out the MetaData you can implement the CVB Notify Interface (INotify) of the Driver.dll in your own application.

If you prefer the CV Grabber Control you can use the ImageNotificationString Event. As examples the VCMovie2PlayerExample and the CSMovie2PlayerExample are included in Movie2.

 

Please note that some media players may get confused by the presence of a text stream in the AVI container.

When an AVI Editor does not support the text stream the MetaData is lost after editing the AVI file.

For Example VirtualDub with DirectStreamCopy writes only the text of the first frame to all other frames.

 

The supported INotify Event is CVNO_EID_METADATA_CHANGE which is fired when new Metadata has arrived.

 

Following StatusCommands are supported with NOGetStatus:

CVNO_INFO_COUNT_REGISTERED

CVNO_INFO_COUNT_FIRED

CVNO_INFO_IS_AVAILABLE

e.g. If you want to check if MetaData is available for your loaded avi file use CVNO_INFO_IS_AVAILABLE:

 

Sample Code in CSharp

  if (Cvb.Driver.INotify.CanNotify(m_cvImage.Image))

  {

    // Check If MetaData is available in the video file. If yes Register the MetaDataAvailable callback

    // If no Output message in StatusUserText.

    long info = 0;

    Cvb.Driver.INotify.NOGetStatus(m_cvImage.Image,

                                   Cvb.Driver.INotify.CVNotifyEventID.METADATA_CHANGE,

                                   Cvb.Driver.INotify.CVNotifyInfoCmd.IS_AVAILABLE,

                                   out info);

    if (info == 1)

      Cvb.Driver.INotify.NORegister(m_cvImage.Image,

                                    Cvb.Driver.INotify.CVNotifyEventID.METADATA_CHANGE,

                                    MetaDataChangedDelegate,

                                    this.Handle,

                                    out m_MetaDataCallbackCookie);

    else

      _MetaDataTextBox.Text = "No MetaData available";

   }

 

Sample Code in VC

  if(CanNotify((IMG)m_cvImg.GetImage()))

  {

    // Check if MetaData is available in the video file. If yes Register the MetaDataAvailable callback

    // If no Output message in StatusUserText.

    __int64 info;

    HRESULT res = NOGetStatus((IMG)m_cvImg.GetImage(),

                               CVNO_EID_METADATA_CHANGE,

                               CVNO_INFO_IS_AVAILABLE,

                               info);

    if(info == 1)

      res = NORegister((IMG)m_cvImg.GetImage(),

                        CVNO_EID_METADATA_CHANGE,

                        &CVCMovie2PlayerExampleDlg::MetaDataAvailable,

                        this,

                        m_MetaDataAvailableCallbackCookie);

    else

      m_cvDisp.SetStatusUserText("No MetaData available");

  }

 

The description and the functions of the INotify Interface are described in Driver Dll.

Example Code can be found in the INotify Callback description.

 

Videofile parameters

 

There are some parameters which could be set via a Registry entry.

Please create a registry entry in ..Software\Common Vision Blox\\Image Manager\AVI

NumBuffers = 2

Sets the Number of Buffers.Values from 2 to 256

DefaultVolume = 10000

Volume for video playback (can be changed via the DigIO Interface during playback). Valid values range from 0(mute) to 10000 (max). If this parameter is omitted, 10000 is assumed by the driver.

DefaultBalance =10000

Balance for video playback (can be changed via the DigIO Interface during playback). Valid values range from 0 (left) to 20000 (right). If this parameter is omitted, 10000 (center) is assumed by the driver.

Note:

The former INI-file CVBAvi.ini is obsolete.