Lazarus

Programming => Graphics and Multimedia => DirectX => Topic started by: TheBlackSheep on April 29, 2012, 06:20:43 pm

Title: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: TheBlackSheep on April 29, 2012, 06:20:43 pm
Hello Everyone

I've been through the DSPack sources and modified them to work with Lazarus (hopefully they'll still compile with Delphi too).  In the progdigy forums there's mention that the SVN source did work but I couldn't get it to compile without a reasonable amount of changes.

There's probably some stuff that doesn't quite convert correctly (I can't get the VMRBitmap to work the same as it does in Delphi) but thought if other's had a play they may see what's not correct.  Ideally we can submit the modified sources back to progdigy so they can add full(?) support for Lazarus too.

It's currently setup to use the pl_win_directx unit from CodeTyphon so if you don't use this version of Lazarus then you'll probably need to include a different requirement (or possibly convert the DSPack version of the DirectX files instead).

Anyway, the the intial stab at this conversion is here;

https://github.com/TheBlackSheep/DSPack-Lazarus

If anyone spots any errors I'd be grateful if you'd point them out - I'd particularly like to find out why the VMRBitmap doesn't work the way it does on Delphi.

TheBlackSheep
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: count on June 14, 2012, 07:58:28 pm
Thanks for component!
Say, is it possible not to  use pl_win_directx? I've failed with it actually. Thanks!
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: TheBlackSheep on June 16, 2012, 08:12:14 pm
Hi count

if you unzip the clootie DirecX92 pas headers (i.e. the "FPC_DirectX92.zip" file) from here;

http://www.clootie.ru/fpc/index.html (http://www.clootie.ru/fpc/index.html)

into the same folder as the dspack source, together with the DirectShow9.pas file from here;

http://dspack.googlecode.com/svn-history/r7/trunk/src/DirectX9/DirectShow9.pas

you will need to edit this one slightly (it wouldn't compile for me without it)

Code: [Select]
    {$IFDEF FPC}
    // martin begin - changed apPin to "var" because "out" crashes
    function QueryInternalConnections(var apPin: IPin; var nPin: ULONG): HResult; stdcall;
    // martin end
    {$ELSE}
    function QueryInternalConnections(out apPin: IPin; var nPin: ULONG): HResult; stdcall;
    {$ENDIF}

I found this FPC change to the code is unnecessary so just replace all the above with;

Code: [Select]
    function QueryInternalConnections(out apPin: IPin; var nPin: ULONG): HResult; stdcall;

(this may have been necessary on an older verion of FPC and this change is no longer required)

then just remove the pl_win_directx requirement and re-install it.

I still couldn't get the VMRBitmap working with this version the way it does under Delphi but maybe you'll have more success with how you want to use the dspack components.

Best of luck!

TheBlackSheep
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: TheBlackSheep on June 16, 2012, 10:03:52 pm
5 mins of playing around with this and I realised there is no problem VMRBitmap - it does work (although I'm not using it properly) - my problem was with assigning a bitmap image on a form from within a test application to a temporary bitmap,

Code: [Select]
    Bitmap := TBitmap.Create;
    Bitmap.Assign(CurrentImage.Picture.Bitmap);  //<-- this line didn't work although does in Delphi

    VMRBitmap.LoadBitmap( Bitmap );
    VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
    VMRBitmap.DrawTo(0,0,1, 1, trkAlpha.Position/10);
    Bitmap.Free;   

Replacing the line with a direct load from a file, as in;

Code: [Select]
    Bitmap.LoadFromFile(CurrentFileName);       
and I do get a merging of the images (an onionskin effect)

However, I can't seem to turn it off again by loading an "EmptyBitmap" as in;

Code: [Select]
    VMRBitmap.LoadEmptyBitmap(640, 480, pf24bit, clBlack);
    VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
    VMRBitmap.DrawTo(0,0,1,1,0);     

which I've just tested on Delphi and it does turn off fine with the same code.

Anyway, I am trying to concentrate on the 5dpo version (Linux) but thought I'd share that the DSPack & VMRBitmap seems to be working ok albeit I'm still missing something in my code for Lazarus and Delphi versions of the same app.

TheBlackSheep

Edit: creating a bitmap and then loading that is the equivalent of LoadEmptyBitmap and appears to work fine, as in;

Code: [Select]
    Bitmap := TBitmap.Create;
    VMRBitmap.LoadBitmap( Bitmap );
    VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
    VMRBitmap.DrawTo(0,0,1,1,0);
    Bitmap.Free;   
 
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Riccardo Giuliani on June 23, 2012, 04:10:11 pm
Hello TheBlackSheep

I'm trying the alternative solution to avoid CodeTyphon; put the DirectShow9.pas and the FPC_DirectX92 folder both into the dspack for Lazarus folder, commented the FPC related code as suggested... but when I try to compile I get this error:
Code: [Select]
C:\lazarus\DSPack-Lazarus-8584331\DXSUtil.pas(913,74) Fatal: Syntax error, ":" expected but "identifier IID" found

which relates to this code line (in DSXUtil.pas):
Code: [Select]
function QueryInterface( {$IFDEF FPC} constref {$ELSE} const {$ENDIF}IID: TGUID; out Obj): HResult; stdcall;
What I have exactly done is to install the dspack package (with all files inside this folder) and launched its compilation, falling into the above error.

What am I missing?
Don't know if it depends on a previous conflicting configuration of Lazarus, or on other required files not available.
About the first idea, I rebuilt Lazarus: nothing changed.
Second one has come in my mind after reading of this
http://www.clootie.ru/delphi/download_dx90.html#Headers_DirectX90 (http://www.clootie.ru/delphi/download_dx90.html#Headers_DirectX90)

I'm using Lazarus 0.9.30 and FPC 2.4.2 on Windows XP.

Hope someone could help me. Thanks
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Andru on June 23, 2012, 04:28:34 pm
Quote
I'm using Lazarus 0.9.30 and FPC 2.4.2 on Windows XP.
This version of FPC missing constref, try to use FPC 2.6.0
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Riccardo Giuliani on June 24, 2012, 11:02:27 am
Upgraded to FPC 2.6.0, and the compiler goes well... until it stops due to this error
Code: [Select]
C:\lazarus\DSPack-Lazarus-8584331\BaseFilterEditor.pas(887,16) Error: Identifier not found "BrushCopy"
related to
Code: [Select]
BrushCopy(Bounds(Rect.Left + Offset, Rect.Top, Bitmap.Width, Bitmap.Height),
          Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clOlive);  {render bitmap}
inside procedure TFormBaseFilter.PinsDrawItem.

I looked for explanations on internet, and found that this problem seems quite recent, from bugtracker http://62.166.198.202/view.php?id=8047 (http://62.166.198.202/view.php?id=8047); and here the status is set to resolved.
Don't know what to do. Anybody knows?
Thanks
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: BigChimp on June 24, 2012, 11:49:24 am
Haven't looked at the bug, but instead of FPC 2.6.0, you could use FPC 2.6.1 (the fixes 2.6 branch), which contain stability updates to 2.6.0.

Also, check the bug report for which version it was fixed. It may be for 2.7 (current trunk/development version). A fix may have been backported to (implemented in) FPC 2.6.1, but not to 2.6.0 as that release will not be changed.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Riccardo Giuliani on June 24, 2012, 11:57:59 am
You're right, the fix is just for Lazarus 0.9.31 SVN, while I'm actually using 0.9.30.4.
This even if my SVN revision is 35940, and the fixed one is 35134.
Anyway, I must try the 0.9.31 to be sure.
Thanks again.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Riccardo Giuliani on June 24, 2012, 05:34:29 pm
Ok
With snapshot Lazarus-1.1-37738-fpc-2.6.1-20120623-win32.exe dspack has been finally installed; not tested if it works, but now controls are available.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on January 15, 2013, 06:08:02 am
I've been using the DSPack bundled with CodeTyphon 2.9 (Lazarus 1.1) for the past week or so, and other than some form inheritance issues (which were easy enough to work around - just dynamically create the controls at run time), it's all been smooth sailing.  Haven't tried capture or DVD yet, just video playback.

Kicking myself actually.  Around 2003/2004 I created similar code to DSPack, based on the Clootie headers.  Looking at the copyright dates for DSPack, looks like I could have avoided months of work back then :-)

Does anyone know if the DSPack used in CodeTyphon is the port completed by TheBlackSheep?
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 15, 2015, 10:24:03 am
Hello everyone.
I would like to use DSPack components for my project with Lazarus.
I Lazarus Ver. 1.2.6 with FPC 2.6.4 in windows 7 32 bit

I have done this:
1) download from DSPack
https://github.com/TheBlackSheep/DSPack-Lazarus (https://github.com/TheBlackSheep/DSPack-Lazarus)
2) download "FPC_DirectX92.zip" extract files in the directory DSPack

