PDA

View Full Version : Sample Grabbing and Seeking adventures


everwicked
17th September 2003, 16:27
Hello everybody,

I know this is not a directshow development forum but since AviSynth implements DirectShowSource and I am getting quite desperate with this problem, I came to ask for help in case someone knows.

For those of you that have not heard, I started development of vqstudio (http://www.everwicked.com/vqstudio), an application to ease objective video quality evaluation. So far, I have implemented frame grabbing and passing via VFW. As you all know, that is limited to AVI files so I wanted to extend functionality by enabling Directshow sources.

Coming down to the problem, just like AviSynth, my framework needs to be able to seek (random access) to a keyframe, grab it and deliver it to the metric for processing. Random access is required because a complex metric might request a previous or next frame so the processing cannot happen in a sequential way.

Before you ask why don't I use the files wrapped in an .avs script, that is not as efficient because the samples delivered will appear to be keyframes always while that's not the case in the original video.

I have been so far using this method to seek and grab:
- Build a graph
- Insert a Sample Grabber filter (the one provided with directx)
- Set the grabber to one shot mode
- Seek to the frame position requested (IMediaSeeking::SetPositions/AM_MEDIA_SEEKING_AbsolutePositioning is used for this)
- Play the graph and wait for it to finish through IMediaEvent::WaitForCompletion()
- Give away the result of the frame buffer

The problem here is that it makes the whole process very slow for some reason. To put down the numbers, in normal mode, the graph (with clock set to 0) will run at about 80 fps. Using this method, it runs at about 4-5fps.

I have came to the conclusion that this is because of the seeking (I also checked that the graph is paused, not stopped by the sample grabber). I tried to use Relative/Incremental Positioning as well without managing to get it to seek to the frame I wanted. I looked at the directshow docs again and again but no good.

So, the question is. Is there a better/faster method to seek/grab frames? Is RelativePositioning faster compared to AbsolutePositioning?

Also, I peaked at AviSynth's source for DirectShowSource class and I saw that it uses a custom SampleGrabber to get the frames off the video. Why is that? Or in other words, do you achieve faster seeking that way?

Any help would be appreciated.

sh0dan
17th September 2003, 21:08
You're a bit early ;)

Actually seeking is not working at all on DirectShow sources ATM. I have just spent four or five hours trying to get it to work, without getting too much further. I did get GRF-loading working though. ;)


You might look at the filters/dump example - I found some useful stuff there.

everwicked
17th September 2003, 23:15
Hrm... it looks like I might have something for you then.

I won't say anything now, let me verify it first.

If that's is the case though, i'll tell you how to improve directshowsource. I could send you sources too but it won't help much, it'll just confuse you (I never had good experiences reading other people's code).

Thanks for the reply.

everwicked
18th September 2003, 01:03
Nevermind that... it didn't work.

However, even sequentially, the frame grabbing is still slow.

Assuming the access is sequential, how can I improve grabbing?

everwicked
18th September 2003, 20:07
Hey, I noticed you updated cvs with a new directshowsource which has seeking!

What are your experiences with seeking then?

sh0dan
18th September 2003, 21:23
Works fine nicely. I had to implement a CPosPassThru object, and correct some threadrelated stuff to make it work. Seeking speed is the same as any Dshow player.

I have had the most success using TIME_FORMAT_MEDIA_TIME when seeking. AbsolutePositioning seems to work in most cases.

The only problem I have is asynchronous access, which is why there is a problem with having synchronized audio at the moment, but some workaround code should be possible.

jfcarbel
19th September 2003, 10:04
I'd be very interested in looking at code of how you did it.

I am planning to write a DirectShow based VOB Player and want to be able to do quick seeking.

By "quick seeking" I mean their will be a trackbar that I can slide back and forth quickly and it will scan thru the video quickly just like DVD2AVI does.

I know this is not the same results you are going after since you just grab a frame and pass it on, but so you think what you are doing could be useful to me?

Also I have to figure out how to open just a VOB of set of VOBs in DS since it only likes you to point the first IFO of a VIDEO_TS. Does AviSynth do this?