Tag Archives: resolution

How to make a constant frame rate video stream from variable frame rate stream, and rescale it

From a conversation:

I have a video stream with variable frame rate, I want to make this in to a constant  frame rate. Do you know of any filters that could help me with this?

Such filter is actually quite easy. You only need to update time stamps of the media samples that are going through. I am not aware of  an “out of the box” ready filter, but you can even do it without special filter: if you build your graph with Sample Grabber Filter in it in  the place of interest, and initialize it to have a callback for each sample, then in SampleCB method you will be able to update time stamps using methods of IMediaSample interface. This is sufficient to redistribute the frames on the timeline, so that they go at constant frame rate.

In your opinion what is the best way to scale the video?

The best depends on what is the criteria (speed, quality etc). The simplest for me while very efficient – and I did this a number of times – is to use a custom filter which inside it uses StretchBlt function on a per frame basis to scale input RGB video into output RGB video of a different resolution.

How to dynamically change resolution for video preview

From a conversation:

Q: I am using Web camera with DirectShow. Camera has only capture pin, so I am looking for the best way to switch resolution on the pin while graph is running. I would like to keep preview with smaller image size and when i would like to capture an image i would like to switch to full resolution. I have to use sample grabber callback since i need access to single image to process them. Is there a way to do that without stopping and starting a graph? This works but very slow between captures.

Is it possible to just reconnect the sample grabber only with new media changes and then resume the graph? Currently i just kill the graph and start it again, but it takes few seconds to do so, so I am looking the way to reduce that time.

There is no way to switch resolution on the running graph. There is a technique to dynamically start/stop individual filters and re-negotiate resolutions (media types), but it does not work for the majority of filters. Additionally to that Sample Grabber Filter cannot change resolution too, as it passes data through.

If you only have to use switched resolution for preview, you can use Geraint’s GMFBridge Toolkit to join two graphs, and a filter that changes resolution. Combining all that you will have a running capture graph that [also] renders video to a bridge sink. In the other graph you have another bridge sink that receives video from first graph and then you resize video to the resolution of interest already in the second graph. You can stop and reconfigure only second graph to update resolution and have first graph running and capturing. This is the best you can do, or just stop your single graph and change resolution this simple way.

So a solution, which is used by many, and I can recommend it too, is to use GMFBridge bridging. Additionally, you can find questions and answers on it on MSDN DirectShow Development Forum (search for “bridge” there). With a certain effort you can duplicate this with your own code but this is more or less ready to use solution and, again, the key advantage you have that you have two graphs which you can top independently.

Would it be possible to use smart tee as a splitter on the capture pin, and then use two sample grabbers on capture and preview, one with smaller resolution and the other one with higher one?

With a Smart Tee Filter you will still have 1 graph, so no individual resolution changes without stopping the graph. Additionally to that, Smart Tee Filter will deliver same frame on its output pins, so they will have to have one resolution and no resizing takes place inside.

Also, is it possible to run 2 graphs in the same time? Same device, 2 graphs, 2 sample grabbers.

Most likely no, for only one reason: you won’t be able to have two running filters for the same device, as source filter will exclusively lock the device. So capture filter will be a single filter. You can use Infinite Tee Pin Filter to split stream between 2+ processing lines. And you can use the same bridge to pass data into another graph for further processing.

Asus Eee PC, Tray Utility, Default Resolution

Among things beyond of any understanding are those presented by Asustek/Asus engineers. While hardware is more or less OK, software is often confusing. Asus Eee PC 1000HE, out of which I own one, comes with Asus Eee PC Tray Utility 5.1.1.4008.

Asus Eee PC Tray Utility 5.1.1.4008

A helper application to provide quick access to certain hardware control functions, it is OK. No, you don’t have an option to close it and even if you kill it from task manager, another Asus utility will immediately relaunch it. It is a kind monther care from Asus who are just sure that they know the right way.

The laptop las an LCD of 1024×600 pixel reoslution, and, as it usually happens, most accurate, sharp and best looking image is on the display when screen resolution is also set to 1024×600. That is, one virtual screen resolution pixel that matches exactly one physical pixel on the LCD matrix. Do I  need to be so much detailed on the obvious things, because everyone knows this as it seems? Everyone but Asus engineers who for some reasons sell laptops that automatically switch to default resolution 800×600. Even if you change resolution to desired one, the laptop will switch it back  sometimes when you logon, when you reboot, when you use fast switch user capability… Could it be more stupid than that? Perhaps it could, but this way it is already rather annoying.

After less than two months, the hotkey which switches LCD resolution sunk down while it was only used for one thing: to bring back resolution of 1024×600, which beyound of any doubt had to be default resolution without any justification to fall back to a different one for no reason. The key is definitely not going to last for too long.

Asus Eee PC 1000HE Resolution Hotkey

Out of curiosity, I started the utility on my desktop, where it immediately blinded me by turning off both of my Asus monitors and left me no other way to press reset button to reboot the box.

I thought that there might be an update for the utility on Asus Support website because this kind of thing had to be fixed with apologies and sincere promises to never happen again. I was reluctant to use Asus Update utility because it is more refined masterpiece of stupidity. However on the website, there is no utility in downloads at all. It could be a part of another downloadable package, but there was also no obvious indication that would give a hint what update is required.

So that only solution left was to anatomize the crapware and think of a workaround to at least for some time extend the life of the hotkey. The utility below, PostAsTrayCommand, will look for Asus tray icon utility to be running and will post a requested command (this way it can also be used to switch on or off wireless LAN, or the camera) to the utility.

To switch resolution to 1024×600, a command of 32797 has to be posted. The screenshot below gives an idea of other values, which might be useful:

AsTray Utility Tray Icon Menu Commands

To post a command, it needs to be started from command line “PostAsTrayCommand.exe 32797″ and it makes sense to add it to Startup group to be automatically launched on logon.

A Visual C++ .NET 2008 source code is available from SVN, release binary included.