http://www.clootie.ru/fpc/index.html (http://www.clootie.ru/fpc/index.html)
3)
   Download DirectShow9.pas file, copied to the directory DSPack
http://dspack.googlecode.com/svn-history/r7/trunk/src/DirectX9/DirectShow9.pas (http://dspack.googlecode.com/svn-history/r7/trunk/src/DirectX9/DirectShow9.pas)
I remove from package "pl_win_directx", and compiled package.
Error in "BaseClass.pas" file

Quote
    // martin begin
    //result := ti.Invoke(Pointer(Integer(Self)), DISPID, Flags, TDispParams(Params),
    //  Variant(VarResult^), ActiveX.EXCEPINFO(ExcepInfo^), UINT(ArgErr^));
    // martin end   
I replaced it with:
Quote
result := ti.Invoke(Pointer(Integer(Self)), DISPID, Flags, TDispParams(Params),
      VarResult, ExcepInfo, ArgErr);

Package successfully compiled and installed, now palette DSPack components OK.
Perform a test project with components:
TFilterGraph, TVideoWindow a button to do this:
Quote
    if not FilterGraph.Active then
         begin FilterGraph.Active := true; end;     ( ERRORE in RUN : exsternal SIGSEGV.   Errore di classe. )

   FilterGraph.ClearGraph;
    FilterGraph.RenderFile('C:\film\01\01.mp4');
    FilterGraph.Play;

Can anyone tell me where I went wrong? Help please.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on February 18, 2015, 06:47:01 am
Can't see anything obviously wrong with the little code snippet you've posted.  You haven't shown how've connected the different components together...

The port by TheBlackSheep is reasonably stale.  The guys over at PilotLogic took this work and expanded it a little, fixing some other items.  http://www.pilotlogic.com/sitejoom/index.php/codetyphon

To the best of knowledge (it's now been over a year since I last checked), you cannot independently download their DirectX and DSPack components.

*cough*  I took a copy of their work middle of last year.  It's here if you want it...
https://svn.code.sf.net/p/lazarusvideoutilities/code/trunk/Packages/

(Yeah, don't look too closely at that SourceForge project, though the code in the link posted is good.  It was in the days when I thought I would have free time in my future: that hasn't happened and that project (and others) has languished)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 23, 2015, 08:23:16 pm
Mike.Cornflake Thanks for your response.
I after many attempts I have installed pl_Win_DirectX, pl_Win_DSPack
Quote
http://www.pilotlogic.com/sitejoom/index.php/forum/pl-win-dspack/2153-lab-pl-win-dspack-tests
This package works.

Now I study examples to understand this technology.
I found an example that is what I want to do:
Quote
http://tutoriels.pecaudchristopher.com/TutorielDSPACK234Delphi.php
I have some problems, but I hope I can achieve this example of the tutorial.

For now, I thank you and excuse me for writing post late.
And you excuse for my english
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 26, 2015, 01:21:43 pm
I need to find example DSPack to use DeckLink card or other similar card for video output?
In dspack \ samples I do not understand how.
In internet I have not found such to be studied to make my project.
I manage to capture and video from web cam input, I can play video from harddisk, and see in Tvideowindows component. I would like this in analog TV connected to my DeckLink Card.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on February 26, 2015, 02:36:40 pm
I need to find example DSPack to use DeckLink card or other similar card for video output?
...I would like this in analog TV connected to my DeckLink Card.

Find and run a binary of the following (AMCap).  If it can see your card, then you can control the card via DirectShow.

https://msdn.microsoft.com/en-us/library/windows/desktop/dd373424(v=vs.85).aspx

To find the binary, download and install Windows SDK (back in my day it was in a separate DirectX SDK, looks like they've merged...)

Back in the old DirectX SDK, there was very comprehensive documentation for the AMCap sample.  I wrote a DVR in Delphi based off that documentation.  Hopefully it's still there in the Windows SDK...   And before you ask, I don't have any of the DVR code, I was working under contract for that and handed all code over...

If you don't want to download the entire SDK just to test viability, then I've added a build of AMCap to SourceForge...

http://sourceforge.net/p/lazarusvideoutilities/code/HEAD/tree/trunk/DirectShow%20Samples/

As for using AMCap, looks like someone has put together a decent FAQ

http://noeld.com/amfaq.htm

So yeah:

Step 1:  Confirm that card is able to be controlled DirectShow by AMCap
Step 2:  Either plough through the AMCap sourcecode from the SDK, or the documentation and work out what's next...  I'd recommend both...
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 26, 2015, 07:41:53 pm
Thanks Mr. Mike.Cornflake
 I will do as you suggested.  :D
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 27, 2015, 11:43:32 am
yes, my card is recognized by AMCAP.
I do a test with:
Quote
SysDev:= TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
    if SysDev.CountFilters > 0 then
    begin
      for i:= 0 to SysDev.CountFilters - 1 do
         ListBox1.Items.Add(SysDev.Filters.FriendlyName);
    end;                                                         
I see my DeckLink card and my web-cam.
I look for a way to use DeckLink video output analogic.
I have not found an example code for this.  :-\
----------------------------------------------------
other problem:
1) with properties BaseFilter click (TBaseFilter). ( error in Properties click )
 2) FilterGraph1 GraphichEdit: = True (error in run)
 graphedt.exe not see my video files to run the application.
 I have installed:
 pl_Win_DirectX.zip (824KB) and pl_Win_DSPack.zip (270KB) of Mr. Sternas,
http://www.pilotlogic.com/sitejoom/index.php/forum/pl-win-dspack/2153-lab-pl-win-dspack-tests?limitstart=0 (http://www.pilotlogic.com/sitejoom/index.php/forum/pl-win-dspack/2153-lab-pl-win-dspack-tests?limitstart=0)
 I have installed and tried WindowsSDK 8.1 or WindowsSDK 7.1 .
 I have win7 32bit

Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on February 27, 2015, 12:03:24 pm
yes, my card is recognized by AMCAP.

Excellent news.

I have not found an example code for this.  :-\

I'll have a quick look around tonight and get back to you.  I'm diving back into DirectShow to help someone else anyway...

A lot of the sample code out there is C++, you will likely have to do some translation yourself along the way...

2) FilterGraph1 GraphichEdit: = True (error in run)

