Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Image Tearing in video capturing, VSync in directshow??

316 views
Skip to first unread message

Albert Pinto

unread,
Dec 9, 2009, 1:47:16 PM12/9/09
to
Hi,

I am developing an application to capture images from the analog video
source. I am using Directshow apis to capture the analog video. The
application is based on msdn sample amcap (first creates graph the
adds video capture filter and finally adds VMR9).

The problem is : I am using a Digital camera as input source and while
changing the images(on camera) one of the image captured is half of
previous image and half portion of the next image.

One of the solution suggested for this problem Vsync mode.

How can I set the v sync mode using directshow apis? I didn't find any
directshow apis for the same.

Any help in this regard is highly appreciated.

Regards,
Albert

Alessandro Angeli

unread,
Dec 9, 2009, 6:09:53 PM12/9/09
to
From: "Albert Pinto"

> The problem is : I am using a Digital camera as input
> source and while changing the images(on camera) one of
> the image captured is half of previous image and half
> portion of the next image.

What video capture filter are you using? This sounds like a
problem in either the hardware or the driver, not DirectShow
(DirectShow only knows how to handle media samples, how to
properly fill them is the responsibility of the source
component).


--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm


Albert Pinto

unread,
Dec 10, 2009, 6:09:35 AM12/10/09
to
On Dec 10, 4:09 am, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

On Dec 10, 4:09 am, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

Hi,

Thanks Alessandro for the reply.

I am using the Avermedia BDA Capture filter. I am creating a graph and
then adding Avermedia BDA Capture filter which I get using the
following call:-
hr = current_device->BindToObject(0,0,IID_IBaseFilter, (void**)
&ret_base_filter);

for the detected frame grabber card.

The base filter is added to graph as "Video Capture" filter as
follows:
hr = _graph_builder->AddFilter(base_filter, L"Video Capture");

and finally adding the VMR9 renderer to the graph. Currently I am
capturing the image using GetCurrentImage API of IBasicVideo
interface.

Is there anyway to disable interlacing using directshow apis such that
problem i got doesn;t occur? or any other way at application level
using direct show apis to fix such problem?

My use-case here is to capture images from analog device. The video
capturing part is implemented in a dll and client application makes
the GetCurrentImage request to get the current image on a timer. Is
there a way to detect change in frame on device using directshow api
so that video capturing dll can detect the change capture the image at
that moment instead ?

Is there any other alternate/better approach for above use case?

Thanks in advance.

Regards
Manpreet

Alessandro Angeli

unread,
Dec 10, 2009, 1:04:49 PM12/10/09
to
From: "Albert Pinto"

> and finally adding the VMR9 renderer to the graph.
> Currently I am capturing the image using GetCurrentImage
> API of IBasicVideo interface.

I get it. By capturing you don't really mean capturing the
video, but grabbing a single displayed picture. And I guess
that what you get are 2 weaved fields belonging to 2
different frames instead of the same frame?

> Is there anyway to disable interlacing using directshow
> apis such that problem i got doesn;t occur? or any other
> way at application level using direct show apis to fix
> such problem?

If the capture driver wants to output interlaced video, it
will. And analog SD capture cards usually do for full
resolutions, because full resolution analog SD video
standards are always interlaced.

Unless the driver gives you a driver-specific way to
configure it to output progressive frames, the only
DirectShow standard way would be if the IAMStreamConfig
interface on the capture source's output pin offered
VIDEOINFOHEADER alongside VIDEOINFOHEADER2 (VIH frames are
supposed to only be progressive).

> My use-case here is to capture images from analog device.
> The video capturing part is implemented in a dll and
> client application makes the GetCurrentImage request to
> get the current image on a timer. Is there a way to
> detect change in frame on device using directshow api so
> that video capturing dll can detect the change capture
> the image at that moment instead ?
>
> Is there any other alternate/better approach for above
> use case?

