Recent

Author Topic: DSPack for Lazarus - Win32 DirectShow Multimedia components  (Read 54713 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #30 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.



Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #31 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
« Last Edit: March 13, 2015, 12:42:05 pm by carmeloconny »

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #32 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?

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #33 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...
« Last Edit: March 13, 2015, 08:13:10 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #34 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
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?  :-\

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #35 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

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #36 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

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #37 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

« Last Edit: March 19, 2015, 12:24:26 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #38 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.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #39 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...
« Last Edit: March 19, 2015, 09:34:47 pm by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #40 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.


carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #42 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;

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #43 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 :-(
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

carmeloconny

  • New member
  • *
  • Posts: 29
Re: DSPack for Lazarus - Win32 DirectShow Multimedia components
« Reply #44 on: March 27, 2015, 08:38:25 am »
thank you, good job  ;)