I reported this to PilotLogic myself two years ago (in the same thread your referencing).    I've already tried and failed to fix this myself - though if someone else could, that would be great :-)   To workaround, simply set GraphEdit := False.  It's required for the RunningObjectTable, which is useful for debug purposes.  Essentially, with GraphEdit := True, you have the ability to view (and manipulate) your running Graph in GraphEdit.    By setting it to false, you just lose this visual debug tool.

1) with properties BaseFilter click (TBaseFilter). ( error in Properties click )

Absolutely nothing anyone can do to help you with this without you sharing code :-(   I've tried trying to glimpse your code in the supplied screenshots, but it's just enough.  Please post code (as full as possible) and highlight the line the error occurs on.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 27, 2015, 12:39:23 pm
Quote
I reported this to PilotLogic myself two years ago (in the same thread your referencing).    I've already tried and failed to fix this myself - though if someone else could, that would be great :-)   To workaround, simply set GraphEdit := False.  It's required for the RunningObjectTable, which is useful for debug purposes.  Essentially, with GraphEdit := True, you have the ability to view (and manipulate) your running Graph in GraphEdit.    By setting it to false, you just lose this visual debug tool.
ok i've understood. work without.
----------------------------------------------
Quote
Absolutely nothing anyone can do to help you with this without you sharing code :-(   I've tried trying to glimpse your code in the supplied screenshots, but it's just enough.  Please post code (as full as possible) and highlight the line the error occurs on.
example: I have a form and insert Tfilter object ispector click TBaseFilter. (Here error)
in attaching I put what I should have, I receive error.
 This is BUG of DsPack component?
------------------------------------------
I await your response to make work DeckLink video output.
 thanks very much  ;)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 27, 2015, 12:49:37 pm
I found this very interesting to understand DSpack work:
Quote
http://www.vwlowen.co.uk/directshow/page01.htm
  ;)
I asked author tutorial to help me for DeckLink Out-put, he replied that they can not help  :-\

P.S.:
"Blackmagic DeckLink SDK 10.1" there is this example to use DeckLink and DsPack
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on February 27, 2015, 04:52:59 pm
I've submitted a patch for the RunningObjectTable issue.  Unfortunately I *think* I need a 64bit GraphEdt to confirm, and I currently can't find one...

http://bugs.freepascal.org/view.php?id=27555
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on February 28, 2015, 12:47:10 pm
cited Mike.Cornflake
Quote
I'll have a quick look around tonight and get back to you.  I'm diving back into DirectShow to help someone else anyway...

A lot of the sample code out there is C++, you will likely have to do some translation yourself along the way...
I found this old tutorial for Delphi:
http://tutoriels.pecaudchristopher.com/TutorielDSPACK234Delphi.php (http://tutoriels.pecaudchristopher.com/TutorielDSPACK234Delphi.php)
this tutorial do what my serve.
I try to realize application, attached my example.
You able to watch this and my help? because my application is not working.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 11, 2015, 09:49:56 am
Hello
 how to change the format type to media video?
 which filter to use?
 I have to use format standard out: 720x576
Quote
hr := (fgRender as IGraphBuilder).AddSourceFilter(StringToOleStr('C:\film\01\video.mp4'),
 'Source Filter', SourceFilter);

Quote
ZeroMemory(@Mt, sizeof(AM_MEDIA_TYPE));
 Mt.MajorType := MEDIATYPE_Video;
 Mt.SubType := MEDIASUBTYPE_RGB32;
 Mt.FormatType := FORMAT_MPEG2_VIDEO;
 Mt.cbFormat := sizeof(MPEG2VIDEOINFO) + sizeof(SegHdr);
 Mt.pbFormat := CoTaskMemAlloc(Mt.cbFormat);
 ZeroMemory(Mt.pbFormat, Mt.cbFormat);

 RCSRC.Left := 0;
 RCSRC.Top:= 0;
 RCSRC.Right := 0;
 RCSRC.Bottom := 0;

 pWIH.hdr.rcSource := RCSRC;
 //*****
 pWIH.hdr.rcTarget.Left:=0;
 pWIH.hdr.rcTarget.Top:=0;
 pWIH.hdr.rcTarget.Bottom:=576;
 pWIH.hdr.rcTarget.Right:=720;

 // pWIH.hdr.rcTarget := Rect(0,0,720,576);
 //****
 pWIH.hdr.AvgTimePerFrame := 333667;
 // pWIH.hdr.AvgTimePerFrame := 278335;
 pWIH.hdr.dwPictAspectRatioX := 4;
 pWIH.hdr.dwPictAspectRatioY := 3;
 pWIH.hdr.bmiHeader.biSize := 40;
 pWIH.hdr.bmiHeader.biWidth := 720; //720
 pWIH.hdr.bmiHeader.biHeight := 576; //480
 pWIH.cbSequenceHeader := sizeof(segHdr);

 CopyMemory(@pWIH.dwSequenceHeader, @segHdr, sizeof(seghdr));

https://msdn.microsoft.com/en-us/library/windows/desktop/dd407277(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/dd407277(v=vs.85).aspx)
This works only MPG2 file.

 how can I work with all video formats?
 and which filter to use?
***********************************************
https://msdn.microsoft.com/en-us/library/windows/desktop/dd407277(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/dd407277(v=vs.85).aspx)
can I use this for my project?
 There is an example code with DSpack e pascal Lazarus language?


 thank you for help me.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 11, 2015, 07:01:02 pm
Hello
 how to change the format type to media video?
 which filter to use?

While I got mediatypes working 12 years ago (sigh) - I no longer have that code with me (company owned code).  For my recent DSPack work, I've only ever been interested in playing video - and for that, the general FilterGraph.RenderFile is more than sufficient...

This works only MPG2 file.

 how can I work with all video formats?
 and which filter to use?

As I say, with regards to MPEG-2, I've only ever ensured a valid codec is installed on the system, then used the standard FilterGraph.RenderFile('C:\film\01\video.mp4') to play the video.   

If insufficient filters exist in the graph, then RenderFile adds video/audio renderers (as required) then attempts to build up the graph between them. RenderFile then attempts to connect all the pins together using the most valid mediatypes - automatically. 

Looks like you're attempting to do something other than play video...  So I've no concrete advice, only ideas. 