You should not use IBasicVideo::GetCurrentImage(). It can be
very slow to begin with, since it will read back from video
memory. What you should do is use a grabbing filter. Which
filter and where it should go depends on whether you need a
preview or not.

Albert Pinto

unread,
Dec 10, 2009, 2:11:31 PM12/10/09
to
On Dec 10, 11:04 pm, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

Hi Alessandro,

Thanks for the response.

Previewing the video is not required. So which filter shall be used?
Any start points for the same?

Also I read about PIN_CATEGORY_STILL pin. I tried to use
PIN_CATEGORY_STILL in renderstream but that doesn;t seems to be
working..

Can PIN_CATEGORY_STILL be used here?

Regards
Manpreet

Alessandro Angeli

unread,
Dec 10, 2009, 4:25:47 PM12/10/09
to
From: "Albert Pinto"

> Previewing the video is not required. So which filter
> shall be used? Any start points for the same?
>
> Also I read about PIN_CATEGORY_STILL pin. I tried to use
> PIN_CATEGORY_STILL in renderstream but that doesn;t seems
> to be working..
>
> Can PIN_CATEGORY_STILL be used here?

This is how, but not all capture drivers support a
PIN_CATEGORY_STILL pin:

http://msdn.microsoft.com/en-us/library/dd318622.aspx

If you use PIN_CATEGORY_STILL, pay attention to the
requirements:

http://msdn.microsoft.com/en-us/library/dd377429.aspx

If the preview is not required, you can use the same
technique involving the SampleGrabber with the normal
PIN_CATEGORY_CAPTURE pin. In the callback, simply discard
the samples unless you want to save the picture.

http://msdn.microsoft.com/en-us/library/dd407288.aspx

Notice that the SampleGrabber has some limitations:

http://msdn.microsoft.com/en-us/library/dd377544.aspx

Saying that it does not support FORMAT_VideoInfo2 is another
way of saying that it does not support interlaced frames so,
if the source can not provide progressive frames, the
SampleGrabber will not work.

Albert Pinto

unread,
Dec 11, 2009, 3:07:42 PM12/11/09
to
On Dec 11, 2:25 am, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:
> //http://www.riseoftheants.com/mmx/faq.htm

Hi Alessandro,

Thanks for the reply. Much appreciate your responses

Going for the sample grabber filter will require time. We need this
fix quickly and very critical for our application. Is there any quick
way of fixing it like setting the move to progressive scan instead of
interlaced mode? or detecting interlaced image ?

Also if the deviice is supporting/running the interlaced mode, is it a
right way to set capturing mode to progressive scan?

Thanks in advance.

Regards
Albert

Alessandro Angeli

unread,
Dec 11, 2009, 4:08:46 PM12/11/09
to
From: "Albert Pinto"

> Going for the sample grabber filter will require time. We
> need this fix quickly and very critical for our
> application. Is there any quick way of fixing it like
> setting the move to progressive scan instead of
> interlaced mode? or detecting interlaced image ?

There is no such thing as progressive or interlaced mode.
DirectShow and the graph have no clue what the video format
is. Interlaced or progressive is simply an attribute of the
video format privately agreed upon by the fitlers.

If your source filter provides a custom configuration
interface to set the mode, then you can use that one because
there is no standard DirectShow interfacw to do it. The only
standard way, if supported by your capture driver, is
through IAMStreamConfig, as I explained 2 messages ago.

> Also if the deviice is supporting/running the interlaced
> mode, is it a right way to set capturing mode to
> progressive scan?

If it is supported, yes.

Albert Pinto

unread,
Dec 16, 2009, 1:27:05 PM12/16/09
to
On Dec 12, 2:08 am, "Alessandro Angeli" <nob...@nowhere.in.the.net>
wrote:

Hi Alessandro,

I made the change to use VIDEOINFOHEADER2 instead of VIDEOINFOHEADER
which seems to have fix the interlaced images problem. Thanks.
Although I not sure what made the difference here as I didn;t change
any parameter passed to structure.