Try adding a consumer of some sort to the graph (video renderer, file writer - whatever it is you're trying to do), add whatever other filters you need.  Don't attempt to connect any pins, don't attempt to set any mediatypes.  Once everything is in the FilterGraph - try calling FilterGraph.RenderFile(<source filename>).

Here's some sample code of me adding a Filter to the FilterGraph before calling RenderFile...  And in this case, just happens to be a MPEG2 filter...

Code: [Select]
Function TFrameDirectShowVideo.Play: Boolean;
Const
  CLSID_MOONLIGHT_ELECARD_DECODER_2: TGUID = '{F50B3F13-19C4-11CF-AA9A-02608C9BABA2}';
  CLSID_MOONLIGHT_ELECARD_DECODER_4: TGUID = '{BC4EB321-771F-4E9F-AF67-37C631ECA106}';
Var
  oFilter: IBaseFilter;
  sExt: String;
Begin
  Result := False;

  If Assigned(FDSFilterGraph) And FileExists(FFilename) Then
    If FDSFilterGraph.State = gsPaused Then
      Result := FDSFilterGraph.Play
    Else
    Begin
      FDuration := -1;

      If FDSFilterGraph.Active Then
        FDSFilterGraph.Active := False;

      oFilter := nil;

      FDSFilterGraph.Active := True;

      sExt := Lowercase(ExtractFileExt(FFilename));

      // Having to do this in case the Microsoft DVD Decoder is in town...
      If (sExt = '.mpg') Or (sExt = '.pkt') Then
        If SUCCEEDED(CoCreateInstance(CLSID_MOONLIGHT_ELECARD_DECODER_2,
                                 nil, CLSCTX_INPROC_SERVER, IID_IBaseFilter, oFilter)) Then
          FDSFilterGraph.AddFilter(oFilter, 'Elecard MPEG2 Video Decoder')
        Else If SUCCEEDED(CoCreateInstance(CLSID_MOONLIGHT_ELECARD_DECODER_4, nil,
                                        CLSCTX_INPROC_SERVER, IID_IBaseFilter, oFilter)) Then
          FDSFilterGraph.AddFilter(oFilter, 'Elecard MPEG2 Video Decoder');

      FDSFilterGraph.RenderFile(WideString(FFilename));

      Result := FDSFilterGraph.Play;
    End;
End;

RenderFile will always attempt to use the Filters already existing in the graph *before* adding any new ones.  On Windows 7 and above - when playing video, Microsoft have started breaking the DirectShow Filter Priorities, and instead just inserts a Microsoft filter for handling MPEG-2.  I don't know why they do that - I've never seen it work.  So the above code is me forcing a filter I know works into the Graph so that DirectShow won't add the Microsoft one...
 
(Don't worry about the .pkt extension.  It is probably very specific to just the industry I work in...)

Who knows - This approach might work for you...  Sorry if it doesn't - I'm not in a position to research further...

Depends on where you got your DSPack from, you may need to move Procedure AddFilter(AFilter: IBaseFilter; sName : UnicodeString);  in DSPack.pas to Public.   (Change already made in my copy, not done in PilotLogic's version)

The above  code should play ANY video for which there is a valid DirectShow codec installed on the system...  I've only had a quick look, but I'm having some problems sourcing a decent DirectShow mp4 filter...   In all honesty, for playback I'm in the process to switching to mplayer/ffmpeg routines as I'm tired of endlessly ensuring the correct codecs are installed on client PCs...
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 11, 2015, 07:36:55 pm
thank you very much for your response.
 I must use :
Quote
hr := ICapGraph.RenderStream(nil,nil, SourceFilter, nil, VideoWindow1 as IBaseFilter);
 hr := ICapGraph.RenderStream(nil,nil, InfinitePinFilter, nil, IVideoRenderFilter);
because I have to see the video of "VideoWindows" application on the desktop and in out-put DeckLink card.

in the window on the desktop work all formats. The DeckLink card I have to send a 720x576 video "TV standard".
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 11, 2015, 07:48:48 pm
thank you very much for your response.
 I must use :
Code: [Select]
hr := ICapGraph.RenderStream(nil,nil, SourceFilter, nil, VideoWindow1 as IBaseFilter);
 hr := ICapGraph.RenderStream(nil,nil, InfinitePinFilter, nil, IVideoRenderFilter);[/quote]

Yes, I remember now.  RenderFile was good for one-path graphs, not for the InfiniteTee...

UPDATE:  Doh!  I don't even think RenderFile is available on the CaptureGraphBuilder - only on the FilterGraph - sorry for the misdirection...

Have you found the example code that ships with PilotLogic's CodeTypon? 

There were a lot of DSPack examples in there.  I'm hoping one was for WebCams, because what you're doing is functionality similar to that scenario...  (Display WebCAM video + record encoded video)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 11, 2015, 07:59:10 pm
Wait :-(

Can you explain simply what it you're trying to achieve?  I'm trying to get a picture of the graph you need.  I've been thinking you're using the DeckLink card for video capture.  I now doubt that...

From what you've said, and forgetting audio, I now think you're doing something like this...

  File.mp4 --> DeckLink Decoder --> VideoRenderer

But I can't see the need for an InfiniteTee in there...

(I had thought you were doing:

DeckLink Encoder --> InfiniteTee --> Video Renderer
                                         |
                                         +-------> File Writer  )
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 12, 2015, 10:51:24 am
My project :
---------------------------------------------------------------------
Play List   --> Infinite tee  --> Monitor PC
                                      --> DeckLick          --> TV analogical
                     Infinite tee --> Default Audio PC
                                      --> DeckLinkAudio --> TV analogical
------------- attached diagram in the post ------------------------
I work with DSPack  "PilotLogic's CodeTypon"
http://www.pilotlogic.com/sitejoom/index.php/forum/pl-win-dspack/2153-lab-pl-win-dspack-tests (http://www.pilotlogic.com/sitejoom/index.php/forum/pl-win-dspack/2153-lab-pl-win-dspack-tests)

my code:
Component DSpack in the form  : 1) Tfiltergraph.name := fgRender;       
                                                 2)  TVideoWindow1.name := VideoWindow1;
Quote
procedure TForm1.Button1Click(Sender: TObject);
const sVideoRenderCategory: string ='External Renderers';
      sVideoRender:string = 'Decklink Video Render';
var
     i,j                                    : integer;
     SysDev, FilterEnum                     : TSysDevEnum;

     CLSID_VideoRender, G                   : TGUID;


     IVideoRenderFilter,
     SourceFilter, EstAudioInterFilter,
     IVideoWindows,
     DefaultAudioFilter,
     InfinitePinFilter,
     DemultiplexFilter,
     InfinitePinFilterAudio,
     ResizeVideoRenderer                     : IBaseFilter;


      // type media
     mt     : AM_Media_Type;
     rcSrc  : Rect;
     SeqHdr : array of Byte;

     pWIH : TMPEG2VIDEOINFO;



begin
  fgRender.ClearGraph;
 (fgRender as IGraphBuilder).QueryInterface(IID_IMediaControl, mc);
 (fgRender as IGraphBuilder).QueryInterface(IID_IMediaEvent, mEvent); 
//******************* assegn file video  ******************
hr := (fgRender as IGraphBuilder).AddSourceFilter(StringToOleStr('C:\film\video720x576.mpg'),
    'Source Filter', SourceFilter);   
//***********************************************************
//***********  Add filter External device   DeckLink ***************
SysDev:= TSysDevEnum.Create;
for i:= 0 to SysDev.CountCategories-1 do
  begin
  if SysDev.Categories.FriendlyName = sVideoRenderCategory then
    begin
   G:=SysDev.Categories.CLSID;
   FilterEnum:=TSysDevEnum.Create(G);
   for j:= 0 to FilterEnum.CountFilters-1 do
      begin
      if FilterEnum.Filters[j].FriendlyName= sVideoRender then
        begin
        CLSID_VideoRender:=FilterEnum.Filters[j].CLSID;
        break;
        end;
      end;
    end;
  end;
SysDev.Free;
FilterEnum.Free;

hr := CoCreateInstance(CLSID_VideoRender,nil, CLSCTX_INPROC_SERVER,
                      IID_IBaseFilter,IVideoRenderFilter);

//(fgRender as IGraphBuilder).AddFilter(IVideoRenderFilter,'Decklink Video Render');
(fgRender as IGraphBuilder).AddFilter(IVideoRenderFilter,PWideChar(sVideoRender));

//****************add filter AUDIO DECKLINK ***************

   SysDev:= TSysDevEnum.Create;
for i:= 0 to SysDev.CountCategories-1 do
  begin
  if SysDev.Categories.FriendlyName = 'Audio Renderers' then
    begin
   G:=SysDev.Categories.CLSID;
    FilterEnum:=TSysDevEnum.Create(G);
   for j:= 0 to FilterEnum.CountFilters-1 do
      begin
//    if FilterEnum.Filters[j].FriendlyName = 'Altoparlanti (Blackmagic Audio)' then
      if FilterEnum.Filters[j].FriendlyName = 'Decklink Audio Render' then
        begin
        CLSID_AudioRender:= FilterEnum.Filters[j].CLSID;
        break;
        end;
      end;
    end;
  end;
SysDev.Free;
FilterEnum.Free;
hr := CoCreateInstance(CLSID_AudioRender, nil,
                       CLSCTX_INPROC_SERVER, IID_IBaseFilter,
                  EstAudioInterFilter);
(fgRender as IGraphBuilder).AddFilter(EstAudioInterFilter,'Decklink Audio Render');   
//****************add filter  Default DirectSound Device ***********
    SysDev:= TSysDevEnum.Create;
for i:= 0 to SysDev.CountCategories-1 do
  begin
  if SysDev.Categories.FriendlyName = 'Audio Renderers' then
    begin
   G:=SysDev.Categories.CLSID;
    FilterEnum:=TSysDevEnum.Create(G);
   for j:= 0 to FilterEnum.CountFilters-1 do
      begin
      if FilterEnum.Filters[j].FriendlyName = 'Default DirectSound Device' then
        begin
        CLSID_AudioRender:= FilterEnum.Filters[j].CLSID;
        break;
        end;
      end;
    end;
  end;
SysDev.Free;
FilterEnum.Free;
hr := CoCreateInstance(CLSID_AudioRender, nil, CLSCTX_INPROC_SERVER,
                       IID_IBaseFilter, DefaultAudioFilter);
(fgRender as IGraphBuilder).AddFilter(DefaultAudioFilter,
                              'Default DirectSound Device');

 //*************************************************************
 //***************add filter - Infinite Pin Tee Filter VIDEO *******

 hr := CoCreateInstance(CLSID_InfTee, nil, CLSCTX_INPROC_SERVER,
                        IID_IBaseFilter, InfinitePinFilter);
(fgRender as IGraphBuilder).AddFilter(InfinitePinFilter,'Infinite Pin Tee Filter');

//*********************************************************
//****************** create GRAPH ****************************

 hr := CoCreateInstance(CLSID_CaptureGraphBuilder2, nil, CLSCTX_INPROC_SERVER,
                        IID_ICaptureGraphBuilder2, ICapGraph);
 ICapGraph.SetFilterGraph(fgRender as IGraphBuilder);
                 //*****************


 hr := ICapGraph.RenderStream(nil,nil, SourceFilter, nil, VideoWindow1 as IBaseFilter);
 hr := ICapGraph.RenderStream(nil,nil, InfinitePinFilter, nil, IVideoRenderFilter);

   // **********  add filter  InfinitePinFilterAudio *******
       hr := CoCreateInstance(CLSID_InfTee, nil, CLSCTX_INPROC_SERVER,
                                    IID_IBaseFilter, InfinitePinFilterAudio);
      (fgRender as IGraphBuilder).AddFilter(InfinitePinFilterAudio,'Infinite Pin Tee Filter');

  //****************************************************
 hr := ICapGraph.RenderStream(nil,nil, SourceFilter, nil, DefaultAudioFilter);
 hr := ICapGraph.RenderStream(nil,nil, InfinitePinFilterAudio, nil, EstAudioInterFilter);

  //**************** RUN GRAPH  ************************   
 fgRender.Play;
 mc.Run;
 //****************************************************
To see the graph with GraphEdit I use this function, because pl_Win_DSPack has a bug with GraphEdit property = true.
Quote

function TForm1.saveGRF(fichier:widestring;fg:TFiltergraph):Boolean;

var  hr:Hresult;
     pStorage:IStorage;
     pStream:IStream;
     pPersist:IPersistStream;

begin
    result:=false;
 try
  try
   hr:= StgCreateDocfile(pwidechar(fichier),STGM_CREATE or STGM_TRANSACTED or
                         STGM_READWRITE or STGM_SHARE_EXCLUSIVE,0, pStorage);

   if FAILED(hr) then exit;
    hr:= pStorage.CreateStream('ActiveMovieGraph',STGM_WRITE or STGM_CREATE or
                               STGM_SHARE_EXCLUSIVE,0, 0, pStream);
      if FAILED(hr) then exit;

    fg.QueryInterface(IPersistStream,pPersist);
    hr:= pPersist.Save(pStream, TRUE);
      if FAILED(hr) then exit;
    pStorage.Commit(STGC_DEFAULT);
      if FAILED(hr) then exit;
    result:=true;

except
end;
 finally
  pStorage:=nil;
  pStream:=nil;
  pPersist:=nil;
 end;

end;                       
I send graphic attached
-------------------- My problem -----not see all format video-------------------
Now my project with video.mpg2 720x576 works!
If I run different video format, eg DivX or MPEG HD video, I see on the desktop "videowindows" I do not see in DeckLink -> TV.
Audio, I feel speacker PC and -> DeckLink -> TV ok!
---- -----    ------- -----------  ------------  ----  --------
sorry for my english language, helps me google translate  :-\
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 13, 2015, 02:46:57 am
Excellent set of information there, many thanks.

Err.  Disclaimer.  Although I'm trying to help, please remember it's 12 years since I played with DirectShow.  That's a *long* time ago :-)

Secondly:  I apologise.  I know English isn't your first language, yet still I talk alot :-(

Now, Nothing to do with the subject at hand.  You're using [ quote ] tags for your code.  Instead use [ code ] tags. (obviously, no spaces - I'm adding those so the tags don't get rendered).  Using [ quote ], your [ i ] indexes get interpreted as Start Italics.  On the other hand, if you use [ i ] inside a [ code ] tag, the forum knows not to start italics.

Next, unfortunately I can't open your .grf file as I don't have the right filters installed.  That doesn't matter though as the graphic you included tells me everything I needed to know.  UPDATE:  Nope, I now doubt your graphic.  Can you post a screenshot of GraphEdit?

Off topic: I'm nicking your code to generate .grf files - that's brilliant :-)

Other observations:
FilterEnum:=TSysDevEnum.Create(G)

Nice.  I missed that the DSPack had this helper, and was still relying on the DirectShow enumerations...   Does the following replacement work?

Code: [Select]
   SysDev:= TSysDevEnum.Create(CLSID_AudioRendererCategory);
  CLSID_AudioRender := SysDev.Filters[SysDev.FilterIndexOfFriendlyName('Decklink Audio Render')].CLSID;
  SysDev.Free;

UPDATE: original post edited.  It was all speculation and now I've found a DeckLink sample, there was no need for it...
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 13, 2015, 03:40:15 am
I've just downloaded and gone quickly through the Decklink SDK.  If you haven't already, I recommend you do so.  Under Win/DirectShow/Sample/Bin there is a file called DeckLinkPlayback.exe.  Looks to me like that app does what you're after.  Play with the binary, see if it works with your sample video files.  if it does, go through the source code and decode that :-)

One thing I find interesting... See the attached image, which is from DecklinkplaybackDlg.cpp, line 445...  Don't worry about the Sample Grabber, that's just for frame grabs.  Looks like you have the correct graph design, not me...

The code that immediately follows that is conceptually similar to yours.  If their application works, and your doesn't, then compare the two and find the differences.  Doesn't matter that their code is C++, you'll find that you'll easily recognise the various DirectShow calls.



Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 13, 2015, 12:39:02 pm
Hi Mike.Cornflake
thanks for your help, sorry for my error in the post " code and Quote"  :-X

I read in DecklinkPlaybackDlg.cpp
Blackmagic DeckLink SDK 10.1 \ Win \ DirectShow \ Samples \ DecklinkPlayback

I confused  %) %)  I study example in this file cpp.
I definitely wrong in connecting PIN and connect filters.

i want to understand this: ( line 582 )
Code: [Select]
hr = CDSUtils::ConnectFilters(m_pGraph, pInfiniteT, NULL, m_pVideoRenderer, NULL);***************************************
attach 2 screenshots graph generate my application ( Graph_generate.jpg)
, 4 filter not connected, video works! ( videowindow and DeckLink, audio works in PC and DeckLink)
Graph as connected all filters, ( Graph_correct_from_graphEdit.jpg)

attach 2 foto:
1) run video 720x576     mpg2    ( Video720x576mpg2.jpg )
2) run video 1920x1080  mpg2   ( video1920x1080-mpg2.jpg )

the same result with:
DecklinkPlayback.exe

Note: my project takes 4 seconds to start video after clicking play. :-\
this can be unseated by filters, and intelligent connection takes a long time

PS: mini monitor is connect with BlackMagic card ( DeckLink ) composite connections
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 13, 2015, 12:54:05 pm
in "DecklinkPlaybackDlg.cpp" filter is used (Sample Grabber), in DSPack there (TSampleGrabber component) this can be used to resize video? O only works to freeze a bmp file?

If this works for resize video, you can help to write code?
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 13, 2015, 08:02:29 pm
Quote
sorry for my error in the post

:)  Everyone does it at the start.  No problems.