But a new problem has sprung up. The images capture with
VIDEOINFOHEADER2 are of size 320 by 240 where as earlier using the
VIDEOINFOHEADER the images were being captured of size 640 by 480.

Given below is the code for setting the video info parameter. This is
same both incase of VIDEOINFOHEADER and VIDEOINFOHEADER2.
stream_config_interface->GetFormat(&media_type);

VIDEOINFOHEADER2 *video_info_header =
reinterpret_cast<VIDEOINFOHEADER2 *>( media_type->pbFormat);

video_info_header->bmiHeader.biWidth = 640;
video_info_header->bmiHeader.biHeight = 480;
video_info_header->bmiHeader.biSizeImage =
640*480*HEADER_BYTES; // HEADER_BYTES = 3

But using the VIDEOINFOHEADER2 causes the image size as 320 by 240.

I also tried setting the rcTarget parameters as follows:-

video_info_header->rcTarget.left = 0;
video_info_header->rcTarget.top = 0;
video_info_header->rcTarget.right = 640;
video_info_header->rcTarget.bottom = 480;

Also before get current image calll basic_video->GetCurrentImage
(&bufSize, NULL); i tried setting the Destination Position as 640 by
480
basic_video->SetDestinationPosition(0,0,640,480);
but the image is still coming out to be 320 by 240

Why is this change in image size happening? How can this be fixed?

Albert Pinto

unread,
Dec 19, 2009, 10:09:17 AM12/19/09
to

Hi,

I checked the device capabilites it doesn't support VIDEOINFOHEADER2
and only supports the VIDEOINFOHEADER which doesn't have de
interlacing flags.

Also I tried using the ISampleGrabberCB(Directshow StillCap Sample)
interface to capture the images. I modified the StillCap sample
application to capture snapshot on timer. On quickly changing the
images on camera this also gives the interlaced images.

So SampleGrabber filter also seems to be giving the interlaced images.

Is there any directshow filter to deinterlace the video?

Can IVMRDeinterlaceControl9 interface be used to disable interlacing
if the videoinfoheader2 is not supported ?

Is there any other way out to like transformation filters which can
detect interlaced images? Any directshow filters available for the
same?

Any help in this regard is highly appreciated.

Regards
Albert

Alessandro Angeli

unread,
Dec 20, 2009, 1:06:16 AM12/20/09
to
From: "Albert Pinto"

> Is there any directshow filter to deinterlace the video?

[...]


> Is there any other way out to like transformation filters
> which can detect interlaced images? Any directshow
> filters available for the same?

Deinterlacing is a dynamic operation, it can not be
performed on still images. There is no stock deinterlacer
available and the only deinterlacing is provided by the
video card when the moving video is rendered. There are many
commercial and open source deinterlacers, provided as either
DS filters or custom libraries (that you can wrap in a
custom transform filter), e.g. DScaler and ffmpeg (both
included in ffdshow - I am not 100% sure about ffmpeg).

> Can IVMRDeinterlaceControl9 interface be used to disable
> interlacing if the videoinfoheader2 is not supported ?

That's a config for video rendering, it has nothing to do
with the format of the video.

VIH samples should not be interlaced in the first place. If
they are, the source driver is producing them incorrectly
and there is really nothing you can do.

Notice that an interlaced picture is just a picture, there
is nothing special about it, unless it is flagged as such,
but only VIH2 allows such flagging, so VIH pictures are
always progressive because there is no way to distinguish
between the different interlacing patterns (short of very
complex and time-consuming guessing algorithms -
deinterlacing without help from the sourceis not for the
faint of heart and the smartest algorithms I believe are
patented).

I think you must accept to live with this flaw unless you
can find a fixed driver for the device (assuming it's a bug
in the driver and not a limitation in the hardware itself:
if the sensor is interlaced and slow, it may produce frames
weaved from fields belonging to different pictures in case
of high motion).

0 new messages