Quote
i want to understand this: ( line 582 )
Code: [Select]
hr = CDSUtils::ConnectFilters(m_pGraph, pInfiniteT, NULL, m_pVideoRenderer, NULL);

Does what it looks like.  Finds the output pin on the InfiniteTee, and connects it to the input pin on the VideoRender.  It's such an amazingly useful function that I've never understood why the DirectShow API doesn't have similar in it.   Nearly every DirectShow application you find on the net will have this function, or similar, implemented somewhere.  I expected DSPack to already have this helper function, but, yeah..., couldn't find it...

In the DeckLink SDK folder, find Win\DirectShow\Samples\Common\Utils.cpp.  The single line above calls one of the functions in this file.

In there, you will find two functions named ConnectFilters.  Both do the same job, just with different parameters.  You should be able to simplify this by using the DSPack PinEnum (and in fact there was an example of a very similar function in the earlier code you posted (DecklinkKeyDSPackTest.zip) that uses PinEnum)

in "DecklinkPlaybackDlg.cpp" filter is used (Sample Grabber), in DSPack there (TSampleGrabber component) this can be used to resize video?

I've been asking myself the very same question.  I've only ever used it to grab a bitmap.  There's nothing about resizing in the documentation, but I can't see why DeckLink have put it in the graph...

If this works for resize video, you can help to write code?

Nope...   I'm on a vessel off New Zealand working 12 hours a day, 7 days a week.   Helping out here during coffee breaks (errr, and when no-one is looking) :-)  And no, no need to apologise, I'm loving this puzzle :-)


BUT


Quote
the same result with:
DecklinkPlayback.exe

This actually changes everything :(   Is the card actually capable of what you're trying to do?   I would send Blackmagic an email confirming this.  If their own sample code doesn't do the job...

UPDATE 1:  Oh, you still have one option to play with.   Load the correct graph into GraphEdit, and ensure one of the non-working video files are at the front.  Now right-click on random output pins and choose properties.  See if you can find one that allows you to resize the video and that works when you click play (should be the output of the decklink decoder, but you never know)...  If that works, we'll find some code that edits the MediaType a pin exports...

UPDATE 2:
Quote
Note: my project takes 4 seconds to start video after clicking play. :-\
this can be unseated by filters, and intelligent connection takes a long time

Yes, I wondered.  There's a note in the DeckLink sample code...
Code: [Select]
//-----------------------------------------------------------------------------
// CreateGraph
// Build a playback graph.  This is a fairly crude implementation, it could be improved
// by searching for audio and video pins and connecting appropriately rather than relying
// too heavily on intelligent connect of the graph.
// Also as the infinite T is used for preview it is invariably connected BEFORE any decoder
// filters.  Rendering to Decklink and preview requires two decoder instances which is not
// very efficient.

Let's get the graph working first, before we optimise...
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 14, 2015, 10:57:39 am
Quote
UPDATE 1:  Oh, you still have one option to play with.   Load the correct graph into GraphEdit, and ensure one of the non-working video files are at the front.  Now right-click on random output pins and choose properties.  See if you can find one that allows you to resize the video and that works when you click play (should be the output of the decklink decoder, but you never know)...  If that works, we'll find some code that edits the MediaType a pin exports...
I do not find this  :-\

I read this in msdn site:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd377589(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/dd377589(v=vs.85).aspx)
Code: [Select]
AM_MEDIA_TYPE mtGroup; 
mtGroup.majortype = MEDIATYPE_Video;
mtGroup.subtype = MEDIASUBTYPE_RGB555;

// Set format headers.
mtGroup.pbFormat = (BYTE*)CoTaskMemAlloc(sizeof(VIDEOINFOHEADER));
if (mtGroup.pbFormat == NULL)
{
    return E_OUTOFMEMORY;
}

VIDEOINFOHEADER *pVideoHeader = (VIDEOINFOHEADER*)mtGroup.pbFormat;
ZeroMemory(pVideoHeader, sizeof(VIDEOINFOHEADER));
pVideoHeader->bmiHeader.biBitCount = 16;
pVideoHeader->bmiHeader.biWidth = 720;
pVideoHeader->bmiHeader.biHeight = 576;
pVideoHeader->bmiHeader.biPlanes = 1;
pVideoHeader->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pVideoHeader->bmiHeader.biSizeImage = DIBSIZE(pVideoHeader->bmiHeader);

// Set the format type and size.
mtGroup.formattype = FORMAT_VideoInfo;
mtGroup.cbFormat = sizeof(VIDEOINFOHEADER);

// Set the sample size.
mtGroup.bFixedSizeSamples = TRUE;
mtGroup.lSampleSize = DIBSIZE(pVideoHeader->bmiHeader);

// Now use this media type for the group.
pGroup->SetMediaType(&mtGroup);

// Clean up.
CoTaskMemFree(mtGroup.pbFormat);

if this code, setting my video, I have to apply to the filter "SourceFilter". But I do not know how to do.
Perhaps this is the right way?  :-\
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 17, 2015, 06:26:22 pm
I have done many tests.
Code: [Select]
//Perhaps it is this statement?
//  SeqHdr :        array[0..0] of DWORD;  // 

//****************************************
  ZeroMemory(@Mt, sizeof(AM_MEDIA_TYPE));
  Mt.MajorType  := MEDIATYPE_Video;
  Mt.SubType    := MEDIASUBTYPE_RGB32;
  Mt.FormatType := FORMAT_MPEG2_VIDEO;

  Mt.cbFormat := sizeof(MPEG2VIDEOINFO) + sizeof(seqHdr);
  Mt.pbFormat := CoTaskMemAlloc(Mt.cbFormat);


  if (mt.pbFormat = NULL) then   // if is NULL then ERROR
  begin
   showmessage('error');
  end;     


  ZeroMemory(mt.pbFormat, mt.cbFormat);

  RCSRC.Left := 0;
  RCSRC.Top:= 0;
  RCSRC.Right := 0;
  RCSRC.Bottom := 0;

  pWIH.hdr.rcSource := RCSRC;
         
  pWIH.hdr.rcTarget.Left:=0;
  pWIH.hdr.rcTarget.Top:=0;
  pWIH.hdr.rcTarget.Bottom:=576;
  pWIH.hdr.rcTarget.Right:=720;

 pWIH.hdr.AvgTimePerFrame := 278335;
 pWIH.hdr.dwPictAspectRatioX := 4;
 pWIH.hdr.dwPictAspectRatioY := 3;
 pWIH.hdr.bmiHeader.biSize := 40;
 pWIH.hdr.bmiHeader.biWidth := 720;
 pWIH.hdr.bmiHeader.biHeight := 576;
 pWIH.cbSequenceHeader := sizeof(seqHdr);
 CopyMemory(@pwih.dwSequenceHeader, @seqHdr, sizeof(seqHdr));   
//******************************

//  ************  connect pin **********************************
   SourceFilter.FindPin('Output',PinOutSource);
   DefaultAudioFilter.FindPin('Input',PInIntermediateFilter);
 
   case PinOutSource.Connect(PInIntermediateFilter,@mt) of
          S_OK                : showmessage('S_OK   ');
          E_POINTER           : showmessage('E_POINTER  ');
          VFW_E_NOT_CONNECTED : showmessage('VFW_E_NOT_CONNECTED');
   end; 
//    I receive ( E_POINTER   )
there is an error in this code. Where is that?
P.S.: see This (  if (mt.pbFormat = NULL) then   )
https://msdn.microsoft.com/en-us/library/windows/desktop/dd407277(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/dd407277(v=vs.85).aspx)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 18, 2015, 05:13:19 pm
Mike.Cornflake
Quote
UPDATE 1:  Oh, you still have one option to play with.   Load the correct graph into GraphEdit, and ensure one of the non-working video files are at the front.  Now right-click on random output pins and choose properties.  See if you can find one that allows you to resize the video and that works when you click play (should be the output of the decklink decoder, but you never know)...  If that works, we'll find some code that edits the MediaType a pin exports...

I found this filter.
 In the properties " Use new output format", in graphedit, is work!
how can I select this function by pascal code, or set the values that I want? resize 720x576 aspect ratio 16/9 or 3/4
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 19, 2015, 12:22:24 am
That filter is part of the Nero suite.  My experience with that lot of filters is twofold:

1.  Somehow or other, Nero detects whether a debugger is in use.  If it is, you will be unable to load that filter into any graph.  So, you can write code that uses it, but you can't test it within the IDE.  Which really tells me that Nero don't want other people to use their filters.

2.  While I admit this was a long time ago, I just couldn't get Nero filters to work fully as expected.  At the time I put this down to a lack of my own experience and moved on.

Quote
In the properties " Use new output format", in graphedit, is work!

Sorry - I've never seen a "use new output format" option in GraphEdt.  You're either using a newer version than mine, or this is a custom property that neresize.ax somehow registers.  Either way I don't have a clue :-(

See attached image.  I was asking if you can right click on any of the output pins, choose pin properties, then change the video size.  You'll find that most of the pins don't have properties, but if we're lucky, I'm hoping that the DeckLnk Decoder output pin has this property.

UPDATE:

See also  http://alax.info/blog/967

Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 19, 2015, 12:44:01 pm
Mike.Cornflake
Quote
See attached image.  I was asking if you can right click on any of the output pins, choose pin properties, then change the video size.  You'll find that most of the pins don't have properties, but if we're lucky, I'm hoping that the DeckLnk Decoder output pin has this property.

I do not find that I can change pin properties.  :-\ :-\
Attached graphic image.
--------------------------------------
with the filter " NeResize.ax "
running activate property page with this code:
Code: [Select]

//leggi : tguid;
//SpecifyPropertyPages : ISpecifyPropertyPages;
  NeroResizeV1.QueryInterface(IID_ISpecifyPropertyPages,leggi);

   hr :=  NeroResizeV1.QueryInterface(IID_ISpecifyPropertyPages, SpecifyPropertyPages);
   if Hr <> S_OK then exit;
      hr :=  SpecifyPropertyPages.GetPages(CAGUID);
   if Hr <> S_OK then exit;
   OleCreatePropertyFrame(0, 0, 0, FilterInfo.achName, 1, @NeroResizeV1,
                          CAGUID.cElems, CAGUID.pElems, 0, 0, nil);


   hr := ICapGraph.RenderStream(nil,nil, SourceFilter, nil, NeroResizeV1);
I look for ways to change properties of the page filter in code project.
This works! Use much CPU.
I do not like.
--------------------------------------------
if I can change rcTarget in Lav Spitter, it would be better, and the graphic work better.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 19, 2015, 09:28:36 pm
This works! Use much CPU.
I do not like.

Nice, you've got a working solution :-)  Well done :-)

Now let's see if you can reduce the CPU overhead...

Concentrating on the video only.  You'v got two identical processing paths following the infinite tee.  I realise this is the way DeckLink configured the stream in their sample.

I'm wondering if this couldn't be optimised to:

Quote
LAV Splitter ---> LAV Video Decoder -->  NeroResize1  --> InfiniteTee  -->  LAV Video Renderer
                                                                                   +--------->  Monitor Video Renderer

In other words, only do the video decoding and resizing once, *then* split the results. 

Same optimisation should be possible on the audio pin, but I doubt that will seriously affect CPU.

A different thought occurs:  Do you need the second Nero Resize?  Sure, you need PAL resolution on the Video Out, but for displaying on your monitor?  I don't think so.  You should be able to display in native resolution, or even just let the VMR handle resizing...

Quote
LAV Splitter ---> LAV Video Decoder  --> InfiniteTee  --> NeroResize1   -->  LAV Video Renderer
                                                            +----------------------------> Monitor Video Renderer

You might be able to do all this experimentation in GraphEdt before turning to code.   

Err, and you do realise you now have to either distribute a licensed copy of Nero with your App, OR you're going to have to insist your users install Nero?

if I can change rcTarget in Lav Spitter, it would be better, and the graphic work better.

Yup, that'll be nice as well - means you won't need Nero Resize, though the above optimisation will still be beneficial for the decoding. 

I'll have a look around, see if I can find some code to edit rcTarget...
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 20, 2015, 08:46:59 am
the filter Nero Resize and filter decoder, work only after tee filter. As a result, 2 Nero Resize and 2 Filter Decoder for video. Double CPU work.

My final project must work with text scroll in video,  i have the same resolution for DeckLink and videowindows.

Now I look in the internet, how to change rcTarget in the filter upstream of the graph, (LAV Splitter) or (Lav Video Decoder). Thanks for your help. If you can try this too.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 21, 2015, 01:15:50 pm
you look this:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd377618(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/windows/desktop/dd377618(v=vs.85).aspx)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 25, 2015, 09:03:06 am
no one can help you understand this code.  Not working

Code: [Select]
   mt        : AM_Media_Type;
  rcSrc    : Rect;
  seqHdr : array[0..0] of Byte;   // this is right?
  pWIH    : MPEG2VIDEOINFO;
//***************  type pin ******************
  ZeroMemory(@Mt, sizeof(AM_MEDIA_TYPE));
  Mt.MajorType := MEDIATYPE_Video;
  Mt.SubType := MEDIASUBTYPE_RGB32;
  Mt.FormatType := FORMAT_MPEG2_VIDEO;
  Mt.cbFormat := sizeof(MPEG2VIDEOINFO) + sizeof(seqHdr);
  mt.pbFormat := CoTaskMemAlloc(mt.cbFormat);

  if (mt.pbFormat = NULL) then exit;   // ERROR   

  ZeroMemory(mt.pbFormat, mt.cbFormat);

  RCSRC.Left := 0;
  RCSRC.Top:= 0;
  RCSRC.Right := 0;
  RCSRC.Bottom := 0;

  pWIH.hdr.rcSource.Left:=0;
  pWIH.hdr.rcSource.Top:=0;
  pWIH.hdr.rcSource.Right:=0;
  pWIH.hdr.rcSource.Bottom:=0;

  pWIH.hdr.rcSource := RCSRC;
//  pWIH.hdr.rcTarget := Rect(0,0,720,576);
  pWIH.hdr.rcTarget.Left:=0;
  pWIH.hdr.rcTarget.Top:=0;
  pWIH.hdr.rcTarget.Right:=576;
  pWIH.hdr.rcTarget.Bottom:=720;

  pWIH.hdr.AvgTimePerFrame := 278335;
  pWIH.hdr.dwPictAspectRatioX := 4;
  pWIH.hdr.dwPictAspectRatioY := 3;
  pWIH.hdr.bmiHeader.biSize := 40;
  pWIH.hdr.bmiHeader.biWidth := 720;
  pWIH.hdr.bmiHeader.biHeight := 576;
  pWIH.cbSequenceHeader := sizeof(seqHdr);
  CopyMemory(@pwih.dwSequenceHeader, @seqHdr, sizeof(seqhdr));
  // ********  connect pin *******************
  SourceFilter.FindPin('Output',PinOutSource);
 (VideoWindow1 as IBaseFilter).FindPin('Input',PIn_input);
 case PinOutSource.Connect(PIn_input,@mt) of
   S_OK                : showmessage('S_OK         ');
   E_POINTER           : showmessage('E_POINTER    ');
   VFW_E_NOT_CONNECTED : showmessage('VFW_E_NOT_CONNECTED ');
   VFW_E_CANNOT_CONNECT : showmessage('VFW_E_CANNOT_CONNECT');
   VFW_E_NOT_IN_GRAPH  : showmessage('VFW_E_NOT_IN_GRAPH ');
 end;
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on March 25, 2015, 06:47:44 pm
Extremely sorry.  I'm now swamped at work, and will be unlikely to help for 4 to 8 weeks :-(
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: carmeloconny on March 27, 2015, 08:38:25 am
thank you, good job  ;)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Gyuri on April 16, 2015, 04:18:23 pm
Hello to All,

I apologise if my post sounds too simple for some of you, but I am a novice in Pascal programming.

I am testing a USB camera with DirectShow, using the DSPACK, and I encountered some problems.
I can visualise the live picture of the camera in a VideoWindow, but I would like to superipose over the
live picture a simple crosshair (see the attached picture). I am using a VMRBitmap to transfer the drawing
to mix it with the live video image.

I draw the pair of horizontal and vertical red lines which form a crosshair on a Bitmap (TBitmap) with white
background. The bitmap could be transferred to the VMRABitmap with the Loadbitmap procedure. However,
this directly is not working (I mean, it does not gives result). I am using the vmrbSrcColorKey and ColorKey
for the white background, this should remain transparent over the live video image, only the crosshair should
be visible from the entire bitmap overlayed on the video. This works correctly under Delphi.

Code: [Select]
// crossBitmap is a TBitmap with the red haircross on it over a white background, it is created previously
try
VMRBitmap.LoadBitmap(crossBitmap);             
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.Options := VMRBitmap.Options + [vmrbSrcColorKey];
VMRBitmap.ColorKey := clWhite;
VMRBitmap.DrawTo(0,0,1,1, 1);
finally
crossBitmap.Free;
 end;

I found a "brute force" way to solve this, first I am saving the bitmap to a file, load the file, and pass the bitmap to the
VMRABitmap. Yes, I admit, this is not a correct way, and I would not use this, but for now it is the only working solution.
The crosshair position has to be moved on the video image, so I can't save and load every time the bitmap.

Code: [Select]
// crossBitmap is a TBitmap with the red haircross on it over a white background, it is created previously
crossBitmap.SaveToFile('test.bmp');
try
crossBitmap.LoadFromFile('test.bmp');
VMRBitmap.LoadBitmap(crossBitmap);             
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.Options := VMRBitmap.Options + [vmrbSrcColorKey];
VMRBitmap.ColorKey := clWhite;
VMRBitmap.DrawTo(0,0,1,1, 1);
finally
crossBitmap.Free;
end;

I have a clue, that this behaviour is due to the native TBitmap format of Lazarus, which is different than the Windows
bitmap, and since VMRABitmap is expecting a Windows type bitmap, it does not mix over the video the desired content.

But I am not able to find a solution. Can anyone recommend another way?

I also noticed the problem mentioned on the first page of the topic, the VMRBitmap.LoadEmptyBitmap
does not work for me either. Instead, to clear the overlay on the video, I am using the same trick, I create
a bitmap, and pass it to VMRBitmap. This could be a compromise, but is acceptable.

Code: [Select]

//emptyBitmap is a TBitmap
emptyBitmap := TBitmap.Create;                 
VMRBitmap.LoadEmptyBitmap(400,300,pf24bit ,clWhite);    //a pixel formattal van valami baj
//VMRBitmap.LoadBitmap( emptyBitmap );
VMRBitmap.Source := VMRBitmap.Canvas.ClipRect;
VMRBitmap.DrawTo(0,0,1,1,0);
emptyBitmap.Free;
end;

Thanks in advance,
Gyuri
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: af0815 on November 03, 2017, 10:58:53 am
For the records, i have done a Fork on GitHub  O:-)  https://github.com/afriess/LazarusVideoUtilities

Thanks to the holder of the original codebase -> Mike.Cornflake  :) https://sourceforge.net/projects/lazarusvideoutilities/

The actual code is working with Lazarus 1.8.0RC5 r56092M FPC 3.1.1 i386-win32-win32/win64 too. It is only working on Windows, because of using MS-DirectShow.

I use this package to work with USB-Cameras in Win7 and WIn10 with resolution up to 1920x1080. This looks like a natural limitation of DirtectShow. Because 4k resolution (eg. Logitech BRIO) are only working with M$ UWP programming on the last version Win 10 (1709) - if the hardware support the 4k.

Andreas
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: Mike.Cornflake on November 03, 2017, 05:35:23 pm
For the records, i have done a Fork on GitHub  O:-)  https://github.com/afriess/LazarusVideoUtilities

Thanks to the holder of the original codebase -> Mike.Cornflake  :) https://sourceforge.net/projects/lazarusvideoutilities/

The actual code is working with Lazarus 1.8.0RC5 r56092M FPC 3.1.1 i386-win32-win32/win64 too. It is only working on Windows, because of using MS-DirectShow.

Awesome stuff, many thanks for this :-).  I've been unable to find time for any of the plans I had for this, let alone maintain it.
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: fin on December 17, 2017, 01:26:32 pm
Thanks af0815 :)
Title: Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
Post by: mtron on December 19, 2017, 08:03:37 pm
I use this package to work with USB-Cameras in Win7 and WIn10 with resolution up to 1920x1080. This looks like a natural limitation of DirtectShow. Because 4k resolution (eg. Logitech BRIO) are only working with M$ UWP programming on the last version Win 10 (1709) - if the hardware support the 4k.

This is great, Andreas!

Do you have any Lazarus example on how to work with camera capture, just still images?

Thanks and best
TinyPortal © 2005-2018